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 mockMultimediaCamera() { 19 const Camera = { 20 cameraId: '[PC preview] unknow pid', 21 cameraPosition: '[PC preview] unknow cameraPosition', 22 cameraType: '[PC preview] unknow cameraType', 23 connectionType: '[PC preview] unknow connectionType' 24 } 25 const FlashMode = '[PC preview] unknow flashMode' 26 const FocusMode = '[PC preview] unknow focusMode' 27 const multimediaCameraMock = { 28 getCameraManager: function (...args) { 29 console.warn('camera.getCameraManager interface mocked in the Previewer. How this interface works on the' + 30 ' Previewer may be different from that on a real device.'); 31 const len = args.length; 32 if (typeof args[len - 1] === 'function') { 33 args[len - 1].call(this, paramMock.businessErrorMock, CameraManager); 34 } else { 35 return new Promise((resolve) => { 36 resolve(CameraManager); 37 }); 38 } 39 }, 40 createCaptureSession: function (...args) { 41 console.warn('camera.createCaptureSession interface mocked in the Previewer. How this interface works on the' + 42 ' Previewer may be different from that on a real device.'); 43 const len = args.length; 44 if (typeof args[len - 1] === 'function') { 45 args[len - 1].call(this, paramMock.businessErrorMock, CaptureSession); 46 } else { 47 return new Promise((resolve) => { 48 resolve(CaptureSession); 49 }); 50 } 51 }, 52 createPreviewOutput: function (...args) { 53 console.warn('camera.createPreviewOutput interface mocked in the Previewer. How this interface works on the' + 54 ' Previewer may be different from that on a real device.'); 55 const len = args.length; 56 if (typeof args[len - 1] === 'function') { 57 args[len - 1].call(this, paramMock.businessErrorMock, PreviewOutput); 58 } else { 59 return new Promise((resolve) => { 60 resolve(PreviewOutput); 61 }); 62 } 63 }, 64 createPhotoOutput: function (...args) { 65 console.warn('camera.createPreviewOutput interface mocked in the Previewer. How this interface works on the' + 66 ' Previewer may be different from that on a real device.'); 67 const len = args.length; 68 if (typeof args[len - 1] === 'function') { 69 args[len - 1].call(this, paramMock.businessErrorMock, PhotoOutput); 70 } else { 71 return new Promise((resolve) => { 72 resolve(PhotoOutput); 73 }); 74 } 75 }, 76 createVideoOutput: function (...args) { 77 console.warn('camera.createVideoOutput interface mocked in the Previewer. How this interface works on the' + 78 ' Previewer may be different from that on a real device.'); 79 const len = args.length; 80 if (typeof args[len - 1] === 'function') { 81 args[len - 1].call(this, paramMock.businessErrorMock, VideoOutput); 82 } else { 83 return new Promise((resolve) => { 84 resolve(VideoOutput); 85 }); 86 } 87 }, 88 } 89 const CameraManager = { 90 getCameras: function (...args) { 91 console.warn('CameraManager.getCameras interface mocked in the Previewer. How this interface works on the' + 92 ' Previewer may be different from that on a real device.'); 93 const len = args.length; 94 if (typeof args[len - 1] === 'function') { 95 args[len - 1].call(this, paramMock.businessErrorMock, [Camera]); 96 } else { 97 return new Promise((resolve) => { 98 resolve([Camera]); 99 }); 100 } 101 }, 102 createCameraInput: function (...args) { 103 console.warn('CameraManager.createCameraInput interface mocked in the Previewer. How this interface works on the' + 104 ' Previewer may be different from that on a real device.'); 105 const len = args.length; 106 if (typeof args[len - 1] === 'function') { 107 args[len - 1].call(this, paramMock.businessErrorMock, CameraInput); 108 } else { 109 return new Promise((resolve) => { 110 resolve(CameraInput); 111 }); 112 } 113 }, 114 on: function (...args) { 115 console.warn('CameraManager.on interface mocked in the Previewer. How this interface works on the' + 116 ' Previewer may be different from that on a real device.'); 117 } 118 } 119 const CameraInput = { 120 getCameraId: function (...args) { 121 console.warn('CameraInput.getCameraId interface mocked in the Previewer. How this interface works on the' + 122 ' Previewer may be different from that on a real device.'); 123 const len = args.length; 124 if (typeof args[len - 1] === 'function') { 125 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 126 } else { 127 return new Promise((resolve) => { 128 resolve(paramMock.paramStringMock); 129 }); 130 } 131 }, 132 hasFlash: function (...args) { 133 console.warn('CameraInput.hasFlash interface mocked in the Previewer. How this interface works on the' + 134 ' Previewer may be different from that on a real device.'); 135 const len = args.length; 136 if (typeof args[len - 1] === 'function') { 137 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 138 } else { 139 return new Promise((resolve) => { 140 resolve(paramMock.paramBooleanMock); 141 }); 142 } 143 }, 144 isFlashModeSupported: function (...args) { 145 console.warn('CameraInput.isFlashModeSupported interface mocked in the Previewer. How this interface works on the' + 146 ' Previewer may be different from that on a real device.'); 147 const len = args.length; 148 if (typeof args[len - 1] === 'function') { 149 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 150 } else { 151 return new Promise((resolve) => { 152 resolve(paramMock.paramBooleanMock); 153 }); 154 } 155 }, 156 getFlashMode: function (...args) { 157 console.warn('CameraInput.getFlashMode interface mocked in the Previewer. How this interface works on the' + 158 ' Previewer may be different from that on a real device.'); 159 const len = args.length; 160 if (typeof args[len - 1] === 'function') { 161 args[len - 1].call(this, paramMock.businessErrorMock, FlashMode); 162 } else { 163 return new Promise((resolve) => { 164 resolve(FlashMode); 165 }); 166 } 167 }, 168 setFlashMode: function (...args) { 169 console.warn('CameraInput.setFlashMode interface mocked in the Previewer. How this interface works on the' + 170 ' Previewer may be different from that on a real device.'); 171 const len = args.length; 172 if (typeof args[len - 1] === 'function') { 173 args[len - 1].call(this, paramMock.businessErrorMock); 174 } else { 175 return new Promise((resolve) => { 176 resolve(); 177 }); 178 } 179 }, 180 isFocusModeSupported: function (...args) { 181 console.warn('CameraInput.isFocusModeSupported interface mocked in the Previewer. How this interface works on the' + 182 ' Previewer may be different from that on a real device.'); 183 const len = args.length; 184 if (typeof args[len - 1] === 'function') { 185 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 186 } else { 187 return new Promise((resolve) => { 188 resolve(paramMock.paramBooleanMock); 189 }); 190 } 191 }, 192 getFocusMode: function (...args) { 193 console.warn('CameraInput.getFocusMode interface mocked in the Previewer. How this interface works on the' + 194 ' Previewer may be different from that on a real device.'); 195 const len = args.length; 196 if (typeof args[len - 1] === 'function') { 197 args[len - 1].call(this, paramMock.businessErrorMock, FocusMode); 198 } else { 199 return new Promise((resolve) => { 200 resolve(FocusMode); 201 }); 202 } 203 }, 204 setFocusMode: function (...args) { 205 console.warn('CameraInput.setFocusMode interface mocked in the Previewer. How this interface works on the' + 206 ' Previewer may be different from that on a real device.'); 207 const len = args.length; 208 if (typeof args[len - 1] === 'function') { 209 args[len - 1].call(this, paramMock.businessErrorMock); 210 } else { 211 return new Promise((resolve) => { 212 resolve(); 213 }); 214 } 215 }, 216 getZoomRatioRange: function (...args) { 217 console.warn('CameraInput.getZoomRatioRange interface mocked in the Previewer. How this interface works on the' + 218 ' Previewer may be different from that on a real device.'); 219 const len = args.length; 220 if (typeof args[len - 1] === 'function') { 221 args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramNumberMock]); 222 } else { 223 return new Promise((resolve) => { 224 resolve([paramMock.paramNumberMock]); 225 }); 226 } 227 }, 228 getZoomRatio: function (...args) { 229 console.warn('CameraInput.getZoomRatioRange interface mocked in the Previewer. How this interface works on the' + 230 ' Previewer may be different from that on a real device.'); 231 const len = args.length; 232 if (typeof args[len - 1] === 'function') { 233 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 234 } else { 235 return new Promise((resolve) => { 236 resolve(paramMock.paramNumberMock); 237 }); 238 } 239 }, 240 setZoomRatio: function (...args) { 241 console.warn('CameraInput.setZoomRatio interface mocked in the Previewer. How this interface works on the' + 242 ' Previewer may be different from that on a real device.'); 243 const len = args.length; 244 if (typeof args[len - 1] === 'function') { 245 args[len - 1].call(this, paramMock.businessErrorMock); 246 } else { 247 return new Promise((resolve) => { 248 resolve(); 249 }); 250 } 251 }, 252 release: function (...args) { 253 console.warn('CameraInput.release interface mocked in the Previewer. How this interface works on the' + 254 ' Previewer may be different from that on a real device.'); 255 const len = args.length; 256 if (typeof args[len - 1] === 'function') { 257 args[len - 1].call(this, paramMock.businessErrorMock); 258 } else { 259 return new Promise((resolve) => { 260 resolve(); 261 }); 262 } 263 }, 264 on: function (...args) { 265 console.warn('CameraInput.on interface mocked in the Previewer. How this interface works on the' + 266 ' Previewer may be different from that on a real device.'); 267 } 268 } 269 const CaptureSession = { 270 beginConfig: function (...args) { 271 console.warn('CaptureSession.beginConfig interface mocked in the Previewer. How this interface works on the' + 272 ' Previewer may be different from that on a real device.'); 273 const len = args.length; 274 if (typeof args[len - 1] === 'function') { 275 args[len - 1].call(this, paramMock.businessErrorMock); 276 } else { 277 return new Promise((resolve) => { 278 resolve(); 279 }); 280 } 281 }, 282 commitConfig: function (...args) { 283 console.warn('CaptureSession.commitConfig interface mocked in the Previewer. How this interface works on the' + 284 ' Previewer may be different from that on a real device.'); 285 const len = args.length; 286 if (typeof args[len - 1] === 'function') { 287 args[len - 1].call(this, paramMock.businessErrorMock); 288 } else { 289 return new Promise((resolve) => { 290 resolve(); 291 }); 292 } 293 }, 294 addInput: function (...args) { 295 console.warn('CaptureSession.addInput interface mocked in the Previewer. How this interface works on the' + 296 ' Previewer may be different from that on a real device.'); 297 const len = args.length; 298 if (typeof args[len - 1] === 'function') { 299 args[len - 1].call(this, paramMock.businessErrorMock); 300 } else { 301 return new Promise((resolve) => { 302 resolve(); 303 }); 304 } 305 }, 306 addOutput: function (...args) { 307 console.warn('CaptureSession.addOutput interface mocked in the Previewer. How this interface works on the' + 308 ' Previewer may be different from that on a real device.'); 309 const len = args.length; 310 if (typeof args[len - 1] === 'function') { 311 args[len - 1].call(this, paramMock.businessErrorMock); 312 } else { 313 return new Promise((resolve) => { 314 resolve(); 315 }); 316 } 317 }, 318 removeInput: function (...args) { 319 console.warn('CaptureSession.removeInput interface mocked in the Previewer. How this interface works on the' + 320 ' Previewer may be different from that on a real device.'); 321 const len = args.length; 322 if (typeof args[len - 1] === 'function') { 323 args[len - 1].call(this, paramMock.businessErrorMock); 324 } else { 325 return new Promise((resolve) => { 326 resolve(); 327 }); 328 } 329 }, 330 removeOutput: function (...args) { 331 console.warn('CaptureSession.removeInput interface mocked in the Previewer. How this interface works on the' + 332 ' Previewer may be different from that on a real device.'); 333 const len = args.length; 334 if (typeof args[len - 1] === 'function') { 335 args[len - 1].call(this, paramMock.businessErrorMock); 336 } else { 337 return new Promise((resolve) => { 338 resolve(); 339 }); 340 } 341 }, 342 start: function (...args) { 343 console.warn('CaptureSession.start interface mocked in the Previewer. How this interface works on the' + 344 ' Previewer may be different from that on a real device.'); 345 const len = args.length; 346 if (typeof args[len - 1] === 'function') { 347 args[len - 1].call(this, paramMock.businessErrorMock); 348 } else { 349 return new Promise((resolve) => { 350 resolve(); 351 }); 352 } 353 }, 354 stop: function (...args) { 355 console.warn('CaptureSession.stop interface mocked in the Previewer. How this interface works on the' + 356 ' Previewer may be different from that on a real device.'); 357 const len = args.length; 358 if (typeof args[len - 1] === 'function') { 359 args[len - 1].call(this, paramMock.businessErrorMock); 360 } else { 361 return new Promise((resolve) => { 362 resolve(); 363 }); 364 } 365 }, 366 release: function (...args) { 367 console.warn('CaptureSession.release interface mocked in the Previewer. How this interface works on the' + 368 ' Previewer may be different from that on a real device.'); 369 const len = args.length; 370 if (typeof args[len - 1] === 'function') { 371 args[len - 1].call(this, paramMock.businessErrorMock); 372 } else { 373 return new Promise((resolve) => { 374 resolve(); 375 }); 376 } 377 }, 378 on: function (...args) { 379 console.warn('CaptureSession.on interface mocked in the Previewer. How this interface works on the' + 380 ' Previewer may be different from that on a real device.'); 381 } 382 } 383 const PreviewOutput = { 384 release: function (...args) { 385 console.warn('PreviewOutput.release interface mocked in the Previewer. How this interface works on the' + 386 ' Previewer may be different from that on a real device.'); 387 const len = args.length; 388 if (typeof args[len - 1] === 'function') { 389 args[len - 1].call(this, paramMock.businessErrorMock); 390 } else { 391 return new Promise((resolve) => { 392 resolve(); 393 }); 394 } 395 }, 396 on: function (...args) { 397 console.warn('PreviewOutput.release interface mocked in the Previewer. How this interface works on the' + 398 ' Previewer may be different from that on a real device.'); 399 }, 400 } 401 const PhotoOutput = { 402 capture: function (...args) { 403 console.warn('PhotoOutput.capture interface mocked in the Previewer. How this interface works on the' + 404 ' Previewer may be different from that on a real device.'); 405 const len = args.length; 406 if (typeof args[len - 1] === 'function') { 407 args[len - 1].call(this, paramMock.businessErrorMock); 408 } else { 409 return new Promise((resolve) => { 410 resolve(); 411 }); 412 } 413 }, 414 release: function (...args) { 415 console.warn('PhotoOutput.release interface mocked in the Previewer. How this interface works on the' + 416 ' Previewer may be different from that on a real device.'); 417 const len = args.length; 418 if (typeof args[len - 1] === 'function') { 419 args[len - 1].call(this, paramMock.businessErrorMock); 420 } else { 421 return new Promise((resolve) => { 422 resolve(); 423 }); 424 } 425 }, 426 on: function (...args) { 427 console.warn('PhotoOutput.on interface mocked in the Previewer. How this interface works on the' + 428 ' Previewer may be different from that on a real device.'); 429 } 430 } 431 const VideoOutput = { 432 start: function (...args) { 433 console.warn('VideoOutput.start interface mocked in the Previewer. How this interface works on the' + 434 ' Previewer may be different from that on a real device.'); 435 const len = args.length; 436 if (typeof args[len - 1] === 'function') { 437 args[len - 1].call(this, paramMock.businessErrorMock); 438 } else { 439 return new Promise((resolve) => { 440 resolve(); 441 }); 442 } 443 }, 444 stop: function (...args) { 445 console.warn('VideoOutput.stop interface mocked in the Previewer. How this interface works on the' + 446 ' Previewer may be different from that on a real device.'); 447 const len = args.length; 448 if (typeof args[len - 1] === 'function') { 449 args[len - 1].call(this, paramMock.businessErrorMock); 450 } else { 451 return new Promise((resolve) => { 452 resolve(); 453 }); 454 } 455 }, 456 release: function (...args) { 457 console.warn('VideoOutput.release interface mocked in the Previewer. How this interface works on the' + 458 ' Previewer may be different from that on a real device.'); 459 const len = args.length; 460 if (typeof args[len - 1] === 'function') { 461 args[len - 1].call(this, paramMock.businessErrorMock); 462 } else { 463 return new Promise((resolve) => { 464 resolve(); 465 }); 466 } 467 }, 468 on: function (...args) { 469 console.warn('VideoOutput.on interface mocked in the Previewer. How this interface works on the' + 470 ' Previewer may be different from that on a real device.'); 471 } 472 } 473 return multimediaCameraMock 474}