mirror of
https://github.com/urbit/shrub.git
synced 2024-12-01 06:35:32 +03:00
channel-js: add onChannelOpen hook
This commit is contained in:
parent
4b61dfc87a
commit
c04d3f1659
@ -9,6 +9,9 @@ class Channel {
|
||||
this.onChannelError = (err) => {
|
||||
console.error('event source error: ', err);
|
||||
};
|
||||
this.onChannelOpen = (e) => {
|
||||
console.log('open', e);
|
||||
};
|
||||
}
|
||||
|
||||
init() {
|
||||
@ -58,6 +61,10 @@ class Channel {
|
||||
this.onChannelError = onError;
|
||||
}
|
||||
|
||||
setOnChannelOpen(onOpen = (e) => {}) {
|
||||
this.onChannelOpen = onOpen;
|
||||
}
|
||||
|
||||
deleteOnUnload() {
|
||||
window.addEventListener("unload", (event) => {
|
||||
this.delete();
|
||||
@ -216,6 +223,8 @@ class Channel {
|
||||
}
|
||||
}
|
||||
|
||||
this.eventSource.onopen = this.onChannelOpen;
|
||||
|
||||
this.eventSource.onerror = e => {
|
||||
this.delete();
|
||||
this.init();
|
||||
|
Loading…
Reference in New Issue
Block a user