-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace client.subscribe with doc.subscribe
- Loading branch information
Showing
13 changed files
with
256 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,36 @@ | ||
const network = { | ||
isOnline: false, | ||
showOffline: (elem) => { | ||
network.isOnline = false; | ||
elem.innerHTML = '<span class="red"> </span>'; | ||
}, | ||
showOnline: (elem) => { | ||
network.isOnline = true; | ||
elem.innerHTML = '<span class="green"> </span>'; | ||
}, | ||
statusListener: (elem) => { | ||
return (event) => { | ||
if ( | ||
network.isOnline && | ||
((event.type == 'status-changed' && event.value == 'deactivated') || | ||
(event.type == 'stream-connection-status-changed' && | ||
event.value == 'disconnected') || | ||
(event.type == 'document-sync-result' && | ||
event.value == 'sync-failed')) | ||
) { | ||
network.showOffline(elem); | ||
} else if ( | ||
!network.isOnline && | ||
((event.type == 'status-changed' && event.value == 'activated') || | ||
(event.type == 'stream-connection-status-changed' && | ||
event.value == 'connected') || | ||
(event.type == 'document-sync-result' && event.value == 'synced') || | ||
event.type == 'document-changed') | ||
) { | ||
network.showOnline(elem); | ||
} | ||
}; | ||
}, | ||
}; | ||
/** | ||
* `Network` is a class that manages the network status. | ||
*/ | ||
class Network { | ||
constructor(elem) { | ||
this.isOnline = false; | ||
this.elem = elem; | ||
} | ||
|
||
/** | ||
* Show offline status. | ||
*/ | ||
showOffline() { | ||
this.isOnline = false; | ||
this.elem.innerHTML = '<span class="red"> </span>'; | ||
} | ||
|
||
/** | ||
* Show online status. | ||
*/ | ||
showOnline() { | ||
this.isOnline = true; | ||
this.elem.innerHTML = '<span class="green"> </span>'; | ||
} | ||
|
||
/** | ||
* Listen to the network status changes. | ||
*/ | ||
statusListener = (event) => { | ||
if (this.isOnline && event.value === 'disconnected') { | ||
this.showOffline(); | ||
} else if (!this.isOnline && event.value === 'connected') { | ||
this.showOnline(); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.