diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-11-13 18:05:35 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-11-13 18:05:35 +0900 |
| commit | bc9a8283c66d7588f931d4b802f7ab1fa7aa3226 (patch) | |
| tree | cac529d136737c95b1656564756da8c4ae84df32 /src/web/app/common/scripts/stream-manager.ts | |
| parent | :v: (diff) | |
| download | misskey-bc9a8283c66d7588f931d4b802f7ab1fa7aa3226.tar.gz misskey-bc9a8283c66d7588f931d4b802f7ab1fa7aa3226.tar.bz2 misskey-bc9a8283c66d7588f931d4b802f7ab1fa7aa3226.zip | |
なんかもうめっちゃ変えた
Diffstat (limited to 'src/web/app/common/scripts/stream-manager.ts')
| -rw-r--r-- | src/web/app/common/scripts/stream-manager.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/web/app/common/scripts/stream-manager.ts b/src/web/app/common/scripts/stream-manager.ts new file mode 100644 index 0000000000..4eaf0f9a45 --- /dev/null +++ b/src/web/app/common/scripts/stream-manager.ts @@ -0,0 +1,33 @@ +import * as uuid from 'uuid'; +import Connection from './stream'; + +export default abstract class StreamManager<T extends Connection> { + protected connection: T = null; + + /** + * コネクションを必要としているユーザー + */ + private users = []; + + public abstract getConnection(): T; + + 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; + } + } +} |