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: CameraPosition, 22 cameraType: CameraType, 23 connectionType: ConnectionType 24 } 25 const multimediaCameraMock = { 26 getCameraManager: function (...args) { 27 console.warn('camera.getCameraManager interface mocked in the Previewer. How this interface works on the' + 28 ' Previewer may be different from that on a real device.'); 29 const len = args.length; 30 if (typeof args[len - 1] === 'function') { 31 args[len - 1].call(this, paramMock.businessErrorMock, CameraManager); 32 } else { 33 return new Promise((resolve) => { 34 resolve(CameraManager); 35 }); 36 } 37 }, 38 createCaptureSession: function (...args) { 39 console.warn('camera.createCaptureSession interface mocked in the Previewer. How this interface works on the' + 40 ' Previewer may be different from that on a real device.'); 41 const len = args.length; 42 if (typeof args[len - 1] === 'function') { 43 args[len - 1].call(this, paramMock.businessErrorMock, CaptureSession); 44 } else { 45 return new Promise((resolve) => { 46 resolve(CaptureSession); 47 }); 48 } 49 }, 50 createPreviewOutput: function (...args) { 51 console.warn('camera.createPreviewOutput interface mocked in the Previewer. How this interface works on the' + 52 ' Previewer may be different from that on a real device.'); 53 const len = args.length; 54 if (typeof args[len - 1] === 'function') { 55 args[len - 1].call(this, paramMock.businessErrorMock, PreviewOutput); 56 } else { 57 return new Promise((resolve) => { 58 resolve(PreviewOutput); 59 }); 60 } 61 }, 62 createPhotoOutput: function (...args) { 63 console.warn('camera.createPhotoOutput interface mocked in the Previewer. How this interface works on the' + 64 ' Previewer may be different from that on a real device.'); 65 const len = args.length; 66 if (typeof args[len - 1] === 'function') { 67 args[len - 1].call(this, paramMock.businessErrorMock, PhotoOutput); 68 } else { 69 return new Promise((resolve) => { 70 resolve(PhotoOutput); 71 }); 72 } 73 }, 74 createVideoOutput: function (...args) { 75 console.warn('camera.createVideoOutput interface mocked in the Previewer. How this interface works on the' + 76 ' Previewer may be different from that on a real device.'); 77 const len = args.length; 78 if (typeof args[len - 1] === 'function') { 79 args[len - 1].call(this, paramMock.businessErrorMock, VideoOutput); 80 } else { 81 return new Promise((resolve) => { 82 resolve(VideoOutput); 83 }); 84 } 85 }, 86 } 87 const CameraStatus = { 88 CAMERA_STATUS_APPEAR: 0, 89 CAMERA_STATUS_DISAPPEAR: 1, 90 CAMERA_STATUS_AVAILABLE: 2, 91 CAMERA_STATUS_UNAVAILABLE: 3 92 } 93 const CameraStatusInfo = { 94 camera: Camera, 95 status: CameraStatus 96 } 97 const CameraManager = { 98 getCameras: function (...args) { 99 console.warn('CameraManager.getCameras interface mocked in the Previewer. How this interface works on the' + 100 ' Previewer may be different from that on a real device.'); 101 const len = args.length; 102 if (typeof args[len - 1] === 'function') { 103 args[len - 1].call(this, paramMock.businessErrorMock, [Camera]); 104 } else { 105 return new Promise((resolve) => { 106 resolve([Camera]); 107 }); 108 } 109 }, 110 createCameraInput: function (...args) { 111 console.warn('CameraManager.createCameraInput interface mocked in the Previewer. How this interface works on the' + 112 ' Previewer may be different from that on a real device.'); 113 const len = args.length; 114 if (typeof args[len - 1] === 'function') { 115 args[len - 1].call(this, paramMock.businessErrorMock, CameraInput); 116 } else { 117 return new Promise((resolve) => { 118 resolve(CameraInput); 119 }); 120 } 121 }, 122 on: function (...args) { 123 console.warn('CameraManager.on interface mocked in the Previewer. How this interface works on the' + 124 ' Previewer may be different from that on a real device.'); 125 const len = args.length; 126 if (typeof args[len - 1] === 'function') { 127 if(args[0] == 'cameraStatus'){ 128 args[len - 1].call(this, paramMock.businessErrorMock, CameraStatusInfo); 129 } 130 } 131 } 132 } 133 const CameraPosition = { 134 CAMERA_POSITION_UNSPECIFIED: 0, 135 CAMERA_POSITION_BACK: 1, 136 CAMERA_POSITION_FRONT: 2 137 } 138 const CameraType = { 139 CAMERA_TYPE_UNSPECIFIED: 0, 140 CAMERA_TYPE_WIDE_ANGLE: 1, 141 CAMERA_TYPE_ULTRA_WIDE: 2, 142 CAMERA_TYPE_TELEPHOTO: 3, 143 CAMERA_TYPE_TRUE_DEPTH: 4 144 } 145 const ConnectionType = { 146 CAMERA_CONNECTION_BUILT_IN: 0, 147 CAMERA_CONNECTION_USB_PLUGIN: 1, 148 CAMERA_CONNECTION_REMOTE: 2 149 } 150 const Size = { 151 height: '[PC preview] unknow height', 152 width: '[PC preview] unknow width' 153 } 154 const CameraInputErrorCode = { 155 ERROR_UNKNOWN: -1 156 } 157 const CameraInputError = { 158 code: CameraInputErrorCode 159 } 160 const FlashMode = { 161 FLASH_MODE_CLOSE: 0, 162 FLASH_MODE_OPEN: 1, 163 FLASH_MODE_AUTO: 2, 164 FLASH_MODE_ALWAYS_OPEN: 3 165 } 166 const FocusMode = { 167 FOCUS_MODE_MANUAL: 0, 168 FOCUS_MODE_CONTINUOUS_AUTO: 1, 169 FOCUS_MODE_AUTO: 2, 170 FOCUS_MODE_LOCKED: 3 171 } 172 const FocusState = { 173 FOCUS_STATE_SCAN: 0, 174 FOCUS_STATE_FOCUSED: 1, 175 FOCUS_STATE_UNFOCUSED: 2 176 } 177 const CameraInput = { 178 getCameraId: function (...args) { 179 console.warn('CameraInput.getCameraId interface mocked in the Previewer. How this interface works on the' + 180 ' Previewer may be different from that on a real device.'); 181 const len = args.length; 182 if (typeof args[len - 1] === 'function') { 183 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 184 } else { 185 return new Promise((resolve) => { 186 resolve(paramMock.paramStringMock); 187 }); 188 } 189 }, 190 hasFlash: function (...args) { 191 console.warn('CameraInput.hasFlash interface mocked in the Previewer. How this interface works on the' + 192 ' Previewer may be different from that on a real device.'); 193 const len = args.length; 194 if (typeof args[len - 1] === 'function') { 195 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 196 } else { 197 return new Promise((resolve) => { 198 resolve(paramMock.paramBooleanMock); 199 }); 200 } 201 }, 202 isFlashModeSupported: function (...args) { 203 console.warn('CameraInput.isFlashModeSupported interface mocked in the Previewer. How this interface works on the' + 204 ' Previewer may be different from that on a real device.'); 205 const len = args.length; 206 if (typeof args[len - 1] === 'function') { 207 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 208 } else { 209 return new Promise((resolve) => { 210 resolve(paramMock.paramBooleanMock); 211 }); 212 } 213 }, 214 getFlashMode: function (...args) { 215 console.warn('CameraInput.getFlashMode interface mocked in the Previewer. How this interface works on the' + 216 ' Previewer may be different from that on a real device.'); 217 const len = args.length; 218 if (typeof args[len - 1] === 'function') { 219 args[len - 1].call(this, paramMock.businessErrorMock, FlashMode); 220 } else { 221 return new Promise((resolve) => { 222 resolve(FlashMode); 223 }); 224 } 225 }, 226 setFlashMode: function (...args) { 227 console.warn('CameraInput.setFlashMode interface mocked in the Previewer. How this interface works on the' + 228 ' Previewer may be different from that on a real device.'); 229 const len = args.length; 230 if (typeof args[len - 1] === 'function') { 231 args[len - 1].call(this, paramMock.businessErrorMock); 232 } else { 233 return new Promise((resolve) => { 234 resolve(); 235 }); 236 } 237 }, 238 isFocusModeSupported: function (...args) { 239 console.warn('CameraInput.isFocusModeSupported interface mocked in the Previewer. How this interface works on the' + 240 ' Previewer may be different from that on a real device.'); 241 const len = args.length; 242 if (typeof args[len - 1] === 'function') { 243 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 244 } else { 245 return new Promise((resolve) => { 246 resolve(paramMock.paramBooleanMock); 247 }); 248 } 249 }, 250 getFocusMode: function (...args) { 251 console.warn('CameraInput.getFocusMode interface mocked in the Previewer. How this interface works on the' + 252 ' Previewer may be different from that on a real device.'); 253 const len = args.length; 254 if (typeof args[len - 1] === 'function') { 255 args[len - 1].call(this, paramMock.businessErrorMock, FocusMode); 256 } else { 257 return new Promise((resolve) => { 258 resolve(FocusMode); 259 }); 260 } 261 }, 262 setFocusMode: function (...args) { 263 console.warn('CameraInput.setFocusMode interface mocked in the Previewer. How this interface works on the' + 264 ' Previewer may be different from that on a real device.'); 265 const len = args.length; 266 if (typeof args[len - 1] === 'function') { 267 args[len - 1].call(this, paramMock.businessErrorMock); 268 } else { 269 return new Promise((resolve) => { 270 resolve(); 271 }); 272 } 273 }, 274 getZoomRatioRange: function (...args) { 275 console.warn('CameraInput.getZoomRatioRange interface mocked in the Previewer. How this interface works on the' + 276 ' Previewer may be different from that on a real device.'); 277 const len = args.length; 278 if (typeof args[len - 1] === 'function') { 279 args[len - 1].call(this, paramMock.businessErrorMock, [paramMock.paramNumberMock]); 280 } else { 281 return new Promise((resolve) => { 282 resolve([paramMock.paramNumberMock]); 283 }); 284 } 285 }, 286 getZoomRatio: function (...args) { 287 console.warn('CameraInput.getZoomRatio interface mocked in the Previewer. How this interface works on the' + 288 ' Previewer may be different from that on a real device.'); 289 const len = args.length; 290 if (typeof args[len - 1] === 'function') { 291 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 292 } else { 293 return new Promise((resolve) => { 294 resolve(paramMock.paramNumberMock); 295 }); 296 } 297 }, 298 setZoomRatio: function (...args) { 299 console.warn('CameraInput.setZoomRatio interface mocked in the Previewer. How this interface works on the' + 300 ' Previewer may be different from that on a real device.'); 301 const len = args.length; 302 if (typeof args[len - 1] === 'function') { 303 args[len - 1].call(this, paramMock.businessErrorMock); 304 } else { 305 return new Promise((resolve) => { 306 resolve(); 307 }); 308 } 309 }, 310 release: function (...args) { 311 console.warn('CameraInput.release interface mocked in the Previewer. How this interface works on the' + 312 ' Previewer may be different from that on a real device.'); 313 const len = args.length; 314 if (typeof args[len - 1] === 'function') { 315 args[len - 1].call(this, paramMock.businessErrorMock); 316 } else { 317 return new Promise((resolve) => { 318 resolve(); 319 }); 320 } 321 }, 322 on: function (...args) { 323 console.warn('CameraInput.on interface mocked in the Previewer. How this interface works on the' + 324 ' Previewer may be different from that on a real device.'); 325 const len = args.length; 326 if (typeof args[len - 1] === 'function') { 327 if(args[0] == 'focusStateChange'){ 328 args[len - 1].call(this, paramMock.businessErrorMock, FocusState); 329 } else if (args[0] == 'error') { 330 args[len - 1].call(this, paramMock.businessErrorMock, CameraInputError); 331 } 332 } 333 } 334 } 335 const CaptureSessionErrorCode = { 336 ERROR_UNKNOWN: -1 337 } 338 const CaptureSessionError = { 339 code: CaptureSessionErrorCode 340 } 341 const CaptureSession = { 342 beginConfig: function (...args) { 343 console.warn('CaptureSession.beginConfig 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 commitConfig: function (...args) { 355 console.warn('CaptureSession.commitConfig 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 addInput: function (...args) { 367 console.warn('CaptureSession.addInput 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 addOutput: function (...args) { 379 console.warn('CaptureSession.addOutput interface mocked in the Previewer. How this interface works on the' + 380 ' Previewer may be different from that on a real device.'); 381 const len = args.length; 382 if (typeof args[len - 1] === 'function') { 383 args[len - 1].call(this, paramMock.businessErrorMock); 384 } else { 385 return new Promise((resolve) => { 386 resolve(); 387 }); 388 } 389 }, 390 removeInput: function (...args) { 391 console.warn('CaptureSession.removeInput interface mocked in the Previewer. How this interface works on the' + 392 ' Previewer may be different from that on a real device.'); 393 const len = args.length; 394 if (typeof args[len - 1] === 'function') { 395 args[len - 1].call(this, paramMock.businessErrorMock); 396 } else { 397 return new Promise((resolve) => { 398 resolve(); 399 }); 400 } 401 }, 402 removeOutput: function (...args) { 403 console.warn('CaptureSession.removeOutput 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 start: function (...args) { 415 console.warn('CaptureSession.start 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 stop: function (...args) { 427 console.warn('CaptureSession.stop interface mocked in the Previewer. How this interface works on the' + 428 ' Previewer may be different from that on a real device.'); 429 const len = args.length; 430 if (typeof args[len - 1] === 'function') { 431 args[len - 1].call(this, paramMock.businessErrorMock); 432 } else { 433 return new Promise((resolve) => { 434 resolve(); 435 }); 436 } 437 }, 438 release: function (...args) { 439 console.warn('CaptureSession.release interface mocked in the Previewer. How this interface works on the' + 440 ' Previewer may be different from that on a real device.'); 441 const len = args.length; 442 if (typeof args[len - 1] === 'function') { 443 args[len - 1].call(this, paramMock.businessErrorMock); 444 } else { 445 return new Promise((resolve) => { 446 resolve(); 447 }); 448 } 449 }, 450 on: function (...args) { 451 console.warn('CaptureSession.on interface mocked in the Previewer. How this interface works on the' + 452 ' Previewer may be different from that on a real device.'); 453 const len = args.length; 454 if (typeof args[len - 1] === 'function') { 455 if(args[0] == 'error'){ 456 args[len - 1].call(this, paramMock.businessErrorMock, CaptureSessionError); 457 } 458 } 459 } 460 } 461 const PreviewOutputErrorCode = { 462 ERROR_UNKNOWN: -1 463 } 464 const PreviewOutputError = { 465 code: PreviewOutputErrorCode 466 } 467 const PreviewOutput = { 468 release: function (...args) { 469 console.warn('PreviewOutput.release interface mocked in the Previewer. How this interface works on the' + 470 ' Previewer may be different from that on a real device.'); 471 const len = args.length; 472 if (typeof args[len - 1] === 'function') { 473 args[len - 1].call(this, paramMock.businessErrorMock); 474 } else { 475 return new Promise((resolve) => { 476 resolve(); 477 }); 478 } 479 }, 480 on: function (...args) { 481 console.warn('PreviewOutput.on interface mocked in the Previewer. How this interface works on the' + 482 ' Previewer may be different from that on a real device.'); 483 const len = args.length; 484 if (typeof args[len - 1] === 'function') { 485 if(args[0] == 'frameStart'){ 486 args[len - 1].call(this, paramMock.businessErrorMock); 487 } else if (args[0] == 'frameEnd') { 488 args[len - 1].call(this, paramMock.businessErrorMock); 489 } else if (args[0] == 'error') { 490 args[len - 1].call(this, paramMock.businessErrorMock, PreviewOutputError); 491 } 492 } 493 }, 494 } 495 const ImageRotation = { 496 ROTATION_0: 0, 497 ROTATION_90: 90, 498 ROTATION_180: 180, 499 ROTATION_270: 270 500 } 501 const QualityLevel = { 502 QUALITY_LEVEL_HIGH: 0, 503 QUALITY_LEVEL_MEDIUM: 1, 504 QUALITY_LEVEL_LOW: 2 505 } 506 const PhotoCaptureSetting = { 507 quality:QualityLevel, 508 rotation: ImageRotation 509 } 510 const FrameShutterInfo = { 511 captureId: '[PC preview] unknow captureId', 512 timestamp: '[PC preview] unknow timestamp' 513 } 514 const CaptureEndInfo = { 515 captureId: '[PC preview] unknow captureId', 516 frameCount: '[PC preview] unknow frameCount' 517 } 518 const PhotoOutputErrorCode = { 519 ERROR_UNKNOWN: -1 520 } 521 const PhotoOutputError = { 522 code: PhotoOutputErrorCode 523 } 524 const PhotoOutput = { 525 capture: function (...args) { 526 console.warn('PhotoOutput.capture interface mocked in the Previewer. How this interface works on the' + 527 ' Previewer may be different from that on a real device.'); 528 const len = args.length; 529 if (typeof args[len - 1] === 'function') { 530 args[len - 1].call(this, paramMock.businessErrorMock); 531 } else { 532 return new Promise((resolve) => { 533 resolve(); 534 }); 535 } 536 }, 537 release: function (...args) { 538 console.warn('PhotoOutput.release interface mocked in the Previewer. How this interface works on the' + 539 ' Previewer may be different from that on a real device.'); 540 const len = args.length; 541 if (typeof args[len - 1] === 'function') { 542 args[len - 1].call(this, paramMock.businessErrorMock); 543 } else { 544 return new Promise((resolve) => { 545 resolve(); 546 }); 547 } 548 }, 549 on: function (...args) { 550 console.warn('PhotoOutput.on interface mocked in the Previewer. How this interface works on the' + 551 ' Previewer may be different from that on a real device.'); 552 const len = args.length; 553 if (typeof args[len - 1] === 'function') { 554 if(args[0] == 'captureStart'){ 555 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 556 } else if (args[0] == 'frameShutter') { 557 args[len - 1].call(this, paramMock.businessErrorMock, FrameShutterInfo); 558 } else if (args[0] == 'captureEnd') { 559 args[len - 1].call(this, paramMock.businessErrorMock, CaptureEndInfo); 560 } else if (args[0] == 'error') { 561 args[len - 1].call(this, paramMock.businessErrorMock, PhotoOutputError); 562 } 563 } 564 } 565 } 566 const VideoOutputErrorCode = { 567 ERROR_UNKNOWN: -1 568 } 569 const VideoOutputError = { 570 code: VideoOutputErrorCode 571 } 572 const VideoOutput = { 573 start: function (...args) { 574 console.warn('VideoOutput.start interface mocked in the Previewer. How this interface works on the' + 575 ' Previewer may be different from that on a real device.'); 576 const len = args.length; 577 if (typeof args[len - 1] === 'function') { 578 args[len - 1].call(this, paramMock.businessErrorMock); 579 } else { 580 return new Promise((resolve) => { 581 resolve(); 582 }); 583 } 584 }, 585 stop: function (...args) { 586 console.warn('VideoOutput.stop interface mocked in the Previewer. How this interface works on the' + 587 ' Previewer may be different from that on a real device.'); 588 const len = args.length; 589 if (typeof args[len - 1] === 'function') { 590 args[len - 1].call(this, paramMock.businessErrorMock); 591 } else { 592 return new Promise((resolve) => { 593 resolve(); 594 }); 595 } 596 }, 597 release: function (...args) { 598 console.warn('VideoOutput.release interface mocked in the Previewer. How this interface works on the' + 599 ' Previewer may be different from that on a real device.'); 600 const len = args.length; 601 if (typeof args[len - 1] === 'function') { 602 args[len - 1].call(this, paramMock.businessErrorMock); 603 } else { 604 return new Promise((resolve) => { 605 resolve(); 606 }); 607 } 608 }, 609 on: function (...args) { 610 console.warn('VideoOutput.on interface mocked in the Previewer. How this interface works on the' + 611 ' Previewer may be different from that on a real device.'); 612 const len = args.length; 613 if (typeof args[len - 1] === 'function') { 614 if(args[0] == 'frameStart'){ 615 args[len - 1].call(this, paramMock.businessErrorMock); 616 } else if (args[0] == 'frameEnd') { 617 args[len - 1].call(this, paramMock.businessErrorMock); 618 } else if (args[0] == 'error') { 619 args[len - 1].call(this, paramMock.businessErrorMock, VideoOutputError); 620 } 621 } 622 } 623 } 624 return multimediaCameraMock 625}