From de5dc87cec2c171ecd890731a3b6978d33249e21 Mon Sep 17 00:00:00 2001 From: syuilo Date: Mon, 20 Mar 2017 14:35:00 +0900 Subject: [PATCH] [Client] Fix bug, some refactorings --- src/web/app/common/scripts/stream.js | 2 ++ src/web/app/desktop/tags/timeline-post.tag | 22 ++++++++++++++-------- src/web/app/mobile/tags/timeline-post.tag | 22 ++++++++++++++-------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/src/web/app/common/scripts/stream.js b/src/web/app/common/scripts/stream.js index cbdde8d2f..5296abfde 100644 --- a/src/web/app/common/scripts/stream.js +++ b/src/web/app/common/scripts/stream.js @@ -45,6 +45,8 @@ class Connection { } send(message) { + // TODO: バッファリングしてつぎ接続した時に送信する + if (this.state != 'connected') return; this.socket.send(JSON.stringify(message)); } diff --git a/src/web/app/desktop/tags/timeline-post.tag b/src/web/app/desktop/tags/timeline-post.tag index 07cc66567..220b8441b 100644 --- a/src/web/app/desktop/tags/timeline-post.tag +++ b/src/web/app/desktop/tags/timeline-post.tag @@ -364,13 +364,24 @@ } }; - this.on('mount', () => { + this.capture = () => { this.stream.send({ type: 'capture', id: this.p.id }); - this.stream.event.on('post-updated', this.onStreamPostUpdated); + }; + + this.decapture = () => { + this.stream.send({ + type: 'decapture', + id: this.p.id + }); + this.stream.event.off('post-updated', this.onStreamPostUpdated); + }; + + this.on('mount', () => { + this.capture(); if (this.p.text) { const tokens = this.p.ast; @@ -393,12 +404,7 @@ }); this.on('unmount', () => { - this.stream.send({ - type: 'decapture', - id: this.p.id - }); - - this.stream.event.off('post-updated', this.onStreamPostUpdated); + this.decapture(); }); this.reply = () => { diff --git a/src/web/app/mobile/tags/timeline-post.tag b/src/web/app/mobile/tags/timeline-post.tag index e0cffb62d..7f02dd487 100644 --- a/src/web/app/mobile/tags/timeline-post.tag +++ b/src/web/app/mobile/tags/timeline-post.tag @@ -340,13 +340,24 @@ } }; - this.on('mount', () => { + this.capture = () => { this.stream.send({ type: 'capture', id: this.p.id }); - this.stream.event.on('post-updated', this.onStreamPostUpdated); + }; + + this.decapture = () => { + this.stream.send({ + type: 'decapture', + id: this.p.id + }); + this.stream.event.off('post-updated', this.onStreamPostUpdated); + }; + + this.on('mount', () => { + this.capture(); if (this.p.text) { const tokens = this.p.ast; @@ -369,12 +380,7 @@ }); this.on('unmount', () => { - this.stream.send({ - type: 'decapture', - id: this.p.id - }); - - this.stream.event.off('post-updated', this.onStreamPostUpdated); + this.decapture(); }); this.reply = () => {