mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-14 05:57:32 -07:00
同じ接続を使いまわすように
This commit is contained in:
parent
5353bce32a
commit
814c1394d9
6 changed files with 60 additions and 13 deletions
|
@ -2,6 +2,10 @@ ChangeLog (Release Notes)
|
|||
=========================
|
||||
主に notable な changes を書いていきます
|
||||
|
||||
unreleased
|
||||
----------
|
||||
* 通信の最適化
|
||||
|
||||
3040 (2017/11/12)
|
||||
-----------------
|
||||
* バグ修正
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
import * as riot from 'riot';
|
||||
|
||||
import activateMe from './i';
|
||||
import activateApi from './api';
|
||||
import activateStream from './stream';
|
||||
|
||||
export default (me, stream) => {
|
||||
export default (me, stream, serverStreamManager) => {
|
||||
activateMe(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>
|
||||
<script>
|
||||
import Connection from '../../../common/scripts/server-stream';
|
||||
|
||||
this.data = {
|
||||
view: 0,
|
||||
design: 0
|
||||
|
@ -69,8 +67,11 @@
|
|||
|
||||
this.mixin('widget');
|
||||
|
||||
this.mixin('server-stream');
|
||||
this.connection = this.serverStream.getConnection();
|
||||
this.connectionId = this.serverStream.use();
|
||||
|
||||
this.initializing = true;
|
||||
this.connection = new Connection();
|
||||
|
||||
this.on('mount', () => {
|
||||
this.api('meta').then(meta => {
|
||||
|
@ -82,7 +83,7 @@
|
|||
});
|
||||
|
||||
this.on('unmount', () => {
|
||||
this.connection.close();
|
||||
this.serverStream.dispose(this.connectionId);
|
||||
});
|
||||
|
||||
this.toggle = () => {
|
||||
|
|
|
@ -9,6 +9,7 @@ import api from './common/scripts/api';
|
|||
import signout from './common/scripts/signout';
|
||||
import checkForUpdate from './common/scripts/check-for-update';
|
||||
import Connection from './common/scripts/home-stream';
|
||||
import ServerStreamManager from './common/scripts/server-stream-manager.ts';
|
||||
import Progress from './common/scripts/loading';
|
||||
import mixin from './common/mixins';
|
||||
import CONFIG from './common/scripts/config';
|
||||
|
@ -111,8 +112,11 @@ export default callback => {
|
|||
// Init home stream connection
|
||||
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');
|
||||
|
|
Loading…
Reference in a new issue