diff --git a/sdk/demo/demo.html b/sdk/demo/demo.html index af06a31e7027204d6ddfe208dd060d66631bf8d3..8aaaf45a08880b300866bad0fef86ad90a30e3f0 100644 --- a/sdk/demo/demo.html +++ b/sdk/demo/demo.html @@ -515,6 +515,14 @@ Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. } } + function uuid_32() { + let uuid = ''; + for(i = 0; i < 26; i++) { + uuid += Math.floor(Math.random()*10) + } + return uuid + '32uuid' + } + function connectCloudPhone() { var cloudPhoneHost = JSON.parse(sessionStorage.getItem('cloudPhoneHost')); var phoneInfo = JSON.parse(sessionStorage.getItem('phoneInfo')); @@ -528,7 +536,7 @@ Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. var cloudPhoneParams = { ip: cloudIp, port: cloudPort, - session_id: '32uuid'.padStart(32, '0'), + session_id: uuid_32(), background_timeout: '60', available_playtime: '6000', touch_timeout: 600, @@ -603,6 +611,10 @@ Copyright 2022 Huawei Cloud Computing Technology Co., Ltd. document.getElementById("loading").style.display = normalStates.includes(state) ? 'none' : 'block'; showAlertModal(data); startsuccessCallBack(data); + + if(state === STATE_CONFIG.RESUMED) { + cloudapp.requestIFrame(); + } }); cloudapp.on("netStateChange", function (event, data) { diff --git a/sdk/src/AppController.js b/sdk/src/AppController.js index e17a82c3d121d97393ee1233aac7f516d98a291f..9c130bdcf571d500175c4829740119f3ed97cc8a 100644 --- a/sdk/src/AppController.js +++ b/sdk/src/AppController.js @@ -89,7 +89,8 @@ const APP_STATE_ERROR_CODE_TIP = { 3584: '试玩时间已到', 2560: '与服务器连接出现异常', 3840: '由于您长时间未操作游戏,服务断开', - 4096: '切换后台超时' + 4096: '切换后台超时', + 8960: '云机在其他设备上被连接,本次连接退出' }; const DEFAULT_VALUME_VALUE = 50; const WEBSOCKET_READY_STATE = { @@ -353,7 +354,7 @@ class AppController { initPlyerAndStart() { this.initPlayer(); if (this.player) { - if (this.options.keycodeInput && !this.options.isMobile) { + if (this.options.keycodeInput || this.isMobile) { this.keyboardListener = new KeyboardListener(this.options.containerId, this.send); } else { this.keyboardInput = new KeyboardInput(this.options.containerId, this.send, this.options.isMobile); @@ -369,7 +370,7 @@ class AppController { containerId: this.options.containerId, }); this.touchHandler.start(); - if (this.options.keycodeInput && !this.options.isMobile) { + if (this.options.keycodeInput || this.isMobile) { this.keyboardListener.start(this.touchHandler); } else { this.keyboardInput.getTouchHandler(this.touchHandler); @@ -700,6 +701,10 @@ class AppController { Logger.debug('Receive failed response, disconnect'); this.disconnect(); break; + case codeConfig.PHONE_CONNECTED: + Logger.debug('Phone has connected, disconnect'); + this.disconnect(); + break; case codeConfig.PLAY_TIMEOUT: Logger.debug('Play timeout, disconnect'); this.disconnect(); @@ -1495,6 +1500,7 @@ class AppController { this.autoRotation && this.autoRotation.destroy(); this.keyboardInput && this.keyboardInput.destroy(); this.fullscreen && this.fullscreen.destroy(); + this.keyboardListener && this.keyboardListener.destroy(); // 停止传感器 this.deviceHardwareHandler && this.deviceHardwareHandler.handleSensorDisable(this.sensorMsgType.TYPE_ACCELEROMETER); this.deviceHardwareHandler && this.deviceHardwareHandler.handleSensorDisable(this.sensorMsgType.TYPE_GYROSCOPE); diff --git a/sdk/src/AutoRotation.js b/sdk/src/AutoRotation.js index 27b54306d4445d60ca5b80dd4cb279b4cbfe61d2..ec565bd7ad4866c6ffa5f10d4e5b7a4fe66e7665 100644 --- a/sdk/src/AutoRotation.js +++ b/sdk/src/AutoRotation.js @@ -296,6 +296,6 @@ export default class AutoRotation { } getDeviceOrientation() { - return window.screen.orientation.angle; + return window?.screen?.orientation?.angle || window.orientation; } } diff --git a/sdk/src/CPHCloudApp.js b/sdk/src/CPHCloudApp.js index 707c6fbca3a9007774be02288db0dc9ac332ce53..cfdefcc64cbc9209f816bd4c3641d2a937daac94 100644 --- a/sdk/src/CPHCloudApp.js +++ b/sdk/src/CPHCloudApp.js @@ -334,6 +334,10 @@ class CPHCloudApp { this.appController.resumeCloudPhone(); } + requestIFrame() { + this.appController.requestIFrame(); + } + reconnect() { this.appController.reconnect(); } diff --git a/sdk/src/CloudApp.js b/sdk/src/CloudApp.js index e118612215c931d43de69d516cc1aaf0079df552..3a7c14af41da59e0a8da519d39a83b3e3a7d4cf1 100644 --- a/sdk/src/CloudApp.js +++ b/sdk/src/CloudApp.js @@ -44,6 +44,10 @@ class CloudApp { this.channel.pause(); } + requestIFrame() { + this.channel.requestIFrame(); + } + resume() { this.channel.resume(); } diff --git a/sdk/src/DirectionHandler.js b/sdk/src/DirectionHandler.js index f17f0f27dcf5c011b237a66745d2399fa71a8054..324c5e9db6920eb3a345a119074df9cd98d557cc 100644 --- a/sdk/src/DirectionHandler.js +++ b/sdk/src/DirectionHandler.js @@ -569,7 +569,7 @@ class DirectionHandler { // 旋转前需要先取消旋转,避免叠加旋转 this.cancelTransform(); if (this.options.isMobile) { - const deviceOrientation = window.screen.orientation.angle; + const deviceOrientation = window.screen.orientation.angle || window.orientation; if ([DEVICE_ORIENTATION_ANGLES.PORTRAIT,DEVICE_ORIENTATION_ANGLES.REVERSE_PORTRAIT].includes(deviceOrientation)) { this.portraitMobile(); } else if ([DEVICE_ORIENTATION_ANGLES.LANDSCAPE, DEVICE_ORIENTATION_ANGLES.REVERSE_LANDSCAPE].includes(deviceOrientation)) { @@ -692,7 +692,7 @@ class DirectionHandler { setTimeout(() => { let width = document.documentElement.clientWidth; let height = document.documentElement.clientHeight; - const deviceOrientation = window.screen.orientation.angle; + const deviceOrientation = window.screen.orientation.angle || window.orientation; if ([DEVICE_ORIENTATION_ANGLES.PORTRAIT,DEVICE_ORIENTATION_ANGLES.REVERSE_PORTRAIT].includes(deviceOrientation)) { if ([PROTOCOL_CONFIG.ORIENTATION[0], PROTOCOL_CONFIG.ORIENTATION[16]].includes(this.orientation)) { playerWidth = width; diff --git a/sdk/src/KeyboardInput.js b/sdk/src/KeyboardInput.js index 426934dba664b8330481737d3ae7e3eed4005820..e1ef1d1c16987edec12f8ace1063832b91a13d31 100644 --- a/sdk/src/KeyboardInput.js +++ b/sdk/src/KeyboardInput.js @@ -60,10 +60,11 @@ export default class KeyboardInput { opacity: 0; box-sizing: border-box; `; - - videoContainer.addEventListener("mouseup", (event) => { - this.onMouseUp(event); - }, true); + if(!this.isMobile) { + videoContainer.addEventListener("mouseup", (event)=>{ + this.onMouseUp(event) + }, true) + } this.util.bind(this.input, 'compositionstart', this.compositionstart.bind(this)); this.util.bind(this.input, 'compositionend', this.compositionend.bind(this)); this.util.bind(this.input, 'input', this.onInput.bind(this)); @@ -104,10 +105,6 @@ export default class KeyboardInput { this.onInput(); } - onInput() { - this.handleInputMsg(this.input.value, 'KEYBOARD_INPUT', PROTOCOL_CONFIG.KEYBOARD_INPUT_MSG_TYPE.TEXT_UPDATE); - } - onInput() { if(!this.cnStart) { this.handleInputMsg(this.input.value, 'KEYBOARD_INPUT' , PROTOCOL_CONFIG.KEYBOARD_INPUT_MSG_TYPE.IME_PASTE_FROM_PC_SDK); @@ -146,6 +143,9 @@ export default class KeyboardInput { destroy() { this.util.unbind(this.input, 'input'); this.util.unbind(this.input, 'keyup'); + this.util.unbind(this.input, 'keydown'); + this.util.unbind(this.input, 'compositionstart'); + this.util.unbind(this.input, 'compositionend'); this.inputContainer.remove(); this.inputContainer = null; } diff --git a/sdk/src/KeyboardListener.js b/sdk/src/KeyboardListener.js index f0856509d59dcc05db4816aa0ac3b48ee89dc78f..43792b720337f86644cf4ff723a28f37e5b3c2e4 100644 --- a/sdk/src/KeyboardListener.js +++ b/sdk/src/KeyboardListener.js @@ -53,5 +53,10 @@ export default class KeyboardListener { cmdBuf.set(msgData, PACKAGE_HEADER_LENGTH + INPUT_HEADER_LENGTH); this.msgHandler(cmdBuf.buffer); - } + } + + destroy() { + this.util.unbind(this.input, 'keydown'); + this.util.unbind(this.input, 'keypress'); + } } \ No newline at end of file diff --git a/sdk/src/config/protocolConfig.js b/sdk/src/config/protocolConfig.js index 5a5d8e0486ec3286d4ec49ee13addb1ae888286d..da6c1e60c845d05f43cdac1ea4ed6ca0eb775f3b 100644 --- a/sdk/src/config/protocolConfig.js +++ b/sdk/src/config/protocolConfig.js @@ -101,6 +101,7 @@ const PROTOCOL_CONFIG = { H265_NOT_SUPPORT: 0x1102, VERIFY_SESSION_ID_INVALID: 0x0607, INVALID_OPERATION: 0xFFFF, + PHONE_CONNECTED: 0x2300, }, ACTIONS_TYPE: { DOWN: 0,