1/* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16export function mockInputMonitor() { 17 const TouchEventReceiver = { 18 "touchEvent": '[PC preview] unknow boolean' 19 } 20 const touches = [{ 21 force: 1.67, 22 globalX: 122, 23 globalY: 3654, 24 localX: 0, 25 localY: 0, 26 size: 2.03 27 }]; 28 const changedTouches = [{ 29 force: 1.67, 30 globalX: 122, 31 globalY: 3654, 32 localX: 0, 33 localY: 0, 34 size: 2.03 35 }]; 36 const pressedButtons = [10, 11, 12, 13, 14]; 37 const inputMonitor = { 38 on: function (...args) { 39 console.warn('multimodalInput.inputMonitor.on interface mocked in the Previewer. How this interface works on the' + 40 ' Previewer may be different from that on a real device.'); 41 clearInterval(this.offInputMonitor); 42 delete this.offInputMonitor; 43 this.offInputMonitor = setInterval(() => { 44 const len = args.length; 45 if (len !== 2 || typeof args[0] !== 'string' || typeof args[len - 1] !== 'function') { 46 console.warn('multimodalInput.inputMonitor.on param invalid.'); 47 return; 48 } 49 if (args[0] !== 'touch' && args[0] !== 'mouse') { 50 console.warn('multimodalInput.inputMonitor.on first param should be touch or mouse.'); 51 return; 52 } 53 const value = {}; 54 value.type = 'up'; 55 value.timestamp = 318878; 56 value.deviceId = 0; 57 value.touches = touches; 58 value.changedTouches = changedTouches; 59 const mouse = {}; 60 mouse.type = 'move'; 61 mouse.pressedButtons = pressedButtons; 62 mouse.displayId = 20; 63 mouse.targetWindowId = 21; 64 mouse.agentWindowId = 22; 65 mouse.localX = 450; 66 mouse.localY = 736; 67 mouse.globalX = 450; 68 mouse.globalY = 784; 69 mouse.timestamp = 55670246; 70 mouse.axisVerticalValue = 15; 71 mouse.axisHorizontalValue = 20; 72 if (args[0] === 'touch') { 73 console.warn('multimodalInput.inputMonitor.on touch callback.'); 74 args[len - 1].call(this, value); 75 } else if (args[0] === 'mouse') { 76 console.warn('multimodalInput.inputMonitor.on mouse callback.'); 77 args[len - 1].call(this, mouse); 78 } 79 }, 1000); 80 }, 81 82 off: function (...args) { 83 console.warn('multimodalInput.inputMonitor.off interface mocked in the Previewer. How this interface works on the' + 84 ' Previewer may be different from that on a real device.'); 85 const len = args.length; 86 if (len < 1 || len > 2) { 87 console.warn("a maximum of two parameters"); 88 return; 89 } 90 if (typeof args[0] !== 'string') { 91 console.warn("the first parameter type must be string"); 92 return; 93 } 94 if (len === 1) { 95 if (args[0] !== 'touch' && args[0] !== 'mouse') { 96 console.warn("the first param should be touch or mouse"); 97 return; 98 } 99 } else { 100 if (typeof args[1] !== 'function') { 101 console.warn("the second parameter type must be function"); 102 return; 103 } 104 } 105 } 106 } 107 return inputMonitor 108} 109 110