summaryrefslogtreecommitdiff
path: root/src/web/app/common/scripts/stream.js
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-03-20 14:49:24 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-03-20 14:49:24 +0900
commitb6475958d03a1d91651e11498f31a1ad0fa01925 (patch)
tree437ba02c692490aade98a3e194434399669b31dc /src/web/app/common/scripts/stream.js
parentv1398 (diff)
downloadmisskey-b6475958d03a1d91651e11498f31a1ad0fa01925.tar.gz
misskey-b6475958d03a1d91651e11498f31a1ad0fa01925.tar.bz2
misskey-b6475958d03a1d91651e11498f31a1ad0fa01925.zip
[Client] Refactoring
Diffstat (limited to 'src/web/app/common/scripts/stream.js')
-rw-r--r--src/web/app/common/scripts/stream.js13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/web/app/common/scripts/stream.js b/src/web/app/common/scripts/stream.js
index 5296abfde8..8004f11bc2 100644
--- a/src/web/app/common/scripts/stream.js
+++ b/src/web/app/common/scripts/stream.js
@@ -8,12 +8,13 @@ class Connection {
this.onOpen = this.onOpen.bind(this);
this.onClose = this.onClose.bind(this);
this.onMessage = this.onMessage.bind(this);
+ this.send = this.send.bind(this);
this.close = this.close.bind(this);
// ----------------------------------------
+ riot.observable(this);
+
this.state = 'initializing';
- this.stateEv = riot.observable();
- this.event = riot.observable();
this.me = me;
const host = CONFIG.apiUrl.replace('http', 'ws');
@@ -22,23 +23,23 @@ class Connection {
this.socket.addEventListener('close', this.onClose);
this.socket.addEventListener('message', this.onMessage);
- this.event.on('i_updated', me.update);
+ this.on('i_updated', me.update);
}
onOpen() {
this.state = 'connected';
- this.stateEv.trigger('connected');
+ this.trigger('_connected_');
}
onClose() {
this.state = 'reconnecting';
- this.stateEv.trigger('closed');
+ this.trigger('_closed_');
}
onMessage(message) {
try {
const msg = JSON.parse(message.data);
- if (msg.type) this.event.trigger(msg.type, msg.body);
+ if (msg.type) this.trigger(msg.type, msg.body);
} catch(e) {
// noop
}