1/* 2 * Copyright (c) 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 function mockDistributedObject() { 19 const DistributedObject = { 20 setSessionId: function (...args) { 21 console.warn("DistributedObject.setSessionId interface mocked in the Previewer." + 22 " How this interface works on the Previewer may be different from that on a real device.") 23 }, 24 on: function (...args) { 25 console.warn("DistributedObject.on interface mocked in the Previewer. How this interface works" + 26 " on the Previewer may be different from that on a real device.") 27 }, 28 off: function (...args) { 29 console.warn("DistributedObject.off interface mocked in the Previewer. How this interface works" + 30 " on the Previewer may be different from that on a real device.") 31 }, 32 save: function (...args) { 33 console.warn("DistributedObject.save interface mocked in the Previewer. How this interface works" + 34 " on the Previewer may be different from that on a real device.") 35 const len = args.length 36 if (len > 0 && typeof args[len - 1] === 'function') { 37 args[len - 1].call(this, paramMock.businessErrorMock, SaveSuccessResponse); 38 } else { 39 return new Promise((resolve, reject) => { 40 resolve(SaveSuccessResponse); 41 }) 42 } 43 }, 44 revokeSave: function (...args) { 45 console.warn("DistributedObject.revokeSave interface mocked in the Previewer. How this interface works" + 46 " on the Previewer may be different from that on a real device.") 47 const len = args.length 48 if (len > 0 && typeof args[len - 1] === 'function') { 49 args[len - 1].call(this, paramMock.businessErrorMock, RevokeSaveSuccessResponse); 50 } else { 51 return new Promise((resolve, reject) => { 52 resolve(RevokeSaveSuccessResponse); 53 }) 54 } 55 } 56 }; 57 const SaveSuccessResponse = { 58 sessionId: "[[PC Preview] unknow sessionId]", 59 version: "[[PC Preview] unknow version]", 60 deviceId: "[[PC Preview] unknow deviceId]" 61 }; 62 const RevokeSaveSuccessResponse = { 63 sessionId: "[[PC Preview] unknow sessionId]" 64 }; 65 const distributedDataObject = { 66 createDistributedObject: function (...args) { 67 console.warn("distributedObject.createDistributedObject interface mocked in the Previewer." + 68 " How this interface works on the Previewer may be different from that on a real device."); 69 return DistributedObject; 70 }, 71 genSessionId: function (...args) { 72 console.warn("distributedObject.genSessionId interface mocked in the Previewer." + 73 " How this interface works on the Previewer may be different from that on a real device."); 74 return paramMock.paramStringMock; 75 } 76 }; 77 return distributedDataObject; 78} 79