gemercheung 1 year ago
parent
commit
ed94b309ce
10 changed files with 606 additions and 16 deletions
  1. 1 0
      .env.dev
  2. 1 0
      .env.production
  3. 1 0
      .env.test
  4. 2 1
      package.json
  5. 64 0
      pnpm-lock.yaml
  6. 58 14
      src/App.vue
  7. 440 0
      src/browser.ts
  8. 1 1
      src/components/sceneList.vue
  9. 20 0
      src/http.ts
  10. 18 0
      vite.config.ts

+ 1 - 0
.env.dev

@@ -1,2 +1,3 @@
+VITE_APP_APIS_URL=https://v4-test.4dkankan.com/
 VITE_APP_IFRAME_URL=https://127.0.0.1:6100
 VITE_PUBLIC_DIR="/"

+ 1 - 0
.env.production

@@ -1,2 +1,3 @@
+VITE_APP_APIS_URL=https://v4-test.4dkankan.com/
 VITE_APP_IFRAME_URL=https://www.4dkankan.com
 VITE_PUBLIC_DIR="/livestream/fd/"

+ 1 - 0
.env.test

@@ -1,2 +1,3 @@
+VITE_APP_APIS_URL=https://v4-test.4dkankan.com/
 VITE_APP_IFRAME_URL=https://test.4dkankan.com/livestream/
 VITE_PUBLIC_DIR="/livestream/fd/"

+ 2 - 1
package.json

@@ -4,7 +4,7 @@
   "version": "0.0.0",
   "type": "module",
   "scripts": {
-    "dev": "vite --mode dev --port=6101",
+    "dev": "vite --mode dev ",
     "build-test": "vue-tsc  --noEmit && vite build --mode test",
     "build-production": "vue-tsc && vite build --mode production",
     "preview": "vite preview"
@@ -12,6 +12,7 @@
   "dependencies": {
     "@vicons/ionicons5": "^0.12.0",
     "@vueuse/core": "^10.3.0",
+    "axios": "^1.5.0",
     "naive-ui": "^2.34.4",
     "sass": "^1.65.1",
     "vfonts": "^0.1.0",

+ 64 - 0
pnpm-lock.yaml

@@ -11,6 +11,9 @@ dependencies:
   '@vueuse/core':
     specifier: ^10.3.0
     version: 10.3.0(vue@3.3.4)
+  axios:
+    specifier: ^1.5.0
+    version: 1.5.0
   naive-ui:
     specifier: ^2.34.4
     version: 2.34.4(vue@3.3.4)
@@ -490,6 +493,20 @@ packages:
     resolution: {integrity: sha512-7HhHjtERjqlNbZtqNqy2rckN/SpOOlmDliet+lP7k+eKZEjPk3DgyeU9lIXLdeLz0uBbbVp+9Qdow9wJWgwwfg==}
     dev: false
 
+  /asynckit@0.4.0:
+    resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==}
+    dev: false
+
+  /axios@1.5.0:
+    resolution: {integrity: sha512-D4DdjDo5CY50Qms0qGQTTw6Q44jl7zRwY7bthds06pUGfChBCTcQs+N743eFWGEd6pRTMd6A+I87aWyFV5wiZQ==}
+    dependencies:
+      follow-redirects: 1.15.2
+      form-data: 4.0.0
+      proxy-from-env: 1.1.0
+    transitivePeerDependencies:
+      - debug
+    dev: false
+
   /balanced-match@1.0.2:
     resolution: {integrity: sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==}
     dev: true
@@ -524,6 +541,13 @@ packages:
     optionalDependencies:
       fsevents: 2.3.2
 
+  /combined-stream@1.0.8:
+    resolution: {integrity: sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==}
+    engines: {node: '>= 0.8'}
+    dependencies:
+      delayed-stream: 1.0.0
+    dev: false
+
   /css-render@0.15.12:
     resolution: {integrity: sha512-eWzS66patiGkTTik+ipO9qNGZ+uNuGyTmnz6/+EJIiFg8+3yZRpnMwgFo8YdXhQRsiePzehnusrxVvugNjXzbw==}
     dependencies:
@@ -557,6 +581,11 @@ packages:
     resolution: {integrity: sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0=}
     dev: true
 
+  /delayed-stream@1.0.0:
+    resolution: {integrity: sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==}
+    engines: {node: '>=0.4.0'}
+    dev: false
+
   /esbuild@0.18.20:
     resolution: {integrity: sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==}
     engines: {node: '>=12'}
@@ -600,6 +629,25 @@ packages:
     dependencies:
       to-regex-range: 5.0.1
 
+  /follow-redirects@1.15.2:
+    resolution: {integrity: sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==}
+    engines: {node: '>=4.0'}
+    peerDependencies:
+      debug: '*'
+    peerDependenciesMeta:
+      debug:
+        optional: true
+    dev: false
+
+  /form-data@4.0.0:
+    resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==}
+    engines: {node: '>= 6'}
+    dependencies:
+      asynckit: 0.4.0
+      combined-stream: 1.0.8
+      mime-types: 2.1.35
+    dev: false
+
   /fsevents@2.3.2:
     resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==}
     engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
@@ -667,6 +715,18 @@ packages:
     dependencies:
       '@jridgewell/sourcemap-codec': 1.4.15
 
+  /mime-db@1.52.0:
+    resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==}
+    engines: {node: '>= 0.6'}
+    dev: false
+
+  /mime-types@2.1.35:
+    resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==}
+    engines: {node: '>= 0.6'}
+    dependencies:
+      mime-db: 1.52.0
+    dev: false
+
   /minimatch@9.0.3:
     resolution: {integrity: sha512-RHiac9mvaRw0x3AYRgDC1CxAP7HTcNrrECeA8YYJeWnpo+2Q5CegtZjaotWTWxDG3UeGA1coE05iH1mPjT/2mg==}
     engines: {node: '>=16 || 14 >=14.17'}
@@ -728,6 +788,10 @@ packages:
       picocolors: 1.0.0
       source-map-js: 1.0.2
 
+  /proxy-from-env@1.1.0:
+    resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==}
+    dev: false
+
   /readdirp@3.6.0:
     resolution: {integrity: sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==}
     engines: {node: '>=8.10.0'}

+ 58 - 14
src/App.vue

@@ -3,7 +3,7 @@
   <n-config-provider :theme="themes['dark']">
     <n-message-provider>
       <n-layout has-sider class="layout">
-        <n-layout-sider
+        <!-- <n-layout-sider
           collapse-mode="width"
           :collapsed-width="10"
           :width="200"
@@ -12,7 +12,7 @@
           bordered
         >
           <sceneList></sceneList>
-        </n-layout-sider>
+        </n-layout-sider> -->
         <n-layout-content content-style="padding: 0px;">
           <iframe
             v-if="isOK"
@@ -26,7 +26,7 @@
             class="page-result"
             status="403"
             title="403 禁止访问"
-            description="服务器配置出错,请联系管理人员"
+            description="当前场景非公开"
           >
           </n-result>
         </n-layout-content>
@@ -41,7 +41,7 @@ import {
   NConfigProvider,
   NMessageProvider,
   NLayout,
-  NLayoutSider,
+  // NLayoutSider,
   NLayoutContent,
   GlobalTheme,
   darkTheme,
@@ -51,32 +51,40 @@ import {
 } from "naive-ui";
 import { onMounted, ref, computed } from "vue";
 import { useUrlSearchParams } from "@vueuse/core";
-import sceneList from "./components/sceneList.vue";
+import { getRoomInfo, dimissMissRoom } from "./http.ts";
+// import sceneList from "./components/sceneList.vue";
 const isOK = ref(true);
 // const iframe = ref(
 //   "https://127.0.0.1:6100/livestream/?vruserId=066893f525e56f09ce8b4420dff7e068&roomId=fd_22253&role=leader&avatar=https%3A%2F%2F4dkk.4dage.com%2Ftake-look%2Fimages%2Fother%2F1573b607db124917804edfaf1887df7a.jpeg&name=Gemer1&isTour=0&m=KJ-t-wOXfx2SDFy&vlog=1"
 // );
 interface needParams {
   avatar: string;
+  name?: string;
   isTour?: number;
   m: string;
   role: string;
   roomId: string;
   vlog?: string;
   vruserId: string;
+  fromMiniApp?: number;
+  redirect?: string;
 }
 const params: needParams = useUrlSearchParams("history");
+const searchParams = new URLSearchParams(
+  Object.assign({ platform: "fd" }, params ? params : {})
+);
+const iframeDomain = import.meta.env.VITE_APP_IFRAME_URL;
+
+let url = searchParams.toString();
 
 const iframeURL = computed(() => {
-  const searchParams = new URLSearchParams(
-    Object.assign({ platform: "fire" }, params ? params : {})
-  );
-  const iframeDomain = import.meta.env.VITE_APP_IFRAME_URL;
-  const url = searchParams.toString();
+  searchParams.set("fromMiniApp", "0");
+  searchParams.set("isTour", "0");
+  // searchParams.delete("redirect");
   return iframeDomain + "?" + url;
 });
 
-if (!params.m || !params.role || !params.vruserId) {
+if (!params.m || !params.role || !params.roomId) {
   isOK.value = false;
 }
 
@@ -89,25 +97,61 @@ const loadFrame = (event: Event) => {
   // console.log("target", event.target);
   const ele = event.target as any as HTMLIFrameElement;
   if (ele.contentWindow) {
-
   }
 };
-const getIframeMessage = (event: MessageEvent) => {
+const getIframeMessage = async (event: MessageEvent) => {
   if ("type" in event.data) {
     const { type, data } = event.data;
     if (type === "metadata") {
       document.title = data.title;
       console.warn("getIframeMessage", data);
     }
+    if (type === "exit") {
+      console.log("火调退出");
+      if (params.role === "leader") {
+        const redirect = decodeURIComponent(
+          decodeURIComponent(params.redirect || "")
+        );
+        //解散房间 ----
+        const res = await dimissMissRoom(params.roomId);
+        if (res && res.data && res.data.code === 0) {
+          setTimeout(() => {
+            window.location.href = redirect;
+          }, 500);
+        } else {
+          isOK.value = false;
+        }
+      } else {
+        isOK.value = false;
+        window.location.search = "";
+      }
+    }
+    if (type === "fillName") {
+      searchParams.set("name", data);
+      url = searchParams.toString();
+      const reloadURL = location.origin + location.pathname + "?" + url;
+      history.replaceState(null, "", reloadURL);
+    }
   }
 };
 
-onMounted(() => {
+onMounted(async () => {
   const frameEle = document.getElementById("mainFrame");
   if (frameEle) {
     frameEle.addEventListener("load", loadFrame, true);
   }
   window.addEventListener("message", getIframeMessage, false);
+  const res = await getRoomInfo(params.roomId);
+  if (res && res.data.code === 0) {
+    console.log("res", res.data.data);
+    const { roomStatus } = res.data.data;
+    console.log("当前房间状态::", roomStatus);
+    if (roomStatus === 2 && params.role !== "leader") {
+      isOK.value = false;
+    }
+  } else {
+    isOK.value = false;
+  }
 });
 </script>
 

File diff suppressed because it is too large
+ 440 - 0
src/browser.ts


+ 1 - 1
src/components/sceneList.vue

@@ -34,7 +34,7 @@
 import { NList, NListItem, NThing } from "naive-ui";
 const handleClickScene = () => {
   const iframe = document.querySelector("iframe");
-  console.log("iframe", iframe);
+  // console.log("iframe", iframe);
   if (iframe) {
     iframe.contentWindow?.postMessage(
       {

+ 20 - 0
src/http.ts

@@ -0,0 +1,20 @@
+import axios, { AxiosResponse } from 'axios';
+import browser from './browser';
+
+const shopAxios = axios.create({
+    baseURL: import.meta.env.VITE_APP_APIS_URL,
+});
+
+
+export const getRoomInfo = async (roomId: string): Promise<AxiosResponse> => {
+    shopAxios.defaults.headers.platform = browser.getURLParam('platform') || '';
+    const res = await shopAxios.get<AxiosResponse>('/takelook/roomInfo', { params: { roomId } });
+    // console.log('res', res)
+    return res
+};
+export const dimissMissRoom = async (roomId: string): Promise<AxiosResponse> => {
+    shopAxios.defaults.headers.platform = browser.getURLParam('platform') || '';
+    const res = await shopAxios.get<AxiosResponse>('/takelook/dissolveTheRoom', { params: { roomId } });
+    // console.log('res', res)
+    return res
+};

+ 18 - 0
vite.config.ts

@@ -10,4 +10,22 @@ export default ({ mode }) =>
   defineConfig({
     base: loadEnv(mode, process.cwd()).VITE_PUBLIC_DIR,
     plugins: [vue()],
+    server: {
+      https: Number(loadEnv(mode, process.cwd()).VITE_USE_HTTPS) == 1,
+      host: true,
+      port: 6800,
+      headers: {
+        'Cache-Control': 'no-store',
+      },
+      proxy: {
+        '/service': {
+          target: loadEnv(mode, process.cwd()).VITE_APP_APIS_URL,
+          changeOrigin: true,
+        },
+        '/takelook': {
+          target: loadEnv(mode, process.cwd()).VITE_APP_APIS_URL,
+          changeOrigin: true,
+        },
+      },
+    },
   })