summaryrefslogtreecommitdiff
path: root/src/client/app/common/scripts/streaming
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2018-10-07 11:06:17 +0900
committerGitHub <noreply@github.com>2018-10-07 11:06:17 +0900
commitd0570d7fe3a3bf3c6b0312dece74bacc04c3534a (patch)
tree698218279a38f9c78b0350e81b8ac77ae52e4a0d /src/client/app/common/scripts/streaming
parentFix お知らせが確認中...のままになる(Announcement Fetching...) (... (diff)
downloadsharkey-d0570d7fe3a3bf3c6b0312dece74bacc04c3534a.tar.gz
sharkey-d0570d7fe3a3bf3c6b0312dece74bacc04c3534a.tar.bz2
sharkey-d0570d7fe3a3bf3c6b0312dece74bacc04c3534a.zip
V10 (#2826)
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update CHANGELOG.md * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update CHANGELOG.md * Update CHANGELOG.md * wip * Update CHANGELOG.md * wip * wip * wip * wip
Diffstat (limited to 'src/client/app/common/scripts/streaming')
-rw-r--r--src/client/app/common/scripts/streaming/drive.ts34
-rw-r--r--src/client/app/common/scripts/streaming/games/reversi/reversi-game.ts13
-rw-r--r--src/client/app/common/scripts/streaming/games/reversi/reversi.ts31
-rw-r--r--src/client/app/common/scripts/streaming/global-timeline.ts34
-rw-r--r--src/client/app/common/scripts/streaming/hashtag.ts13
-rw-r--r--src/client/app/common/scripts/streaming/home.ts126
-rw-r--r--src/client/app/common/scripts/streaming/hybrid-timeline.ts34
-rw-r--r--src/client/app/common/scripts/streaming/local-timeline.ts34
-rw-r--r--src/client/app/common/scripts/streaming/messaging-index.ts34
-rw-r--r--src/client/app/common/scripts/streaming/messaging.ts20
-rw-r--r--src/client/app/common/scripts/streaming/notes-stats.ts30
-rw-r--r--src/client/app/common/scripts/streaming/server-stats.ts30
-rw-r--r--src/client/app/common/scripts/streaming/stream-manager.ts109
-rw-r--r--src/client/app/common/scripts/streaming/stream.ts137
-rw-r--r--src/client/app/common/scripts/streaming/user-list.ts17
15 files changed, 0 insertions, 696 deletions
diff --git a/src/client/app/common/scripts/streaming/drive.ts b/src/client/app/common/scripts/streaming/drive.ts
deleted file mode 100644
index 50fff05737..0000000000
--- a/src/client/app/common/scripts/streaming/drive.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import Stream from './stream';
-import StreamManager from './stream-manager';
-import MiOS from '../../../mios';
-
-/**
- * Drive stream connection
- */
-export class DriveStream extends Stream {
- constructor(os: MiOS, me) {
- super(os, 'drive', {
- i: me.token
- });
- }
-}
-
-export class DriveStreamManager extends StreamManager<DriveStream> {
- private me;
- private os: MiOS;
-
- constructor(os: MiOS, me) {
- super();
-
- this.me = me;
- this.os = os;
- }
-
- public getConnection() {
- if (this.connection == null) {
- this.connection = new DriveStream(this.os, this.me);
- }
-
- return this.connection;
- }
-}
diff --git a/src/client/app/common/scripts/streaming/games/reversi/reversi-game.ts b/src/client/app/common/scripts/streaming/games/reversi/reversi-game.ts
deleted file mode 100644
index adfa75ff3b..0000000000
--- a/src/client/app/common/scripts/streaming/games/reversi/reversi-game.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import Stream from '../../stream';
-import MiOS from '../../../../../mios';
-
-export class ReversiGameStream extends Stream {
- constructor(os: MiOS, me, game) {
- super(os, 'games/reversi-game', me ? {
- i: me.token,
- game: game.id
- } : {
- game: game.id
- });
- }
-}
diff --git a/src/client/app/common/scripts/streaming/games/reversi/reversi.ts b/src/client/app/common/scripts/streaming/games/reversi/reversi.ts
deleted file mode 100644
index 1f4fd8c63e..0000000000
--- a/src/client/app/common/scripts/streaming/games/reversi/reversi.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import StreamManager from '../../stream-manager';
-import Stream from '../../stream';
-import MiOS from '../../../../../mios';
-
-export class ReversiStream extends Stream {
- constructor(os: MiOS, me) {
- super(os, 'games/reversi', {
- i: me.token
- });
- }
-}
-
-export class ReversiStreamManager extends StreamManager<ReversiStream> {
- private me;
- private os: MiOS;
-
- constructor(os: MiOS, me) {
- super();
-
- this.me = me;
- this.os = os;
- }
-
- public getConnection() {
- if (this.connection == null) {
- this.connection = new ReversiStream(this.os, this.me);
- }
-
- return this.connection;
- }
-}
diff --git a/src/client/app/common/scripts/streaming/global-timeline.ts b/src/client/app/common/scripts/streaming/global-timeline.ts
deleted file mode 100644
index a639f1595c..0000000000
--- a/src/client/app/common/scripts/streaming/global-timeline.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import Stream from './stream';
-import StreamManager from './stream-manager';
-import MiOS from '../../../mios';
-
-/**
- * Global timeline stream connection
- */
-export class GlobalTimelineStream extends Stream {
- constructor(os: MiOS, me) {
- super(os, 'global-timeline', {
- i: me.token
- });
- }
-}
-
-export class GlobalTimelineStreamManager extends StreamManager<GlobalTimelineStream> {
- private me;
- private os: MiOS;
-
- constructor(os: MiOS, me) {
- super();
-
- this.me = me;
- this.os = os;
- }
-
- public getConnection() {
- if (this.connection == null) {
- this.connection = new GlobalTimelineStream(this.os, this.me);
- }
-
- return this.connection;
- }
-}
diff --git a/src/client/app/common/scripts/streaming/hashtag.ts b/src/client/app/common/scripts/streaming/hashtag.ts
deleted file mode 100644
index 276b8f8d3d..0000000000
--- a/src/client/app/common/scripts/streaming/hashtag.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-import Stream from './stream';
-import MiOS from '../../../mios';
-
-export class HashtagStream extends Stream {
- constructor(os: MiOS, me, q) {
- super(os, 'hashtag', me ? {
- i: me.token,
- q: JSON.stringify(q)
- } : {
- q: JSON.stringify(q)
- });
- }
-}
diff --git a/src/client/app/common/scripts/streaming/home.ts b/src/client/app/common/scripts/streaming/home.ts
deleted file mode 100644
index 26729507fb..0000000000
--- a/src/client/app/common/scripts/streaming/home.ts
+++ /dev/null
@@ -1,126 +0,0 @@
-import Stream from './stream';
-import StreamManager from './stream-manager';
-import MiOS from '../../../mios';
-
-/**
- * Home stream connection
- */
-export class HomeStream extends Stream {
- constructor(os: MiOS, me) {
- super(os, '', {
- i: me.token
- });
-
- // 最終利用日時を更新するため定期的にaliveメッセージを送信
- setInterval(() => {
- this.send({ type: 'alive' });
- me.lastUsedAt = new Date();
- }, 1000 * 60);
-
- // 自分の情報が更新されたとき
- this.on('meUpdated', i => {
- if (os.debug) {
- console.log('I updated:', i);
- }
-
- os.store.dispatch('mergeMe', i);
- });
-
- this.on('read_all_notifications', () => {
- os.store.dispatch('mergeMe', {
- hasUnreadNotification: false
- });
- });
-
- this.on('unread_notification', () => {
- os.store.dispatch('mergeMe', {
- hasUnreadNotification: true
- });
- });
-
- this.on('read_all_messaging_messages', () => {
- os.store.dispatch('mergeMe', {
- hasUnreadMessagingMessage: false
- });
- });
-
- this.on('unread_messaging_message', () => {
- os.store.dispatch('mergeMe', {
- hasUnreadMessagingMessage: true
- });
- });
-
- this.on('unreadMention', () => {
- os.store.dispatch('mergeMe', {
- hasUnreadMentions: true
- });
- });
-
- this.on('readAllUnreadMentions', () => {
- os.store.dispatch('mergeMe', {
- hasUnreadMentions: false
- });
- });
-
- this.on('unreadSpecifiedNote', () => {
- os.store.dispatch('mergeMe', {
- hasUnreadSpecifiedNotes: true
- });
- });
-
- this.on('readAllUnreadSpecifiedNotes', () => {
- os.store.dispatch('mergeMe', {
- hasUnreadSpecifiedNotes: false
- });
- });
-
- this.on('clientSettingUpdated', x => {
- os.store.commit('settings/set', {
- key: x.key,
- value: x.value
- });
- });
-
- this.on('home_updated', x => {
- os.store.commit('settings/setHome', x);
- });
-
- this.on('mobile_home_updated', x => {
- os.store.commit('settings/setMobileHome', x);
- });
-
- this.on('widgetUpdated', x => {
- os.store.commit('settings/setWidget', {
- id: x.id,
- data: x.data
- });
- });
-
- // トークンが再生成されたとき
- // このままではMisskeyが利用できないので強制的にサインアウトさせる
- this.on('my_token_regenerated', () => {
- alert('%i18n:common.my-token-regenerated%');
- os.signout();
- });
- }
-}
-
-export class HomeStreamManager extends StreamManager<HomeStream> {
- private me;
- private os: MiOS;
-
- constructor(os: MiOS, me) {
- super();
-
- this.me = me;
- this.os = os;
- }
-
- public getConnection() {
- if (this.connection == null) {
- this.connection = new HomeStream(this.os, this.me);
- }
-
- return this.connection;
- }
-}
diff --git a/src/client/app/common/scripts/streaming/hybrid-timeline.ts b/src/client/app/common/scripts/streaming/hybrid-timeline.ts
deleted file mode 100644
index cd290797c4..0000000000
--- a/src/client/app/common/scripts/streaming/hybrid-timeline.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import Stream from './stream';
-import StreamManager from './stream-manager';
-import MiOS from '../../../mios';
-
-/**
- * Hybrid timeline stream connection
- */
-export class HybridTimelineStream extends Stream {
- constructor(os: MiOS, me) {
- super(os, 'hybrid-timeline', {
- i: me.token
- });
- }
-}
-
-export class HybridTimelineStreamManager extends StreamManager<HybridTimelineStream> {
- private me;
- private os: MiOS;
-
- constructor(os: MiOS, me) {
- super();
-
- this.me = me;
- this.os = os;
- }
-
- public getConnection() {
- if (this.connection == null) {
- this.connection = new HybridTimelineStream(this.os, this.me);
- }
-
- return this.connection;
- }
-}
diff --git a/src/client/app/common/scripts/streaming/local-timeline.ts b/src/client/app/common/scripts/streaming/local-timeline.ts
deleted file mode 100644
index 41c36aa14c..0000000000
--- a/src/client/app/common/scripts/streaming/local-timeline.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import Stream from './stream';
-import StreamManager from './stream-manager';
-import MiOS from '../../../mios';
-
-/**
- * Local timeline stream connection
- */
-export class LocalTimelineStream extends Stream {
- constructor(os: MiOS, me) {
- super(os, 'local-timeline', me ? {
- i: me.token
- } : {});
- }
-}
-
-export class LocalTimelineStreamManager extends StreamManager<LocalTimelineStream> {
- private me;
- private os: MiOS;
-
- constructor(os: MiOS, me) {
- super();
-
- this.me = me;
- this.os = os;
- }
-
- public getConnection() {
- if (this.connection == null) {
- this.connection = new LocalTimelineStream(this.os, this.me);
- }
-
- return this.connection;
- }
-}
diff --git a/src/client/app/common/scripts/streaming/messaging-index.ts b/src/client/app/common/scripts/streaming/messaging-index.ts
deleted file mode 100644
index addcccb952..0000000000
--- a/src/client/app/common/scripts/streaming/messaging-index.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import Stream from './stream';
-import StreamManager from './stream-manager';
-import MiOS from '../../../mios';
-
-/**
- * Messaging index stream connection
- */
-export class MessagingIndexStream extends Stream {
- constructor(os: MiOS, me) {
- super(os, 'messaging-index', {
- i: me.token
- });
- }
-}
-
-export class MessagingIndexStreamManager extends StreamManager<MessagingIndexStream> {
- private me;
- private os: MiOS;
-
- constructor(os: MiOS, me) {
- super();
-
- this.me = me;
- this.os = os;
- }
-
- public getConnection() {
- if (this.connection == null) {
- this.connection = new MessagingIndexStream(this.os, this.me);
- }
-
- return this.connection;
- }
-}
diff --git a/src/client/app/common/scripts/streaming/messaging.ts b/src/client/app/common/scripts/streaming/messaging.ts
deleted file mode 100644
index a59377d867..0000000000
--- a/src/client/app/common/scripts/streaming/messaging.ts
+++ /dev/null
@@ -1,20 +0,0 @@
-import Stream from './stream';
-import MiOS from '../../../mios';
-
-/**
- * Messaging stream connection
- */
-export class MessagingStream extends Stream {
- constructor(os: MiOS, me, otherparty) {
- super(os, 'messaging', {
- i: me.token,
- otherparty
- });
-
- (this as any).on('_connected_', () => {
- this.send({
- i: me.token
- });
- });
- }
-}
diff --git a/src/client/app/common/scripts/streaming/notes-stats.ts b/src/client/app/common/scripts/streaming/notes-stats.ts
deleted file mode 100644
index 9e3e78a709..0000000000
--- a/src/client/app/common/scripts/streaming/notes-stats.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import Stream from './stream';
-import StreamManager from './stream-manager';
-import MiOS from '../../../mios';
-
-/**
- * Notes stats stream connection
- */
-export class NotesStatsStream extends Stream {
- constructor(os: MiOS) {
- super(os, 'notes-stats');
- }
-}
-
-export class NotesStatsStreamManager extends StreamManager<NotesStatsStream> {
- private os: MiOS;
-
- constructor(os: MiOS) {
- super();
-
- this.os = os;
- }
-
- public getConnection() {
- if (this.connection == null) {
- this.connection = new NotesStatsStream(this.os);
- }
-
- return this.connection;
- }
-}
diff --git a/src/client/app/common/scripts/streaming/server-stats.ts b/src/client/app/common/scripts/streaming/server-stats.ts
deleted file mode 100644
index 9983dfcaf0..0000000000
--- a/src/client/app/common/scripts/streaming/server-stats.ts
+++ /dev/null
@@ -1,30 +0,0 @@
-import Stream from './stream';
-import StreamManager from './stream-manager';
-import MiOS from '../../../mios';
-
-/**
- * Server stats stream connection
- */
-export class ServerStatsStream extends Stream {
- constructor(os: MiOS) {
- super(os, 'server-stats');
- }
-}
-
-export class ServerStatsStreamManager extends StreamManager<ServerStatsStream> {
- private os: MiOS;
-
- constructor(os: MiOS) {
- super();
-
- this.os = os;
- }
-
- public getConnection() {
- if (this.connection == null) {
- this.connection = new ServerStatsStream(this.os);
- }
-
- return this.connection;
- }
-}
diff --git a/src/client/app/common/scripts/streaming/stream-manager.ts b/src/client/app/common/scripts/streaming/stream-manager.ts
deleted file mode 100644
index 8dd06f67d3..0000000000
--- a/src/client/app/common/scripts/streaming/stream-manager.ts
+++ /dev/null
@@ -1,109 +0,0 @@
-import { EventEmitter } from 'eventemitter3';
-import * as uuid from 'uuid';
-import Connection from './stream';
-import { erase } from '../../../../../prelude/array';
-
-/**
- * ストリーム接続を管理するクラス
- * 複数の場所から同じストリームを利用する際、接続をまとめたりする
- */
-export default abstract class StreamManager<T extends Connection> extends EventEmitter {
- private _connection: T = null;
-
- private disposeTimerId: any;
-
- /**
- * コネクションを必要としているユーザー
- */
- private users = [];
-
- protected set connection(connection: T) {
- this._connection = connection;
-
- if (this._connection == null) {
- this.emit('disconnected');
- } else {
- this.emit('connected', this._connection);
-
- this._connection.on('_connected_', () => {
- this.emit('_connected_');
- });
-
- this._connection.on('_disconnected_', () => {
- this.emit('_disconnected_');
- });
-
- this._connection.user = 'Managed';
- }
- }
-
- protected get connection() {
- return this._connection;
- }
-
- /**
- * コネクションを持っているか否か
- */
- public get hasConnection() {
- return this._connection != null;
- }
-
- public get state(): string {
- if (!this.hasConnection) return 'no-connection';
- return this._connection.state;
- }
-
- /**
- * コネクションを要求します
- */
- public abstract getConnection(): T;
-
- /**
- * 現在接続しているコネクションを取得します
- */
- public borrow() {
- return this._connection;
- }
-
- /**
- * コネクションを要求するためのユーザーIDを発行します
- */
- public use() {
- // タイマー解除
- if (this.disposeTimerId) {
- clearTimeout(this.disposeTimerId);
- this.disposeTimerId = null;
- }
-
- // ユーザーID生成
- const userId = uuid();
-
- this.users.push(userId);
-
- this._connection.user = `Managed (${ this.users.length })`;
-
- return userId;
- }
-
- /**
- * コネクションを利用し終わってもう必要ないことを通知します
- * @param userId use で発行したユーザーID
- */
- public dispose(userId) {
- this.users = erase(userId, this.users);
-
- this._connection.user = `Managed (${ this.users.length })`;
-
- // 誰もコネクションの利用者がいなくなったら
- if (this.users.length == 0) {
- // また直ぐに再利用される可能性があるので、一定時間待ち、
- // 新たな利用者が現れなければコネクションを切断する
- this.disposeTimerId = setTimeout(() => {
- this.disposeTimerId = null;
-
- this.connection.close();
- this.connection = null;
- }, 3000);
- }
- }
-}
diff --git a/src/client/app/common/scripts/streaming/stream.ts b/src/client/app/common/scripts/streaming/stream.ts
deleted file mode 100644
index 4ab78f1190..0000000000
--- a/src/client/app/common/scripts/streaming/stream.ts
+++ /dev/null
@@ -1,137 +0,0 @@
-import { EventEmitter } from 'eventemitter3';
-import * as uuid from 'uuid';
-import * as ReconnectingWebsocket from 'reconnecting-websocket';
-import { wsUrl } from '../../../config';
-import MiOS from '../../../mios';
-
-/**
- * Misskey stream connection
- */
-export default class Connection extends EventEmitter {
- public state: string;
- private buffer: any[];
- public socket: ReconnectingWebsocket;
- public name: string;
- public connectedAt: Date;
- public user: string = null;
- public in: number = 0;
- public out: number = 0;
- public inout: Array<{
- type: 'in' | 'out',
- at: Date,
- data: string
- }> = [];
- public id: string;
- public isSuspended = false;
- private os: MiOS;
-
- constructor(os: MiOS, endpoint, params?) {
- super();
-
- //#region BIND
- this.onOpen = this.onOpen.bind(this);
- this.onClose = this.onClose.bind(this);
- this.onMessage = this.onMessage.bind(this);
- this.send = this.send.bind(this);
- this.close = this.close.bind(this);
- //#endregion
-
- this.id = uuid();
- this.os = os;
- this.name = endpoint;
- this.state = 'initializing';
- this.buffer = [];
-
- const query = params
- ? Object.keys(params)
- .map(k => `${encodeURIComponent(k)}=${encodeURIComponent(params[k])}`)
- .join('&')
- : null;
-
- this.socket = new ReconnectingWebsocket(`${wsUrl}/${endpoint}${query ? `?${query}` : ''}`);
- this.socket.addEventListener('open', this.onOpen);
- this.socket.addEventListener('close', this.onClose);
- this.socket.addEventListener('message', this.onMessage);
-
- // Register this connection for debugging
- this.os.registerStreamConnection(this);
- }
-
- /**
- * Callback of when open connection
- */
- private onOpen() {
- this.state = 'connected';
- this.emit('_connected_');
-
- this.connectedAt = new Date();
-
- // バッファーを処理
- const _buffer = [].concat(this.buffer); // Shallow copy
- this.buffer = []; // Clear buffer
- _buffer.forEach(data => {
- this.send(data); // Resend each buffered messages
-
- if (this.os.debug) {
- this.out++;
- this.inout.push({ type: 'out', at: new Date(), data });
- }
- });
- }
-
- /**
- * Callback of when close connection
- */
- private onClose() {
- this.state = 'reconnecting';
- this.emit('_disconnected_');
- }
-
- /**
- * Callback of when received a message from connection
- */
- private onMessage(message) {
- if (this.isSuspended) return;
-
- if (this.os.debug) {
- this.in++;
- this.inout.push({ type: 'in', at: new Date(), data: message.data });
- }
-
- try {
- const msg = JSON.parse(message.data);
- if (msg.type) this.emit(msg.type, msg.body);
- } catch (e) {
- // noop
- }
- }
-
- /**
- * Send a message to connection
- */
- public send(data) {
- if (this.isSuspended) return;
-
- // まだ接続が確立されていなかったらバッファリングして次に接続した時に送信する
- if (this.state != 'connected') {
- this.buffer.push(data);
- return;
- }
-
- if (this.os.debug) {
- this.out++;
- this.inout.push({ type: 'out', at: new Date(), data });
- }
-
- this.socket.send(JSON.stringify(data));
- }
-
- /**
- * Close this connection
- */
- public close() {
- this.os.unregisterStreamConnection(this);
- this.socket.removeEventListener('open', this.onOpen);
- this.socket.removeEventListener('message', this.onMessage);
- }
-}
diff --git a/src/client/app/common/scripts/streaming/user-list.ts b/src/client/app/common/scripts/streaming/user-list.ts
deleted file mode 100644
index 30a52b98dd..0000000000
--- a/src/client/app/common/scripts/streaming/user-list.ts
+++ /dev/null
@@ -1,17 +0,0 @@
-import Stream from './stream';
-import MiOS from '../../mios';
-
-export class UserListStream extends Stream {
- constructor(os: MiOS, me, listId) {
- super(os, 'user-list', {
- i: me.token,
- listId
- });
-
- (this as any).on('_connected_', () => {
- this.send({
- i: me.token
- });
- });
- }
-}