summaryrefslogtreecommitdiff
path: root/src/server/api/stream/channels
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/server/api/stream/channels
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/server/api/stream/channels')
-rw-r--r--src/server/api/stream/channels/drive.ts12
-rw-r--r--src/server/api/stream/channels/games/reversi-game.ts309
-rw-r--r--src/server/api/stream/channels/games/reversi.ts30
-rw-r--r--src/server/api/stream/channels/global-timeline.ts39
-rw-r--r--src/server/api/stream/channels/hashtag.ts33
-rw-r--r--src/server/api/stream/channels/home-timeline.ts39
-rw-r--r--src/server/api/stream/channels/hybrid-timeline.ts41
-rw-r--r--src/server/api/stream/channels/index.ts31
-rw-r--r--src/server/api/stream/channels/local-timeline.ts39
-rw-r--r--src/server/api/stream/channels/main.ts25
-rw-r--r--src/server/api/stream/channels/messaging-index.ts12
-rw-r--r--src/server/api/stream/channels/messaging.ts26
-rw-r--r--src/server/api/stream/channels/notes-stats.ts34
-rw-r--r--src/server/api/stream/channels/server-stats.ts37
-rw-r--r--src/server/api/stream/channels/user-list.ts14
15 files changed, 721 insertions, 0 deletions
diff --git a/src/server/api/stream/channels/drive.ts b/src/server/api/stream/channels/drive.ts
new file mode 100644
index 0000000000..807fc93cd0
--- /dev/null
+++ b/src/server/api/stream/channels/drive.ts
@@ -0,0 +1,12 @@
+import autobind from 'autobind-decorator';
+import Channel from '../channel';
+
+export default class extends Channel {
+ @autobind
+ public async init(params: any) {
+ // Subscribe drive stream
+ this.subscriber.on(`driveStream:${this.user._id}`, data => {
+ this.send(data);
+ });
+ }
+}
diff --git a/src/server/api/stream/channels/games/reversi-game.ts b/src/server/api/stream/channels/games/reversi-game.ts
new file mode 100644
index 0000000000..11f1fb1feb
--- /dev/null
+++ b/src/server/api/stream/channels/games/reversi-game.ts
@@ -0,0 +1,309 @@
+import autobind from 'autobind-decorator';
+import * as CRC32 from 'crc-32';
+import ReversiGame, { pack } from '../../../../../models/games/reversi/game';
+import { publishReversiGameStream } from '../../../../../stream';
+import Reversi from '../../../../../games/reversi/core';
+import * as maps from '../../../../../games/reversi/maps';
+import Channel from '../../channel';
+
+export default class extends Channel {
+ private gameId: string;
+
+ @autobind
+ public async init(params: any) {
+ this.gameId = params.gameId as string;
+
+ // Subscribe game stream
+ this.subscriber.on(`reversiGameStream:${this.gameId}`, data => {
+ this.send(data);
+ });
+ }
+
+ @autobind
+ public onMessage(type: string, body: any) {
+ switch (type) {
+ case 'accept': this.accept(true); break;
+ case 'cancel-accept': this.accept(false); break;
+ case 'update-settings': this.updateSettings(body.settings); break;
+ case 'init-form': this.initForm(body); break;
+ case 'update-form': this.updateForm(body.id, body.value); break;
+ case 'message': this.message(body); break;
+ case 'set': this.set(body.pos); break;
+ case 'check': this.check(body.crc32); break;
+ }
+ }
+
+ @autobind
+ private async updateSettings(settings: any) {
+ const game = await ReversiGame.findOne({ _id: this.gameId });
+
+ if (game.isStarted) return;
+ if (!game.user1Id.equals(this.user._id) && !game.user2Id.equals(this.user._id)) return;
+ if (game.user1Id.equals(this.user._id) && game.user1Accepted) return;
+ if (game.user2Id.equals(this.user._id) && game.user2Accepted) return;
+
+ await ReversiGame.update({ _id: this.gameId }, {
+ $set: {
+ settings
+ }
+ });
+
+ publishReversiGameStream(this.gameId, 'updateSettings', settings);
+ }
+
+ @autobind
+ private async initForm(form: any) {
+ const game = await ReversiGame.findOne({ _id: this.gameId });
+
+ if (game.isStarted) return;
+ if (!game.user1Id.equals(this.user._id) && !game.user2Id.equals(this.user._id)) return;
+
+ const set = game.user1Id.equals(this.user._id) ? {
+ form1: form
+ } : {
+ form2: form
+ };
+
+ await ReversiGame.update({ _id: this.gameId }, {
+ $set: set
+ });
+
+ publishReversiGameStream(this.gameId, 'initForm', {
+ userId: this.user._id,
+ form
+ });
+ }
+
+ @autobind
+ private async updateForm(id: string, value: any) {
+ const game = await ReversiGame.findOne({ _id: this.gameId });
+
+ if (game.isStarted) return;
+ if (!game.user1Id.equals(this.user._id) && !game.user2Id.equals(this.user._id)) return;
+
+ const form = game.user1Id.equals(this.user._id) ? game.form2 : game.form1;
+
+ const item = form.find((i: any) => i.id == id);
+
+ if (item == null) return;
+
+ item.value = value;
+
+ const set = game.user1Id.equals(this.user._id) ? {
+ form2: form
+ } : {
+ form1: form
+ };
+
+ await ReversiGame.update({ _id: this.gameId }, {
+ $set: set
+ });
+
+ publishReversiGameStream(this.gameId, 'updateForm', {
+ userId: this.user._id,
+ id,
+ value
+ });
+ }
+
+ @autobind
+ private async message(message: any) {
+ message.id = Math.random();
+ publishReversiGameStream(this.gameId, 'message', {
+ userId: this.user._id,
+ message
+ });
+ }
+
+ @autobind
+ private async accept(accept: boolean) {
+ const game = await ReversiGame.findOne({ _id: this.gameId });
+
+ if (game.isStarted) return;
+
+ let bothAccepted = false;
+
+ if (game.user1Id.equals(this.user._id)) {
+ await ReversiGame.update({ _id: this.gameId }, {
+ $set: {
+ user1Accepted: accept
+ }
+ });
+
+ publishReversiGameStream(this.gameId, 'changeAccepts', {
+ user1: accept,
+ user2: game.user2Accepted
+ });
+
+ if (accept && game.user2Accepted) bothAccepted = true;
+ } else if (game.user2Id.equals(this.user._id)) {
+ await ReversiGame.update({ _id: this.gameId }, {
+ $set: {
+ user2Accepted: accept
+ }
+ });
+
+ publishReversiGameStream(this.gameId, 'changeAccepts', {
+ user1: game.user1Accepted,
+ user2: accept
+ });
+
+ if (accept && game.user1Accepted) bothAccepted = true;
+ } else {
+ return;
+ }
+
+ if (bothAccepted) {
+ // 3秒後、まだacceptされていたらゲーム開始
+ setTimeout(async () => {
+ const freshGame = await ReversiGame.findOne({ _id: this.gameId });
+ if (freshGame == null || freshGame.isStarted || freshGame.isEnded) return;
+ if (!freshGame.user1Accepted || !freshGame.user2Accepted) return;
+
+ let bw: number;
+ if (freshGame.settings.bw == 'random') {
+ bw = Math.random() > 0.5 ? 1 : 2;
+ } else {
+ bw = freshGame.settings.bw as number;
+ }
+
+ function getRandomMap() {
+ const mapCount = Object.entries(maps).length;
+ const rnd = Math.floor(Math.random() * mapCount);
+ return Object.values(maps)[rnd].data;
+ }
+
+ const map = freshGame.settings.map != null ? freshGame.settings.map : getRandomMap();
+
+ await ReversiGame.update({ _id: this.gameId }, {
+ $set: {
+ startedAt: new Date(),
+ isStarted: true,
+ black: bw,
+ 'settings.map': map
+ }
+ });
+
+ //#region 盤面に最初から石がないなどして始まった瞬間に勝敗が決定する場合があるのでその処理
+ const o = new Reversi(map, {
+ isLlotheo: freshGame.settings.isLlotheo,
+ canPutEverywhere: freshGame.settings.canPutEverywhere,
+ loopedBoard: freshGame.settings.loopedBoard
+ });
+
+ if (o.isEnded) {
+ let winner;
+ if (o.winner === true) {
+ winner = freshGame.black == 1 ? freshGame.user1Id : freshGame.user2Id;
+ } else if (o.winner === false) {
+ winner = freshGame.black == 1 ? freshGame.user2Id : freshGame.user1Id;
+ } else {
+ winner = null;
+ }
+
+ await ReversiGame.update({
+ _id: this.gameId
+ }, {
+ $set: {
+ isEnded: true,
+ winnerId: winner
+ }
+ });
+
+ publishReversiGameStream(this.gameId, 'ended', {
+ winnerId: winner,
+ game: await pack(this.gameId, this.user)
+ });
+ }
+ //#endregion
+
+ publishReversiGameStream(this.gameId, 'started', await pack(this.gameId, this.user));
+ }, 3000);
+ }
+ }
+
+ // 石を打つ
+ @autobind
+ private async set(pos: number) {
+ const game = await ReversiGame.findOne({ _id: this.gameId });
+
+ if (!game.isStarted) return;
+ if (game.isEnded) return;
+ if (!game.user1Id.equals(this.user._id) && !game.user2Id.equals(this.user._id)) return;
+
+ const o = new Reversi(game.settings.map, {
+ isLlotheo: game.settings.isLlotheo,
+ canPutEverywhere: game.settings.canPutEverywhere,
+ loopedBoard: game.settings.loopedBoard
+ });
+
+ game.logs.forEach(log => {
+ o.put(log.color, log.pos);
+ });
+
+ const myColor =
+ (game.user1Id.equals(this.user._id) && game.black == 1) || (game.user2Id.equals(this.user._id) && game.black == 2)
+ ? true
+ : false;
+
+ if (!o.canPut(myColor, pos)) return;
+ o.put(myColor, pos);
+
+ let winner;
+ if (o.isEnded) {
+ if (o.winner === true) {
+ winner = game.black == 1 ? game.user1Id : game.user2Id;
+ } else if (o.winner === false) {
+ winner = game.black == 1 ? game.user2Id : game.user1Id;
+ } else {
+ winner = null;
+ }
+ }
+
+ const log = {
+ at: new Date(),
+ color: myColor,
+ pos
+ };
+
+ const crc32 = CRC32.str(game.logs.map(x => x.pos.toString()).join('') + pos.toString());
+
+ await ReversiGame.update({
+ _id: this.gameId
+ }, {
+ $set: {
+ crc32,
+ isEnded: o.isEnded,
+ winnerId: winner
+ },
+ $push: {
+ logs: log
+ }
+ });
+
+ publishReversiGameStream(this.gameId, 'set', Object.assign(log, {
+ next: o.turn
+ }));
+
+ if (o.isEnded) {
+ publishReversiGameStream(this.gameId, 'ended', {
+ winnerId: winner,
+ game: await pack(this.gameId, this.user)
+ });
+ }
+ }
+
+ @autobind
+ private async check(crc32: string) {
+ const game = await ReversiGame.findOne({ _id: this.gameId });
+
+ if (!game.isStarted) return;
+
+ // 互換性のため
+ if (game.crc32 == null) return;
+
+ if (crc32 !== game.crc32) {
+ this.send('rescue', await pack(game, this.user));
+ }
+ }
+}
diff --git a/src/server/api/stream/channels/games/reversi.ts b/src/server/api/stream/channels/games/reversi.ts
new file mode 100644
index 0000000000..d75025c944
--- /dev/null
+++ b/src/server/api/stream/channels/games/reversi.ts
@@ -0,0 +1,30 @@
+import autobind from 'autobind-decorator';
+import * as mongo from 'mongodb';
+import Matching, { pack } from '../../../../../models/games/reversi/matching';
+import { publishMainStream } from '../../../../../stream';
+import Channel from '../../channel';
+
+export default class extends Channel {
+ @autobind
+ public async init(params: any) {
+ // Subscribe reversi stream
+ this.subscriber.on(`reversiStream:${this.user._id}`, data => {
+ this.send(data);
+ });
+ }
+
+ @autobind
+ public async onMessage(type: string, body: any) {
+ switch (type) {
+ case 'ping':
+ if (body.id == null) return;
+ const matching = await Matching.findOne({
+ parentId: this.user._id,
+ childId: new mongo.ObjectID(body.id)
+ });
+ if (matching == null) return;
+ publishMainStream(matching.childId, 'reversiInvited', await pack(matching, matching.childId));
+ break;
+ }
+ }
+}
diff --git a/src/server/api/stream/channels/global-timeline.ts b/src/server/api/stream/channels/global-timeline.ts
new file mode 100644
index 0000000000..ab0fe5d094
--- /dev/null
+++ b/src/server/api/stream/channels/global-timeline.ts
@@ -0,0 +1,39 @@
+import autobind from 'autobind-decorator';
+import Mute from '../../../../models/mute';
+import { pack } from '../../../../models/note';
+import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
+import Channel from '../channel';
+
+export default class extends Channel {
+ private mutedUserIds: string[] = [];
+
+ @autobind
+ public async init(params: any) {
+ // Subscribe events
+ this.subscriber.on('globalTimeline', this.onNote);
+
+ const mute = await Mute.find({ muterId: this.user._id });
+ this.mutedUserIds = mute.map(m => m.muteeId.toString());
+ }
+
+ @autobind
+ private async onNote(note: any) {
+ // Renoteなら再pack
+ if (note.renoteId != null) {
+ note.renote = await pack(note.renoteId, this.user, {
+ detail: true
+ });
+ }
+
+ // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
+ if (shouldMuteThisNote(note, this.mutedUserIds)) return;
+
+ this.send('note', note);
+ }
+
+ @autobind
+ public dispose() {
+ // Unsubscribe events
+ this.subscriber.off('globalTimeline', this.onNote);
+ }
+}
diff --git a/src/server/api/stream/channels/hashtag.ts b/src/server/api/stream/channels/hashtag.ts
new file mode 100644
index 0000000000..652b0caa5b
--- /dev/null
+++ b/src/server/api/stream/channels/hashtag.ts
@@ -0,0 +1,33 @@
+import autobind from 'autobind-decorator';
+import Mute from '../../../../models/mute';
+import { pack } from '../../../../models/note';
+import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
+import Channel from '../channel';
+
+export default class extends Channel {
+ @autobind
+ public async init(params: any) {
+ const mute = this.user ? await Mute.find({ muterId: this.user._id }) : null;
+ const mutedUserIds = mute ? mute.map(m => m.muteeId.toString()) : [];
+
+ const q: Array<string[]> = params.q;
+
+ // Subscribe stream
+ this.subscriber.on('hashtag', async note => {
+ const matched = q.some(tags => tags.every(tag => note.tags.map((t: string) => t.toLowerCase()).includes(tag.toLowerCase())));
+ if (!matched) return;
+
+ // Renoteなら再pack
+ if (note.renoteId != null) {
+ note.renote = await pack(note.renoteId, this.user, {
+ detail: true
+ });
+ }
+
+ // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
+ if (shouldMuteThisNote(note, mutedUserIds)) return;
+
+ this.send('note', note);
+ });
+ }
+}
diff --git a/src/server/api/stream/channels/home-timeline.ts b/src/server/api/stream/channels/home-timeline.ts
new file mode 100644
index 0000000000..4c674e75ef
--- /dev/null
+++ b/src/server/api/stream/channels/home-timeline.ts
@@ -0,0 +1,39 @@
+import autobind from 'autobind-decorator';
+import Mute from '../../../../models/mute';
+import { pack } from '../../../../models/note';
+import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
+import Channel from '../channel';
+
+export default class extends Channel {
+ private mutedUserIds: string[] = [];
+
+ @autobind
+ public async init(params: any) {
+ // Subscribe events
+ this.subscriber.on(`homeTimeline:${this.user._id}`, this.onNote);
+
+ const mute = await Mute.find({ muterId: this.user._id });
+ this.mutedUserIds = mute.map(m => m.muteeId.toString());
+ }
+
+ @autobind
+ private async onNote(note: any) {
+ // Renoteなら再pack
+ if (note.renoteId != null) {
+ note.renote = await pack(note.renoteId, this.user, {
+ detail: true
+ });
+ }
+
+ // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
+ if (shouldMuteThisNote(note, this.mutedUserIds)) return;
+
+ this.send('note', note);
+ }
+
+ @autobind
+ public dispose() {
+ // Unsubscribe events
+ this.subscriber.off(`homeTimeline:${this.user._id}`, this.onNote);
+ }
+}
diff --git a/src/server/api/stream/channels/hybrid-timeline.ts b/src/server/api/stream/channels/hybrid-timeline.ts
new file mode 100644
index 0000000000..0b12ab3a8f
--- /dev/null
+++ b/src/server/api/stream/channels/hybrid-timeline.ts
@@ -0,0 +1,41 @@
+import autobind from 'autobind-decorator';
+import Mute from '../../../../models/mute';
+import { pack } from '../../../../models/note';
+import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
+import Channel from '../channel';
+
+export default class extends Channel {
+ private mutedUserIds: string[] = [];
+
+ @autobind
+ public async init(params: any) {
+ // Subscribe events
+ this.subscriber.on('hybridTimeline', this.onNewNote);
+ this.subscriber.on(`hybridTimeline:${this.user._id}`, this.onNewNote);
+
+ const mute = await Mute.find({ muterId: this.user._id });
+ this.mutedUserIds = mute.map(m => m.muteeId.toString());
+ }
+
+ @autobind
+ private async onNewNote(note: any) {
+ // Renoteなら再pack
+ if (note.renoteId != null) {
+ note.renote = await pack(note.renoteId, this.user, {
+ detail: true
+ });
+ }
+
+ // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
+ if (shouldMuteThisNote(note, this.mutedUserIds)) return;
+
+ this.send('note', note);
+ }
+
+ @autobind
+ public dispose() {
+ // Unsubscribe events
+ this.subscriber.off('hybridTimeline', this.onNewNote);
+ this.subscriber.off(`hybridTimeline:${this.user._id}`, this.onNewNote);
+ }
+}
diff --git a/src/server/api/stream/channels/index.ts b/src/server/api/stream/channels/index.ts
new file mode 100644
index 0000000000..7e71590d00
--- /dev/null
+++ b/src/server/api/stream/channels/index.ts
@@ -0,0 +1,31 @@
+import main from './main';
+import homeTimeline from './home-timeline';
+import localTimeline from './local-timeline';
+import hybridTimeline from './hybrid-timeline';
+import globalTimeline from './global-timeline';
+import notesStats from './notes-stats';
+import serverStats from './server-stats';
+import userList from './user-list';
+import messaging from './messaging';
+import messagingIndex from './messaging-index';
+import drive from './drive';
+import hashtag from './hashtag';
+import gamesReversi from './games/reversi';
+import gamesReversiGame from './games/reversi-game';
+
+export default {
+ main,
+ homeTimeline,
+ localTimeline,
+ hybridTimeline,
+ globalTimeline,
+ notesStats,
+ serverStats,
+ userList,
+ messaging,
+ messagingIndex,
+ drive,
+ hashtag,
+ gamesReversi,
+ gamesReversiGame
+};
diff --git a/src/server/api/stream/channels/local-timeline.ts b/src/server/api/stream/channels/local-timeline.ts
new file mode 100644
index 0000000000..769ec6392f
--- /dev/null
+++ b/src/server/api/stream/channels/local-timeline.ts
@@ -0,0 +1,39 @@
+import autobind from 'autobind-decorator';
+import Mute from '../../../../models/mute';
+import { pack } from '../../../../models/note';
+import shouldMuteThisNote from '../../../../misc/should-mute-this-note';
+import Channel from '../channel';
+
+export default class extends Channel {
+ private mutedUserIds: string[] = [];
+
+ @autobind
+ public async init(params: any) {
+ // Subscribe events
+ this.subscriber.on('localTimeline', this.onNote);
+
+ const mute = this.user ? await Mute.find({ muterId: this.user._id }) : null;
+ this.mutedUserIds = mute ? mute.map(m => m.muteeId.toString()) : [];
+ }
+
+ @autobind
+ private async onNote(note: any) {
+ // Renoteなら再pack
+ if (note.renoteId != null) {
+ note.renote = await pack(note.renoteId, this.user, {
+ detail: true
+ });
+ }
+
+ // 流れてきたNoteがミュートしているユーザーが関わるものだったら無視する
+ if (shouldMuteThisNote(note, this.mutedUserIds)) return;
+
+ this.send('note', note);
+ }
+
+ @autobind
+ public dispose() {
+ // Unsubscribe events
+ this.subscriber.off('localTimeline', this.onNote);
+ }
+}
diff --git a/src/server/api/stream/channels/main.ts b/src/server/api/stream/channels/main.ts
new file mode 100644
index 0000000000..a6c5b12760
--- /dev/null
+++ b/src/server/api/stream/channels/main.ts
@@ -0,0 +1,25 @@
+import autobind from 'autobind-decorator';
+import Mute from '../../../../models/mute';
+import Channel from '../channel';
+
+export default class extends Channel {
+ @autobind
+ public async init(params: any) {
+ const mute = await Mute.find({ muterId: this.user._id });
+ const mutedUserIds = mute.map(m => m.muteeId.toString());
+
+ // Subscribe main stream channel
+ this.subscriber.on(`mainStream:${this.user._id}`, async data => {
+ const { type, body } = data;
+
+ switch (type) {
+ case 'notification': {
+ if (!mutedUserIds.includes(body.userId)) {
+ this.send('notification', body);
+ }
+ break;
+ }
+ }
+ });
+ }
+}
diff --git a/src/server/api/stream/channels/messaging-index.ts b/src/server/api/stream/channels/messaging-index.ts
new file mode 100644
index 0000000000..6e87cca7f4
--- /dev/null
+++ b/src/server/api/stream/channels/messaging-index.ts
@@ -0,0 +1,12 @@
+import autobind from 'autobind-decorator';
+import Channel from '../channel';
+
+export default class extends Channel {
+ @autobind
+ public async init(params: any) {
+ // Subscribe messaging index stream
+ this.subscriber.on(`messagingIndexStream:${this.user._id}`, data => {
+ this.send(data);
+ });
+ }
+}
diff --git a/src/server/api/stream/channels/messaging.ts b/src/server/api/stream/channels/messaging.ts
new file mode 100644
index 0000000000..e1a78c8678
--- /dev/null
+++ b/src/server/api/stream/channels/messaging.ts
@@ -0,0 +1,26 @@
+import autobind from 'autobind-decorator';
+import read from '../../common/read-messaging-message';
+import Channel from '../channel';
+
+export default class extends Channel {
+ private otherpartyId: string;
+
+ @autobind
+ public async init(params: any) {
+ this.otherpartyId = params.otherparty as string;
+
+ // Subscribe messaging stream
+ this.subscriber.on(`messagingStream:${this.user._id}-${this.otherpartyId}`, data => {
+ this.send(data);
+ });
+ }
+
+ @autobind
+ public onMessage(type: string, body: any) {
+ switch (type) {
+ case 'read':
+ read(this.user._id, this.otherpartyId, body.id);
+ break;
+ }
+ }
+}
diff --git a/src/server/api/stream/channels/notes-stats.ts b/src/server/api/stream/channels/notes-stats.ts
new file mode 100644
index 0000000000..cc68d9886d
--- /dev/null
+++ b/src/server/api/stream/channels/notes-stats.ts
@@ -0,0 +1,34 @@
+import autobind from 'autobind-decorator';
+import Xev from 'xev';
+import Channel from '../channel';
+
+const ev = new Xev();
+
+export default class extends Channel {
+ @autobind
+ public async init(params: any) {
+ ev.addListener('notesStats', this.onStats);
+ }
+
+ @autobind
+ private onStats(stats: any) {
+ this.send('stats', stats);
+ }
+
+ @autobind
+ public onMessage(type: string, body: any) {
+ switch (type) {
+ case 'requestLog':
+ ev.once(`notesStatsLog:${body.id}`, statsLog => {
+ this.send('statsLog', statsLog);
+ });
+ ev.emit('requestNotesStatsLog', body.id);
+ break;
+ }
+ }
+
+ @autobind
+ public dispose() {
+ ev.removeListener('notesStats', this.onStats);
+ }
+}
diff --git a/src/server/api/stream/channels/server-stats.ts b/src/server/api/stream/channels/server-stats.ts
new file mode 100644
index 0000000000..28a566e8ae
--- /dev/null
+++ b/src/server/api/stream/channels/server-stats.ts
@@ -0,0 +1,37 @@
+import autobind from 'autobind-decorator';
+import Xev from 'xev';
+import Channel from '../channel';
+
+const ev = new Xev();
+
+export default class extends Channel {
+ @autobind
+ public async init(params: any) {
+ ev.addListener('serverStats', this.onStats);
+ }
+
+ @autobind
+ private onStats(stats: any) {
+ this.send('stats', stats);
+ }
+
+ @autobind
+ public onMessage(type: string, body: any) {
+ switch (type) {
+ case 'requestLog':
+ ev.once(`serverStatsLog:${body.id}`, statsLog => {
+ this.send('statsLog', statsLog);
+ });
+ ev.emit('requestServerStatsLog', {
+ id: body.id,
+ length: body.length
+ });
+ break;
+ }
+ }
+
+ @autobind
+ public dispose() {
+ ev.removeListener('serverStats', this.onStats);
+ }
+}
diff --git a/src/server/api/stream/channels/user-list.ts b/src/server/api/stream/channels/user-list.ts
new file mode 100644
index 0000000000..4ace308923
--- /dev/null
+++ b/src/server/api/stream/channels/user-list.ts
@@ -0,0 +1,14 @@
+import autobind from 'autobind-decorator';
+import Channel from '../channel';
+
+export default class extends Channel {
+ @autobind
+ public async init(params: any) {
+ const listId = params.listId as string;
+
+ // Subscribe stream
+ this.subscriber.on(`userListStream:${listId}`, data => {
+ this.send(data);
+ });
+ }
+}