浏览代码

添加事件

lex-xin 3 年之前
父节点
当前提交
5240232b9b

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

@@ -13,6 +13,8 @@ export const LIVE_EVENT_MESSAGE = {
   'RM:RTC:SwitchRole': 'SwitchRole',
   'RM:RTC:SwitchRole': 'SwitchRole',
   'RM:RTC:UserLeave': 'UserLeave',
   'RM:RTC:UserLeave': 'UserLeave',
   'RC:Chatroom:Leave': 'Leave',
   'RC:Chatroom:Leave': 'Leave',
+  'RC:ForcedOffline': 'ForcedOffline',
+  'RC:LookerLoginOut': 'LookerLoginOut',
 }
 }
 
 
 export default mitt()
 export default mitt()

+ 8 - 4
src/components/live-message/model/join-model.tsx

@@ -42,13 +42,17 @@ export default defineComponent({
     event.on(LIVE_EVENT_MESSAGE['RC:Chatroom:SeatResponse'], this.onSeatApply);
     event.on(LIVE_EVENT_MESSAGE['RC:Chatroom:SeatResponse'], this.onSeatApply);
     event.on(LIVE_EVENT_MESSAGE['RM:RTC:UserLeave'], this.onSeatApply);
     event.on(LIVE_EVENT_MESSAGE['RM:RTC:UserLeave'], this.onSeatApply);
     event.on(LIVE_EVENT_MESSAGE['RM:RTC:SwitchRole'], this.onSwitchRole);
     event.on(LIVE_EVENT_MESSAGE['RM:RTC:SwitchRole'], this.onSwitchRole);
-    event.on(LIVE_EVENT_MESSAGE['RC:Chatroom:Leave'], this.onLeave);
+    event.on(LIVE_EVENT_MESSAGE['RC:Chatroom:Leave'], this.onLeave); // 移动端接收的消息
+    event.on(LIVE_EVENT_MESSAGE['RC:LookerLoginOut'], this.onLeave); // 后台接收的消息
   },
   },
   methods: {
   methods: {
     onLeave(value: any) {
     onLeave(value: any) {
-      // console.log(value)
-      RuntimeModelUtils.removeJoin(value.userId)
-      RuntimeModelUtils.removeLook(value.userId)
+      if(runtimeModel.joinList[value.userId]) {
+        RuntimeModelUtils.removeJoin(value.userId)
+      }
+      if(runtimeModel.lookList[value.userId]) {
+        RuntimeModelUtils.removeLook(value.userId)
+      }
     },
     },
     onSeatApply(evt: any) {
     onSeatApply(evt: any) {
       // console.log(evt, 'onSeatApply joinModel')
       // console.log(evt, 'onSeatApply joinModel')

+ 23 - 1
src/components/live-message/model/message-model.tsx

@@ -4,11 +4,14 @@ import { ElTag } from "element-plus";
 // import VirtualList from 'vue3-virtual-list'
 // import VirtualList from 'vue3-virtual-list'
 // import { RecycleScroller } from 'vue-virtual-scroller'
 // import { RecycleScroller } from 'vue-virtual-scroller'
 import styles from './index.module.less'
 import styles from './index.module.less'
+import request from '/src/helpers/request';
 import event, { LIVE_EVENT_MESSAGE } from '/src/components/live-broadcast/event';
 import event, { LIVE_EVENT_MESSAGE } from '/src/components/live-broadcast/event';
 import { state } from '/src/state'
 import { state } from '/src/state'
 import dayjs from 'dayjs';
 import dayjs from 'dayjs';
 import Empty from "/src/components/empty";
 import Empty from "/src/components/empty";
 import runtime, * as RuntimeUtils from '/src/components/live-message/model/runtime'
 import runtime, * as RuntimeUtils from '/src/components/live-message/model/runtime'
+import runtimeCast, * as RuntimeUtilCast from "/src/components/live-broadcast/runtime";
+import { removeToken } from "/src/utils/auth";
 
 
 export default defineComponent({
 export default defineComponent({
   data() {
   data() {
@@ -21,6 +24,7 @@ export default defineComponent({
     this.loadingMessage = true
     this.loadingMessage = true
     event.on(LIVE_EVENT_MESSAGE["RC:TxtMsg"], this.onMessage);
     event.on(LIVE_EVENT_MESSAGE["RC:TxtMsg"], this.onMessage);
     event.on(LIVE_EVENT_MESSAGE["RC:Chatroom:Like"], this.onLike)
     event.on(LIVE_EVENT_MESSAGE["RC:Chatroom:Like"], this.onLike)
+    event.on(LIVE_EVENT_MESSAGE["RC:ForcedOffline"], this.onForcedOffline)
 
 
     setTimeout(() => {
     setTimeout(() => {
       this.loadingMessage = false;
       this.loadingMessage = false;
@@ -32,6 +36,24 @@ export default defineComponent({
     event.off(LIVE_EVENT_MESSAGE["RC:Chatroom:Like"], this.onLike);
     event.off(LIVE_EVENT_MESSAGE["RC:Chatroom:Like"], this.onLike);
   },
   },
   methods: {
   methods: {
+    async onForcedOffline() {
+      // 强制退出登录
+      try {
+        await request.post('/api-auth/exit', { data: {} });
+        RuntimeUtilCast.closeDevice('camera')
+        RuntimeUtilCast.closeDevice('microphone')
+        state.user = null
+        removeToken();
+        (this as any).$router.push({
+          path: '/login',
+          query: {
+            ...this.$route.query
+          }
+        });
+      } catch (e) {
+        // TODO: handle error
+      }
+    },
     onLike(value: any) {
     onLike(value: any) {
       if (value && value.user) {
       if (value && value.user) {
         const sendTime = dayjs(value.$EventMessage.sentTime || new Date()).format('HH:mm:ss')
         const sendTime = dayjs(value.$EventMessage.sentTime || new Date()).format('HH:mm:ss')
@@ -97,7 +119,7 @@ export default defineComponent({
           </div>
           </div>
         )) : (this.loadingMessage ? <div class={styles.loadingStyle}>
         )) : (this.loadingMessage ? <div class={styles.loadingStyle}>
           <div class="el-loading-mask" style="background-color: rgba(0, 0, 0, 0.8);"><div class="el-loading-spinner"><svg class="circular" viewBox="25 25 50 50"><circle class="path" cx="50" cy="50" r="20" fill="none"></circle></svg></div></div>
           <div class="el-loading-mask" style="background-color: rgba(0, 0, 0, 0.8);"><div class="el-loading-spinner"><svg class="circular" viewBox="25 25 50 50"><circle class="path" cx="50" cy="50" r="20" fill="none"></circle></svg></div></div>
-          </div>: <Empty style={{ paddingTop: '120px' }} text="暂无学员互动!" icon="noData-no-message" />)}
+        </div> : <Empty style={{ paddingTop: '120px' }} text="暂无学员互动!" icon="noData-no-message" />)}
       </div>
       </div>
     )
     )
   }
   }