diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-11-17 21:14:03 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-11-17 21:14:03 +0900 |
| commit | 3ca3cd8d650a690a314feaf18373c0fce48aad90 (patch) | |
| tree | 7b959c083605b902cb643e961c46bf5d7d40538b /src/web/app | |
| parent | Update home-stream.ts (diff) | |
| download | sharkey-3ca3cd8d650a690a314feaf18373c0fce48aad90.tar.gz sharkey-3ca3cd8d650a690a314feaf18373c0fce48aad90.tar.bz2 sharkey-3ca3cd8d650a690a314feaf18373c0fce48aad90.zip | |
#928
Diffstat (limited to 'src/web/app')
| -rw-r--r-- | src/web/app/common/scripts/streaming/stream-manager.ts | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/web/app/common/scripts/streaming/stream-manager.ts b/src/web/app/common/scripts/streaming/stream-manager.ts index 1383b97828..23ad48970e 100644 --- a/src/web/app/common/scripts/streaming/stream-manager.ts +++ b/src/web/app/common/scripts/streaming/stream-manager.ts @@ -9,6 +9,8 @@ import Connection from './stream'; export default abstract class StreamManager<T extends Connection> extends EventEmitter { private _connection: T = null; + private disposeTimerId: any; + /** * コネクションを必要としているユーザー */ @@ -51,6 +53,12 @@ export default abstract class StreamManager<T extends Connection> extends EventE * コネクションを要求するためのユーザーIDを発行します */ public use() { + // タイマー解除 + if (this.disposeTimerId) { + clearTimeout(this.disposeTimerId); + this.disposeTimerId = null; + } + // ユーザーID生成 const userId = uuid(); @@ -68,9 +76,12 @@ export default abstract class StreamManager<T extends Connection> extends EventE // 誰もコネクションの利用者がいなくなったら if (this.users.length == 0) { - // コネクションを切断する - this.connection.close(); - this.connection = null; + // また直ぐに再利用される可能性があるので、一定時間待ち、 + // 新たな利用者が現れなければコネクションを切断する + this.disposeTimerId = setTimeout(() => { + this.connection.close(); + this.connection = null; + }, 3000); } } } |