1/* 2 * Copyright (c) 2021-2022 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 16import { paramMock } from "../utils" 17 18export const EventPriority = { 19 IMMEDIATE: 0, 20 HIGH: 1, 21 LOW: 2, 22 IDLE: 3, 23} 24export const EventData = { 25 data: '[PC preview] unknow data', 26} 27export const InnerEvent = { 28 eventId: '[PC preview] unknow eventId', 29 priority: EventPriority, 30} 31 32export function mockEmitter() { 33 const emitter = { 34 on: function (...args) { 35 console.warn("emitter.on interface mocked in the Previewer. How this interface works on the" + 36 " Previewer may be different from that on a real device."); 37 const len = args.length; 38 if (typeof args[len - 1] === 'function') { 39 args[len - 1].call(this, EventData); 40 } 41 }, 42 once: function (...args) { 43 console.warn("emitter.once interface mocked in the Previewer. How this interface works on the" + 44 " Previewer may be different from that on a real device."); 45 const len = args.length; 46 if (typeof args[len - 1] === 'function') { 47 args[len - 1].call(this, EventData); 48 } 49 }, 50 off: function (...args) { 51 console.warn("emitter.off interface mocked in the Previewer. How this interface works on the" + 52 " Previewer may be different from that on a real device."); 53 }, 54 emit: function (...args) { 55 console.warn("emitter.emit interface mocked in the Previewer. How this interface works on the" + 56 " Previewer may be different from that on a real device."); 57 }, 58 EventData, 59 InnerEvent, 60 EventPriority 61 } 62 return emitter 63} 64