Sfoglia il codice sorgente

优化webRTC视图进行9:16画面适配

tangdehang 2 mesi fa
parent
commit
723406ea64

+ 3 - 3
static/rtcEngine/WXtrialInterface.html

@@ -7,10 +7,10 @@
     <title>双子星云手机</title>
     <link rel="stylesheet" href="./config/css/vant.css">
     <link rel="stylesheet" href="./css/WXtrialInterface.css">
-    <!-- <script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/vConsole/3.12.1/vconsole.min.js"></script> -->
-    <!-- <script>
+    <script src="https://lf9-cdn-tos.bytecdntp.com/cdn/expire-1-M/vConsole/3.12.1/vconsole.min.js"></script>
+    <script>
         const vConsole = new VConsole();
-    </script> -->
+    </script>
 </head>
 
 <body @touchmove.prevent>

+ 10 - 6
static/rtcEngine/css/WXtrialInterface.css

@@ -115,14 +115,16 @@ html {
   font-size: 0.12rem;
 }
 .layout .layout-view {
-  height: calc(100% - 0.6rem);
+  height: calc(100% - 0.4rem);
   width: 100%;
   position: relative;
+  display: flex;
+  align-content: center;
+  justify-content: center;
+  align-items: center;
+  flex-wrap: nowrap;
 }
 .layout .layout-view .videoRotate {
-  position: absolute;
-  left: 0;
-  top: 0;
   display: block;
   object-fit: fill;
 }
@@ -130,7 +132,7 @@ html {
   display: grid;
   grid-template-columns: repeat(3, 1fr);
   text-align: center;
-  height: 0.6rem;
+  height: 0.4rem;
 }
 .layout .layout-footer img {
   margin: auto;
@@ -483,4 +485,6 @@ html {
 .levitated-sphere img {
   width: 0.42rem;
   height: 0.42rem;
-}
+}
+
+/*# sourceMappingURL=WXtrialInterface.css.map */

+ 36 - 7
static/rtcEngine/js/WXtrialInterface.js

@@ -142,15 +142,18 @@ const app = new Vue({
 
         rtcMediaPlayerStyle() {
             let obj = {
-                objectFit: "fill"
+                objectFit: "fill",
+                width: `${this.layoutViewWidth}px`,
+                height: `${this.layoutViewHeight}px`,
             }
             if (this.isLandscape) {
                 obj = {
                     width: `${this.layoutViewHeight}px`,
                     height: `${this.layoutViewWidth}px`,
-                    left: '50%',
-                    top: '50%',
-                    transform: 'translate(-50%, -50%) rotate(90deg)'
+                    // left: '50%',
+                    // top: '50%',
+                    // transform: 'translate(-50%, -50%) rotate(90deg)'
+                    transform: 'rotate(90deg)'
                 }
             }
 
@@ -237,7 +240,7 @@ const app = new Vue({
             switch (event.type) {
                 case "screenChange":
                     // 0:横屏 1:竖屏
-                    // console.log("屏幕方向变化事件:" + event.val);
+                    console.log("屏幕方向变化事件:" + event.val);
                     this.isLandscape = event.val === 0;
                     break;
                 case "wsState":
@@ -975,10 +978,36 @@ method: post
             this.height = window.innerHeight
             this.width = window.innerWidth
             this.$nextTick(() => {
+
                 // 云机画面宽高
                 let layoutView = document.querySelector('.layout-view')
-                this.layoutViewWidth = layoutView.offsetWidth
-                this.layoutViewHeight = layoutView.offsetHeight
+                // 获取视口宽度,webRTC需要做成16:9的画面
+                let currentWidth = layoutView.clientWidth;
+                let currentHeight = layoutView.clientHeight;
+
+                // this.layoutViewWidth = layoutView.offsetWidth;
+                // this.layoutViewHeight = layoutView.offsetHeight;
+                
+                // 计算当前视口的宽高比
+                const currentRatio = currentWidth / currentHeight;
+            
+                // 9:16 的目标比例
+                const targetRatio = 9 / 16;
+                console.log(`当前视口的宽高比: ${currentRatio}`);
+                // 判断当前视口的宽高比与目标比例的关系
+                if (currentRatio > targetRatio) {
+                    // 当前视口的宽高比大于目标比例,说明宽度“过宽”,需要以高度为基准
+                    console.log("当前视口宽度过宽,应以高度为基准调整宽度");
+                    this.layoutViewWidth = currentHeight * targetRatio;
+                    this.layoutViewHeight = currentHeight;
+                    console.log(`1目标: 宽${this.layoutViewWidth},高${this.layoutViewHeight}`);
+                } else {
+                    // 当前视口的宽高比小于目标比例,说明高度“过高”,需要以宽度为基准
+                    console.log("当前视口高度过高,应以宽度为基准调整高度");
+                    this.layoutViewHeight = currentWidth / targetRatio;
+                    this.layoutViewWidth = currentWidth;
+                    console.log(`2目标: 宽${this.layoutViewWidth},高${this.layoutViewHeight}`);
+                }
             })
         },
 

+ 10 - 5
static/rtcEngine/scss/WXtrialInterface.scss

@@ -119,14 +119,19 @@ html {
     font-size: toREM(12);
 
     .layout-view {
-        height: calc(100% - toREM(60));
+        height: calc(100% - toREM(40));
         width: 100%;
         position: relative;
+        display: flex;
+        align-content: center;
+        justify-content: center;
+        align-items: center;
+        flex-wrap: nowrap;
 
         .videoRotate {
-            position: absolute;
-            left: 0;
-            top: 0;
+            // position: absolute;
+            // left: 0;
+            // top: 0;
             display: block;
             object-fit: fill;
         }
@@ -136,7 +141,7 @@ html {
         display: grid;
         grid-template-columns: repeat(3, 1fr);
         text-align: center;
-        height: toREM(60);
+        height: toREM(40);
 
         img {
             margin: auto;