This commit is contained in:
		
							parent
							
								
									842b5e878f
								
							
						
					
					
						commit
						3ca3cd8d65
					
				
					 1 changed files with 14 additions and 3 deletions
				
			
		| 
						 | 
					@ -9,6 +9,8 @@ import Connection from './stream';
 | 
				
			||||||
export default abstract class StreamManager<T extends Connection> extends EventEmitter {
 | 
					export default abstract class StreamManager<T extends Connection> extends EventEmitter {
 | 
				
			||||||
	private _connection: T = null;
 | 
						private _connection: T = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						private disposeTimerId: any;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	/**
 | 
						/**
 | 
				
			||||||
	 * コネクションを必要としているユーザー
 | 
						 * コネクションを必要としているユーザー
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
| 
						 | 
					@ -51,6 +53,12 @@ export default abstract class StreamManager<T extends Connection> extends EventE
 | 
				
			||||||
	 * コネクションを要求するためのユーザーIDを発行します
 | 
						 * コネクションを要求するためのユーザーIDを発行します
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	public use() {
 | 
						public use() {
 | 
				
			||||||
 | 
							// タイマー解除
 | 
				
			||||||
 | 
							if (this.disposeTimerId) {
 | 
				
			||||||
 | 
								clearTimeout(this.disposeTimerId);
 | 
				
			||||||
 | 
								this.disposeTimerId = null;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// ユーザーID生成
 | 
							// ユーザーID生成
 | 
				
			||||||
		const userId = uuid();
 | 
							const userId = uuid();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,9 +76,12 @@ export default abstract class StreamManager<T extends Connection> extends EventE
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// 誰もコネクションの利用者がいなくなったら
 | 
							// 誰もコネクションの利用者がいなくなったら
 | 
				
			||||||
		if (this.users.length == 0) {
 | 
							if (this.users.length == 0) {
 | 
				
			||||||
			// コネクションを切断する
 | 
								// また直ぐに再利用される可能性があるので、一定時間待ち、
 | 
				
			||||||
 | 
								// 新たな利用者が現れなければコネクションを切断する
 | 
				
			||||||
 | 
								this.disposeTimerId = setTimeout(() => {
 | 
				
			||||||
				this.connection.close();
 | 
									this.connection.close();
 | 
				
			||||||
				this.connection = null;
 | 
									this.connection = null;
 | 
				
			||||||
 | 
								}, 3000);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue