diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-03-21 18:14:59 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-03-21 18:14:59 +0900 |
| commit | 48386a8f68e478ee2561cfb28aea638ab7a20216 (patch) | |
| tree | 883e84b84648019021352cc38cc4d3ebd50c3505 /src/web/app/common/scripts | |
| parent | [Client] :art: (diff) | |
| download | sharkey-48386a8f68e478ee2561cfb28aea638ab7a20216.tar.gz sharkey-48386a8f68e478ee2561cfb28aea638ab7a20216.tar.bz2 sharkey-48386a8f68e478ee2561cfb28aea638ab7a20216.zip | |
[Client] Implement streaming buffering
Diffstat (limited to 'src/web/app/common/scripts')
| -rw-r--r-- | src/web/app/common/scripts/stream.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/web/app/common/scripts/stream.js b/src/web/app/common/scripts/stream.js index 8004f11bc2..f6eaef3723 100644 --- a/src/web/app/common/scripts/stream.js +++ b/src/web/app/common/scripts/stream.js @@ -16,6 +16,7 @@ class Connection { this.state = 'initializing'; this.me = me; + this.buffer = []; const host = CONFIG.apiUrl.replace('http', 'ws'); this.socket = new ReconnectingWebSocket(`${host}?i=${me.token}`); @@ -29,6 +30,13 @@ class Connection { onOpen() { this.state = 'connected'; this.trigger('_connected_'); + + // バッファーを処理 + const _buffer = [].concat(this.buffer); // Shallow copy + this.buffer = []; // Clear buffer + _buffer.forEach(message => { + this.send(message); // Resend each buffered messages + }); } onClose() { @@ -46,8 +54,12 @@ class Connection { } send(message) { - // TODO: バッファリングしてつぎ接続した時に送信する - if (this.state != 'connected') return; + // まだ接続が確立されていなかったらバッファリングして次に接続した時に送信する + if (this.state != 'connected') { + this.buffer.push(message); + return; + }; + this.socket.send(JSON.stringify(message)); } |