mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
parent
815ff046ff
commit
e666f02b88
1 changed files with 13 additions and 5 deletions
|
@ -1,3 +1,6 @@
|
|||
import { uMapAlert as Alert } from '../../components/alerts/alert.js'
|
||||
import { translate } from '../i18n.js'
|
||||
|
||||
const PONG_TIMEOUT = 5000
|
||||
const PING_INTERVAL = 30000
|
||||
const FIRST_CONNECTION_TIMEOUT = 2000
|
||||
|
@ -14,15 +17,20 @@ export class WebSocketTransport {
|
|||
}
|
||||
this.websocket.addEventListener('message', this.onMessage.bind(this))
|
||||
this.websocket.onclose = () => {
|
||||
console.log('websocket closed')
|
||||
console.debug('websocket closed')
|
||||
if (!this.receiver.closeRequested) {
|
||||
console.log('Not requested, reconnecting...')
|
||||
Alert.info(
|
||||
translate(
|
||||
'This map has enabled real-time synchronization with other users, but you are currently disconnected. We will try to reconnect in the background and reconcile with other users, but this feature is still experimental, and you might lose data. Have fun!'
|
||||
)
|
||||
)
|
||||
console.debug('Not requested, reconnecting...')
|
||||
this.receiver.reconnect()
|
||||
}
|
||||
}
|
||||
|
||||
this.websocket.onerror = (error) => {
|
||||
console.log('WS ERROR', error)
|
||||
console.debug('WS ERROR', error)
|
||||
}
|
||||
|
||||
this.ensureOpen = setInterval(() => {
|
||||
|
@ -38,7 +46,7 @@ export class WebSocketTransport {
|
|||
// See https://making.close.com/posts/reliable-websockets/ for more details.
|
||||
this.pingInterval = setInterval(() => {
|
||||
if (this.websocket.readyState === WebSocket.OPEN) {
|
||||
console.log('sending ping')
|
||||
console.debug('sending ping')
|
||||
this.websocket.send('ping')
|
||||
this.pongReceived = false
|
||||
setTimeout(() => {
|
||||
|
@ -68,7 +76,7 @@ export class WebSocketTransport {
|
|||
}
|
||||
|
||||
close() {
|
||||
console.log('Closing')
|
||||
console.debug('Closing')
|
||||
this.receiver.closeRequested = true
|
||||
this.websocket.close()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue