Clean up and fix

This commit is contained in:
syuilo 2018-10-11 21:25:55 +09:00
parent 7f40fba652
commit b8ae18b81a

View file

@ -10,7 +10,6 @@ import MiOS from '../../mios';
export default class Stream extends EventEmitter { export default class Stream extends EventEmitter {
private stream: ReconnectingWebsocket; private stream: ReconnectingWebsocket;
private state: string; private state: string;
private buffer: any[];
private sharedConnectionPools: Pool[] = []; private sharedConnectionPools: Pool[] = [];
private sharedConnections: SharedConnection[] = []; private sharedConnections: SharedConnection[] = [];
private nonSharedConnections: NonSharedConnection[] = []; private nonSharedConnections: NonSharedConnection[] = [];
@ -19,7 +18,6 @@ export default class Stream extends EventEmitter {
super(); super();
this.state = 'initializing'; this.state = 'initializing';
this.buffer = [];
const user = os.store.state.i; const user = os.store.state.i;
@ -70,17 +68,12 @@ export default class Stream extends EventEmitter {
this.state = 'connected'; this.state = 'connected';
this.emit('_connected_'); this.emit('_connected_');
// バッファーを処理
const _buffer = [].concat(this.buffer); // Shallow copy
this.buffer = []; // Clear buffer
_buffer.forEach(data => {
this.send(data); // Resend each buffered messages
});
// チャンネル再接続 // チャンネル再接続
if (isReconnect) { if (isReconnect) {
this.sharedConnectionPools.forEach(p => { this.sharedConnectionPools.forEach(p => {
p.connect(); if (p.users > 0) {
p.connect();
}
}); });
this.nonSharedConnections.forEach(c => { this.nonSharedConnections.forEach(c => {
c.connect(); c.connect();
@ -133,12 +126,6 @@ export default class Stream extends EventEmitter {
body: payload body: payload
}; };
// まだ接続が確立されていなかったらバッファリングして次に接続した時に送信する
if (this.state != 'connected') {
this.buffer.push(data);
return;
}
this.stream.send(JSON.stringify(data)); this.stream.send(JSON.stringify(data));
} }
@ -156,7 +143,7 @@ class Pool {
public channel: string; public channel: string;
public id: string; public id: string;
protected stream: Stream; protected stream: Stream;
private users = 0; public users = 0;
private disposeTimerId: any; private disposeTimerId: any;
private isConnected = false; private isConnected = false;