fix connection status and awareness info when disconnected (ws-provider)
This commit is contained in:
parent
e699f92333
commit
453407b93d
@ -61,15 +61,24 @@ const setupWS = (doc, url) => {
|
|||||||
websocket.onclose = () => {
|
websocket.onclose = () => {
|
||||||
doc.ws = null
|
doc.ws = null
|
||||||
doc.wsconnected = false
|
doc.wsconnected = false
|
||||||
|
// update awareness (all users left)
|
||||||
|
const removed = []
|
||||||
|
doc.getAwarenessInfo().forEach((_, userid) => {
|
||||||
|
removed.push(userid)
|
||||||
|
})
|
||||||
|
doc.awareness = new Map()
|
||||||
|
doc.emit('awareness', {
|
||||||
|
added: [], updated: [], removed
|
||||||
|
})
|
||||||
doc.emit('status', {
|
doc.emit('status', {
|
||||||
status: 'connected'
|
status: 'disconnected'
|
||||||
})
|
})
|
||||||
setTimeout(setupWS, reconnectTimeout, doc, url)
|
setTimeout(setupWS, reconnectTimeout, doc, url)
|
||||||
}
|
}
|
||||||
websocket.onopen = () => {
|
websocket.onopen = () => {
|
||||||
doc.wsconnected = true
|
doc.wsconnected = true
|
||||||
doc.emit('status', {
|
doc.emit('status', {
|
||||||
status: 'disconnected'
|
status: 'connected'
|
||||||
})
|
})
|
||||||
// always send sync step 1 when connected
|
// always send sync step 1 when connected
|
||||||
const encoder = Y.encoding.createEncoder()
|
const encoder = Y.encoding.createEncoder()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user