From b6475958d03a1d91651e11498f31a1ad0fa01925 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 Mar 2017 14:49:24 +0900 Subject: [Client] Refactoring --- src/web/app/common/scripts/stream.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/web/app/common/scripts/stream.js') 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 } -- cgit v1.3.1-freya