Browse Source

🎈 perf: 同步后端人数

wolyshaw 3 years ago
parent
commit
94c41e4ad9

+ 1 - 0
src/components/live-broadcast/event.ts

@@ -16,6 +16,7 @@ export const LIVE_EVENT_MESSAGE = {
   'RC:ForcedOffline': 'ForcedOffline',
   'RC:LookerLoginOut': 'LookerLoginOut',
   'RC:Chatroom:downSeat': 'DownSeat',
+  'RC:Chatroom:MemberCount': 'MemberCount',
 }
 
 export default mitt()

+ 12 - 0
src/components/live-message/model/look-model.tsx

@@ -38,10 +38,15 @@ export default defineComponent({
     await this._init()
     this.loadingLook = true
     event.on(LIVE_EVENT_MESSAGE["RC:Chatroom:Welcome"], this.onWelcome);
+    event.on(LIVE_EVENT_MESSAGE["RC:Chatroom:MemberCount"], this.onMemberCount);
     setTimeout(() => {
       this.loadingLook = false;
     })
   },
+  beforeUnmount() {
+    event.off(LIVE_EVENT_MESSAGE["RC:Chatroom:Welcome"], this.onWelcome);
+    event.off(LIVE_EVENT_MESSAGE["RC:Chatroom:MemberCount"], this.onMemberCount);
+  },
   methods: {
     async _init() {
       try {
@@ -68,6 +73,13 @@ export default defineComponent({
         //
       }
     },
+    /**
+     * 当后端发送人数消息时,更新人数
+     */
+    onMemberCount(evt: any) {
+      runtime.lookCount = evt.content.count || 0
+      RuntimeUtils.sendMessage({ count: runtime.lookCount }, 'MemberCount')
+    },
     async onWelcome(value: any) {
       // console.log(value)
       if (value && value.user) {