summaryrefslogtreecommitdiff
path: root/src/web/app/common/scripts/streaming/home-stream.ts
blob: 57bf0ec2a6d6c8090373a7c7ca748e604c4aa893 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import Stream from './stream';
import MiOS from '../../mios';

/**
 * Home stream connection
 */
export default class Connection extends Stream {
	constructor(os: MiOS, me) {
		super('', {
			i: me.token
		});

		// 最終利用日時を更新するため定期的にaliveメッセージを送信
		setInterval(() => {
			this.send({ type: 'alive' });
			me.last_used_at = new Date();
		}, 1000 * 60);

		// 自分の情報が更新されたとき
		this.on('i_updated', i => {
			Object.assign(me, i);
		});

		// トークンが再生成されたとき
		// このままではAPIが利用できないので強制的にサインアウトさせる
		this.on('my_token_regenerated', () => {
			alert('%i18n:common.my-token-regenerated%');
			os.signout();
		});
	}
}