forked from FoundKeyGang/FoundKey
同じ接続を使いまわすように
This commit is contained in:
parent
f24d86bf93
commit
98dca7b7ac
6 changed files with 60 additions and 13 deletions
|
@ -2,6 +2,10 @@ ChangeLog (Release Notes)
|
||||||
=========================
|
=========================
|
||||||
主に notable な changes を書いていきます
|
主に notable な changes を書いていきます
|
||||||
|
|
||||||
|
unreleased
|
||||||
|
----------
|
||||||
|
* 通信の最適化
|
||||||
|
|
||||||
3040 (2017/11/12)
|
3040 (2017/11/12)
|
||||||
-----------------
|
-----------------
|
||||||
* バグ修正
|
* バグ修正
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
|
import * as riot from 'riot';
|
||||||
|
|
||||||
import activateMe from './i';
|
import activateMe from './i';
|
||||||
import activateApi from './api';
|
import activateApi from './api';
|
||||||
import activateStream from './stream';
|
|
||||||
|
|
||||||
export default (me, stream) => {
|
export default (me, stream, serverStreamManager) => {
|
||||||
activateMe(me);
|
activateMe(me);
|
||||||
activateApi(me);
|
activateApi(me);
|
||||||
activateStream(stream);
|
|
||||||
|
riot.mixin('stream', { stream });
|
||||||
|
|
||||||
|
riot.mixin('server-stream', { serverStream: serverStreamManager });
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
import * as riot from 'riot';
|
|
||||||
|
|
||||||
export default stream => {
|
|
||||||
riot.mixin('stream', { stream });
|
|
||||||
};
|
|
39
src/web/app/common/scripts/server-stream-manager.ts
Normal file
39
src/web/app/common/scripts/server-stream-manager.ts
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -60,8 +60,6 @@
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
import Connection from '../../../common/scripts/server-stream';
|
|
||||||
|
|
||||||
this.data = {
|
this.data = {
|
||||||
view: 0,
|
view: 0,
|
||||||
design: 0
|
design: 0
|
||||||
|
@ -69,8 +67,11 @@
|
||||||
|
|
||||||
this.mixin('widget');
|
this.mixin('widget');
|
||||||
|
|
||||||
|
this.mixin('server-stream');
|
||||||
|
this.connection = this.serverStream.getConnection();
|
||||||
|
this.connectionId = this.serverStream.use();
|
||||||
|
|
||||||
this.initializing = true;
|
this.initializing = true;
|
||||||
this.connection = new Connection();
|
|
||||||
|
|
||||||
this.on('mount', () => {
|
this.on('mount', () => {
|
||||||
this.api('meta').then(meta => {
|
this.api('meta').then(meta => {
|
||||||
|
@ -82,7 +83,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
this.on('unmount', () => {
|
this.on('unmount', () => {
|
||||||
this.connection.close();
|
this.serverStream.dispose(this.connectionId);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.toggle = () => {
|
this.toggle = () => {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import api from './common/scripts/api';
|
||||||
import signout from './common/scripts/signout';
|
import signout from './common/scripts/signout';
|
||||||
import checkForUpdate from './common/scripts/check-for-update';
|
import checkForUpdate from './common/scripts/check-for-update';
|
||||||
import Connection from './common/scripts/home-stream';
|
import Connection from './common/scripts/home-stream';
|
||||||
|
import ServerStreamManager from './common/scripts/server-stream-manager.ts';
|
||||||
import Progress from './common/scripts/loading';
|
import Progress from './common/scripts/loading';
|
||||||
import mixin from './common/mixins';
|
import mixin from './common/mixins';
|
||||||
import CONFIG from './common/scripts/config';
|
import CONFIG from './common/scripts/config';
|
||||||
|
@ -111,8 +112,11 @@ export default callback => {
|
||||||
// Init home stream connection
|
// Init home stream connection
|
||||||
const stream = me ? new Connection(me) : null;
|
const stream = me ? new Connection(me) : null;
|
||||||
|
|
||||||
|
// Init server stream connection manager
|
||||||
|
const serverStreamManager = new ServerStreamManager();
|
||||||
|
|
||||||
// ミックスイン初期化
|
// ミックスイン初期化
|
||||||
mixin(me, stream);
|
mixin(me, stream, serverStreamManager);
|
||||||
|
|
||||||
// ローディング画面クリア
|
// ローディング画面クリア
|
||||||
const ini = document.getElementById('ini');
|
const ini = document.getElementById('ini');
|
||||||
|
|
Loading…
Reference in a new issue