mirror of
https://github.com/syuilo/ai.git
synced 2025-03-25 21:12:56 +00:00
Update stream.ts
This commit is contained in:
parent
55b3f22dc3
commit
4b19cff643
1 changed files with 5 additions and 6 deletions
|
@ -72,14 +72,14 @@ export default class Stream extends EventEmitter {
|
||||||
this.state = 'connected';
|
this.state = 'connected';
|
||||||
this.emit('_connected_');
|
this.emit('_connected_');
|
||||||
|
|
||||||
// バッファーを処理
|
// Process the buffer
|
||||||
const _buffer = [...this.buffer]; // Shallow copy
|
const _buffer = [...this.buffer]; // Shallow copy
|
||||||
this.buffer = []; // Clear buffer
|
this.buffer = []; // Clear buffer
|
||||||
for (const data of _buffer) {
|
for (const data of _buffer) {
|
||||||
this.send(data); // Resend each buffered messages
|
this.send(data); // Resend each buffered messages
|
||||||
}
|
}
|
||||||
|
|
||||||
// チャンネル再接続
|
// Reconnect the channel
|
||||||
if (isReconnect) {
|
if (isReconnect) {
|
||||||
this.sharedConnectionPools.forEach(p => {
|
this.sharedConnectionPools.forEach(p => {
|
||||||
p.connect();
|
p.connect();
|
||||||
|
@ -137,7 +137,7 @@ export default class Stream extends EventEmitter {
|
||||||
body: payload
|
body: payload
|
||||||
};
|
};
|
||||||
|
|
||||||
// まだ接続が確立されていなかったらバッファリングして次に接続した時に送信する
|
// If the connection is not established yet, buffer it and send it the next time a connection is established.
|
||||||
if (this.state != 'connected') {
|
if (this.state != 'connected') {
|
||||||
this.buffer.push(data);
|
this.buffer.push(data);
|
||||||
return;
|
return;
|
||||||
|
@ -179,7 +179,7 @@ class Pool {
|
||||||
|
|
||||||
this.users++;
|
this.users++;
|
||||||
|
|
||||||
// タイマー解除
|
// Cancel the timer
|
||||||
if (this.disposeTimerId) {
|
if (this.disposeTimerId) {
|
||||||
clearTimeout(this.disposeTimerId);
|
clearTimeout(this.disposeTimerId);
|
||||||
this.disposeTimerId = null;
|
this.disposeTimerId = null;
|
||||||
|
@ -192,8 +192,7 @@ class Pool {
|
||||||
|
|
||||||
// そのコネクションの利用者が誰もいなくなったら
|
// そのコネクションの利用者が誰もいなくなったら
|
||||||
if (this.users === 0) {
|
if (this.users === 0) {
|
||||||
// また直ぐに再利用される可能性があるので、一定時間待ち、
|
// Since there is a possibility that the connection will be reused soon, wait a certain amount of time, and if no new users appear, close the connection.
|
||||||
// 新たな利用者が現れなければコネクションを切断する
|
|
||||||
this.disposeTimerId = setTimeout(() => {
|
this.disposeTimerId = setTimeout(() => {
|
||||||
this.disconnect();
|
this.disconnect();
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
Loading…
Reference in a new issue