Fix
This commit is contained in:
parent
a04f0e3545
commit
5df0e102fd
1 changed files with 16 additions and 5 deletions
|
@ -46,6 +46,11 @@ export default class Stream extends EventEmitter {
|
||||||
this.sharedConnections = this.sharedConnections.filter(c => c !== connection);
|
this.sharedConnections = this.sharedConnections.filter(c => c !== connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@autobind
|
||||||
|
public removeSharedConnectionPool(pool: Pool) {
|
||||||
|
this.sharedConnectionPools = this.sharedConnectionPools.filter(p => p !== pool);
|
||||||
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
public connectToChannel(channel: string, params?: any): NonSharedConnection {
|
public connectToChannel(channel: string, params?: any): NonSharedConnection {
|
||||||
const connection = new NonSharedConnection(this, channel, params);
|
const connection = new NonSharedConnection(this, channel, params);
|
||||||
|
@ -71,9 +76,7 @@ export default class Stream extends EventEmitter {
|
||||||
// チャンネル再接続
|
// チャンネル再接続
|
||||||
if (isReconnect) {
|
if (isReconnect) {
|
||||||
this.sharedConnectionPools.forEach(p => {
|
this.sharedConnectionPools.forEach(p => {
|
||||||
if (p.users > 0) {
|
p.connect();
|
||||||
p.connect();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
this.nonSharedConnections.forEach(c => {
|
this.nonSharedConnections.forEach(c => {
|
||||||
c.connect();
|
c.connect();
|
||||||
|
@ -152,6 +155,13 @@ class Pool {
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
|
|
||||||
this.id = Math.random().toString();
|
this.id = Math.random().toString();
|
||||||
|
|
||||||
|
this.stream.on('_disconnected_', this.onStreamDisconnected);
|
||||||
|
}
|
||||||
|
|
||||||
|
@autobind
|
||||||
|
private onStreamDisconnected() {
|
||||||
|
this.isConnected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
|
@ -185,6 +195,7 @@ class Pool {
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
public connect() {
|
public connect() {
|
||||||
|
if (this.isConnected) return;
|
||||||
this.isConnected = true;
|
this.isConnected = true;
|
||||||
this.stream.send('connect', {
|
this.stream.send('connect', {
|
||||||
channel: this.channel,
|
channel: this.channel,
|
||||||
|
@ -194,9 +205,9 @@ class Pool {
|
||||||
|
|
||||||
@autobind
|
@autobind
|
||||||
private disconnect() {
|
private disconnect() {
|
||||||
this.isConnected = false;
|
this.stream.off('_disconnected_', this.onStreamDisconnected);
|
||||||
this.disposeTimerId = null;
|
|
||||||
this.stream.send('disconnect', { id: this.id });
|
this.stream.send('disconnect', { id: this.id });
|
||||||
|
this.stream.removeSharedConnectionPool(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue