Browse Source

优化初始化

gemercheung 2 years ago
parent
commit
31431f0eef

+ 1 - 1
src/components/chatRoom/controls/sync.ts

@@ -1,13 +1,13 @@
 import { getApp } from '/@/hooks/userApp';
 import { useRtcStore } from '/@/store/modules/rtc';
 
+// const isInit = false;
 // 同屏帶看
 export async function handleSync(data: any) {
   try {
     const app = getApp();
     const rtcStore = useRtcStore();
     if (!rtcStore.isLeader) {
-      // app.Connect.follow.start({ follow: false });
       // console.log('app.Connect.follow', app.Connect.follow.started)
       app.Connect.follow.receive(data);
     }

+ 21 - 9
src/components/chatRoom/index.vue

@@ -251,15 +251,27 @@
   };
 
   onMounted(async () => {
-    const app = await useApp();
-    // app.Connect.follow.start({ follow: !unref(isNativeLeader) });
-    watchEffect(() => {
-      if (unref(isNativeLeader)) {
-        app.Connect.follow.start({ follow: false });
-        app.Connect.follow.on('data', leaderSync);
-        app.Connect.paint.on('data', leaderPaint);
-      }
-    });
+    //初始化同屏等
+    watch(
+      () => [isJoined, isNativeLeader],
+      async (val) => {
+        console.log('初始化同屏', unref(val[0]), unref(val[1]));
+        if (unref(val[0])) {
+          const app = await useApp();
+          if (unref(isNativeLeader)) {
+            app.Connect.follow.start({ follow: false });
+          } else {
+            console.log('customer-follow');
+            app.Connect.follow.start({ follow: true });
+          }
+          app.Connect.follow.on('data', leaderSync);
+          app.Connect.paint.on('data', leaderPaint);
+        }
+      },
+      {
+        deep: true,
+      },
+    );
   });
   onUnmounted(async () => {
     const { handleLeave } = useRtcSdk();

+ 1 - 0
src/store/modules/rtc.ts

@@ -225,6 +225,7 @@ export const useRtcStore = defineStore({
 
     setIsJoined(payload: boolean) {
       this.isJoined = payload;
+      console.log('setIsJoined', payload);
     },
     setIsPublished(payload: boolean) {
       this.isPublished = payload;

+ 2 - 2
src/store/modules/scene.ts

@@ -1,7 +1,7 @@
 import { defineStore } from 'pinia';
 import { KankanMetaDataType } from '/#/sdk';
-import { useApp, getApp } from '/@/hooks/userApp';
-
+import { getApp } from '/@/hooks/userApp';
+// useApp,
 export interface FloorsType {
   id: string;
   subgroup?: string;