diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-11-13 03:47:06 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-11-13 03:47:06 +0900 |
| commit | 98dca7b7ac16c4ea38f808bc20d4a71a3acb3355 (patch) | |
| tree | d1b1b5f2542ee3c8bda747ef3b63f44d3becce4d /src/web/app/common/scripts | |
| parent | Update setup.en.md (diff) | |
| download | sharkey-98dca7b7ac16c4ea38f808bc20d4a71a3acb3355.tar.gz sharkey-98dca7b7ac16c4ea38f808bc20d4a71a3acb3355.tar.bz2 sharkey-98dca7b7ac16c4ea38f808bc20d4a71a3acb3355.zip | |
同じ接続を使いまわすように
Diffstat (limited to 'src/web/app/common/scripts')
| -rw-r--r-- | src/web/app/common/scripts/server-stream-manager.ts | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/web/app/common/scripts/server-stream-manager.ts b/src/web/app/common/scripts/server-stream-manager.ts new file mode 100644 index 0000000000..e3f03ae40b --- /dev/null +++ b/src/web/app/common/scripts/server-stream-manager.ts @@ -0,0 +1,39 @@ +import Connection from './server-stream'; +import uuid from './uuid'; + +export default class ServerStreamManager { + private connection = null; + + /** + * コネクションを必要としているユーザー + */ + private users = []; + + public getConnection() { + if (this.connection == null) { + this.connection = new Connection(); + } + + return this.connection; + } + + public use() { + // ユーザーID生成 + const userId = uuid(); + + this.users.push(userId); + + return userId; + } + + public dispose(userId) { + this.users = this.users.filter(id => id != userId); + + // 誰もコネクションの利用者がいなくなったら + if (this.users.length == 0) { + // コネクションを切断する + this.connection.close(); + this.connection = null; + } + } +} |