From 380d357a740b4b2d90158b57d1c496f0a5077aa6 Mon Sep 17 00:00:00 2001 From: tamaina Date: Sun, 12 Sep 2021 01:27:20 +0900 Subject: [PATCH] refactor --- src/server/api/stream/index.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/server/api/stream/index.ts b/src/server/api/stream/index.ts index 7a980093f7..ba0a8f6e25 100644 --- a/src/server/api/stream/index.ts +++ b/src/server/api/stream/index.ts @@ -47,8 +47,8 @@ export default class Connection { this.wsConnection.on('message', this.onWsConnectionMessage); - this.subscriber.on('broadcast', async ev => { - this.onBroadcastMessage(ev.type, ev.body); + this.subscriber.on('broadcast', data => { + this.onBroadcastMessage(data); }); if (this.user) { @@ -58,9 +58,7 @@ export default class Connection { this.updateFollowingChannels(); this.updateUserProfile(); - this.subscriber.on(`user:${this.user.id}`, ev => { - this.onUserEvent(ev); - }); + this.subscriber.on(`user:${this.user.id}`, this.onUserEvent); } } @@ -146,8 +144,8 @@ export default class Connection { } @autobind - private onBroadcastMessage(type: string, body: any) { - this.sendMessageToWs(type, body); + private onBroadcastMessage(data: StreamMessages['broadcast']['spec']) { + this.sendMessageToWs(data.type, data.body); } @autobind