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 mockCall() { 19 const CallWaitingStatus = "[PC Preview] unknow CallWaitingStatus"; 20 const RestrictionStatus = "[PC Preview] unknow RestrictionStatus"; 21 const CallAttributeOptions = { 22 accountNumber: "[PC Preview] unknow accountNumber", 23 speakerphoneOn: "[PC Preview] unknow speakerphoneOn", 24 accountId: "[PC Preview] unknow accountId", 25 videoState: "[PC Preview] unknow videoState", 26 startTime: "[PC Preview] unknow startTime", 27 isEcc: "[PC Preview] unknow isEcc", 28 callType: "[PC Preview] unknow callType", 29 callId: "[PC Preview] unknow callId", 30 callState: "[PC Preview] unknow callState", 31 conferenceState: "[PC Preview] unknow conferenceState" 32 } 33 const CallTransferResult = { 34 status: "[PC Preview] unknow status", 35 number: "[PC Preview] unknow number", 36 } 37 const call = { 38 dial: function (...args) { 39 console.warn("telephony.call.dial interface mocked in the Previewer. How this interface works on the Previewer may" + 40 " 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, paramMock.paramBooleanMock); 44 } else { 45 return new Promise((resolve, reject) => { 46 resolve(paramMock.paramBooleanMock); 47 }) 48 } 49 }, 50 makeCall: function (...args) { 51 console.warn("telephony.call.makeCall interface mocked in the Previewer. How this interface works on the Previewer may" + 52 " 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); 56 } else { 57 return new Promise((resolve, reject) => { 58 resolve(); 59 }) 60 } 61 }, 62 hasCall: function (...args) { 63 console.warn("telephony.call.hasCall interface mocked in the Previewer. How this interface works on the Previewer may" + 64 " 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, paramMock.paramBooleanMock); 68 } else { 69 return new Promise((resolve, reject) => { 70 resolve(paramMock.paramBooleanMock); 71 }) 72 } 73 }, 74 getCallState: function (...args) { 75 console.warn("telephony.call.getCallState interface mocked in the Previewer. How this interface works on the Previewer may" + 76 " 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, CallState); 80 } else { 81 return new Promise((resolve, reject) => { 82 resolve(CallState); 83 }) 84 } 85 }, 86 displayCallScreen: function (...args) { 87 console.warn("telephony.call.displayCallScreen interface mocked in the Previewer. How this interface works on the Previewer may" + 88 " be different from that on a real device.") 89 const len = args.length 90 if (typeof args[len - 1] === 'function') { 91 args[len - 1].call(this, paramMock.businessErrorMock); 92 } else { 93 return new Promise((resolve, reject) => { 94 resolve(); 95 }) 96 } 97 }, 98 muteRinger: function (...args) { 99 console.warn("telephony.call.muteRinger interface mocked in the Previewer. How this interface works on the Previewer may" + 100 " 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); 104 } else { 105 return new Promise((resolve, reject) => { 106 resolve(); 107 }) 108 } 109 }, 110 hasVoiceCapability: function () { 111 console.warn("telephony.call.hasVoiceCapability interface mocked in the Previewer. How this interface works on the Previewer may" + 112 " be different from that on a real device.") 113 return paramMock.paramBooleanMock; 114 }, 115 isVideoCallingEnabled: function (...args) { 116 console.warn("telephony.call.isVideoCallingEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + 117 " be different from that on a real device.") 118 const len = args.length 119 if (typeof args[len - 1] === 'function') { 120 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 121 } else { 122 return new Promise((resolve, reject) => { 123 resolve(paramMock.paramBooleanMock); 124 }) 125 } 126 }, 127 inputDialerSpecialCode: function (...args) { 128 console.warn("telephony.call.inputDialerSpecialCode interface mocked in the Previewer. How this interface works on the Previewer may" + 129 " be different from that on a real device.") 130 const len = args.length 131 if (typeof args[len - 1] === 'function') { 132 args[len - 1].call(this, paramMock.businessErrorMock); 133 } else { 134 return new Promise((resolve, reject) => { 135 resolve(); 136 }) 137 } 138 }, 139 isHacEnabled: function (...args) { 140 console.warn("telephony.call.isHacEnabled interface mocked in the Previewer. How this interface works on the Previewer may" + 141 " be different from that on a real device.") 142 const len = args.length 143 if (typeof args[len - 1] === 'function') { 144 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 145 } else { 146 return new Promise((resolve, reject) => { 147 resolve(paramMock.paramBooleanMock); 148 }) 149 } 150 }, 151 isEmergencyPhoneNumber: function (...args) { 152 console.warn("telephony.call.isEmergencyPhoneNumber interface mocked in the Previewer. How this interface works on the Previewer may" + 153 " be different from that on a real device.") 154 const len = args.length 155 if (typeof args[len - 1] === 'function') { 156 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 157 } else { 158 return new Promise((resolve, reject) => { 159 resolve(paramMock.paramBooleanMock); 160 }) 161 } 162 }, 163 formatPhoneNumber: function (...args) { 164 console.warn("telephony.call.formatPhoneNumber interface mocked in the Previewer. How this interface works on the Previewer may" + 165 " be different from that on a real device.") 166 const len = args.length 167 if (typeof args[len - 1] === 'function') { 168 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 169 } else { 170 return new Promise((resolve, reject) => { 171 resolve(paramMock.paramStringMock); 172 }) 173 } 174 }, 175 formatPhoneNumberToE164: function (...args) { 176 console.warn("telephony.call.formatPhoneNumberToE164 interface mocked in the Previewer. How this interface works on the Previewer may" + 177 " be different from that on a real device.") 178 const len = args.length 179 if (typeof args[len - 1] === 'function') { 180 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 181 } else { 182 return new Promise((resolve, reject) => { 183 resolve(paramMock.paramStringMock); 184 }) 185 } 186 }, 187 comparePhoneNumbers: function (...args) { 188 console.warn("telephony.call.comparePhoneNumbers interface mocked in the Previewer. How this interface works on the Previewer may" + 189 " be different from that on a real device.") 190 const len = args.length 191 if (typeof args[len - 1] === 'function') { 192 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 193 } else { 194 return new Promise((resolve, reject) => { 195 resolve(paramMock.paramBooleanMock); 196 }) 197 } 198 }, 199 getCallerIndex: function (...args) { 200 console.warn("telephony.call.getCallerIndex interface mocked in the Previewer. How this interface works on the Previewer may" + 201 " be different from that on a real device.") 202 const len = args.length 203 if (typeof args[len - 1] === 'function') { 204 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 205 } else { 206 return new Promise((resolve, reject) => { 207 resolve(paramMock.paramNumberMock); 208 }) 209 } 210 }, 211 getCountryCodeFromDbNumber: function (...args) { 212 console.warn("telephony.call.getCountryCodeFromDbNumber interface mocked in the Previewer. How this interface works on the Previewer may" + 213 " be different from that on a real device.") 214 const len = args.length 215 if (typeof args[len - 1] === 'function') { 216 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); 217 } else { 218 return new Promise((resolve, reject) => { 219 resolve(paramMock.paramStringMock); 220 }) 221 } 222 }, 223 getIntlPrefixAndCountryCodeLen: function (...args) { 224 console.warn("telephony.call.getIntlPrefixAndCountryCodeLen interface mocked in the Previewer. How this interface works on the Previewer may" + 225 " be different from that on a real device.") 226 const len = args.length 227 if (typeof args[len - 1] === 'function') { 228 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 229 } else { 230 return new Promise((resolve, reject) => { 231 resolve(paramMock.paramNumberMock); 232 }) 233 } 234 }, 235 answer: function (...args) { 236 console.warn("telephony.call.answer interface mocked in the Previewer. How this interface works on the Previewer may" + 237 " be different from that on a real device.") 238 const len = args.length 239 if (typeof args[len - 1] === 'function') { 240 args[len - 1].call(this, paramMock.businessErrorMock); 241 } else { 242 return new Promise((resolve, reject) => { 243 resolve(); 244 }) 245 } 246 }, 247 hangup: function (...args) { 248 console.warn("telephony.call.hangup interface mocked in the Previewer. How this interface works on the Previewer may" + 249 " be different from that on a real device.") 250 const len = args.length 251 if (typeof args[len - 1] === 'function') { 252 args[len - 1].call(this, paramMock.businessErrorMock); 253 } else { 254 return new Promise((resolve, reject) => { 255 resolve(); 256 }) 257 } 258 }, 259 reject: function (...args) { 260 console.warn("telephony.call.reject interface mocked in the Previewer. How this interface works on the Previewer may" + 261 " be different from that on a real device.") 262 const len = args.length 263 if (typeof args[len - 1] === 'function') { 264 args[len - 1].call(this, paramMock.businessErrorMock); 265 } else { 266 return new Promise((resolve, reject) => { 267 resolve(); 268 }) 269 } 270 }, 271 holdCall: function (...args) { 272 console.warn("telephony.call.holdCall interface mocked in the Previewer. How this interface works on the Previewer may" + 273 " be different from that on a real device.") 274 const len = args.length 275 if (typeof args[len - 1] === 'function') { 276 args[len - 1].call(this, paramMock.businessErrorMock); 277 } else { 278 return new Promise((resolve, reject) => { 279 resolve(); 280 }) 281 } 282 }, 283 unHoldCall: function (...args) { 284 console.warn("telephony.call.unHoldCall interface mocked in the Previewer. How this interface works on the Previewer may" + 285 " be different from that on a real device.") 286 const len = args.length 287 if (typeof args[len - 1] === 'function') { 288 args[len - 1].call(this, paramMock.businessErrorMock); 289 } else { 290 return new Promise((resolve, reject) => { 291 resolve(); 292 }) 293 } 294 }, 295 switchCall: function (...args) { 296 console.warn("telephony.call.switchCall interface mocked in the Previewer. How this interface works on the Previewer may" + 297 " be different from that on a real device.") 298 const len = args.length 299 if (typeof args[len - 1] === 'function') { 300 args[len - 1].call(this, paramMock.businessErrorMock); 301 } else { 302 return new Promise((resolve, reject) => { 303 resolve(); 304 }) 305 } 306 }, 307 combineConference: function (...args) { 308 console.warn("telephony.call.combineConference interface mocked in the Previewer. How this interface works on the Previewer may" + 309 " be different from that on a real device.") 310 const len = args.length 311 if (typeof args[len - 1] === 'function') { 312 args[len - 1].call(this, paramMock.businessErrorMock); 313 } else { 314 return new Promise((resolve, reject) => { 315 resolve(); 316 }) 317 } 318 }, 319 getMainCallId: function (...args) { 320 console.warn("telephony.call.getMainCallId interface mocked in the Previewer. How this interface works on the Previewer may" + 321 " be different from that on a real device.") 322 const len = args.length 323 if (typeof args[len - 1] === 'function') { 324 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); 325 } else { 326 return new Promise((resolve, reject) => { 327 resolve(paramMock.paramNumberMock); 328 }) 329 } 330 }, 331 getSubCallIdList: function (...args) { 332 console.warn("telephony.call.getSubCallIdList interface mocked in the Previewer. How this interface works on the Previewer may" + 333 " be different from that on a real device.") 334 const len = args.length 335 if (typeof args[len - 1] === 'function') { 336 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); 337 } else { 338 return new Promise((resolve, reject) => { 339 resolve(paramMock.paramArrayMock); 340 }) 341 } 342 }, 343 getCallIdListForConference: function (...args) { 344 console.warn("telephony.call.getCallIdListForConference interface mocked in the Previewer. How this interface works on the Previewer may" + 345 " be different from that on a real device.") 346 const len = args.length 347 if (typeof args[len - 1] === 'function') { 348 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramArrayMock); 349 } else { 350 return new Promise((resolve, reject) => { 351 resolve(paramMock.paramArrayMock); 352 }) 353 } 354 }, 355 getCallWaitingStatus: function (...args) { 356 console.warn("telephony.call.getCallWaitingStatus interface mocked in the Previewer. How this interface works on the Previewer may" + 357 " be different from that on a real device.") 358 const len = args.length 359 if (typeof args[len - 1] === 'function') { 360 args[len - 1].call(this, paramMock.businessErrorMock, CallWaitingStatus); 361 } else { 362 return new Promise((resolve, reject) => { 363 resolve(CallWaitingStatus); 364 }) 365 } 366 }, 367 setCallWaiting: function (...args) { 368 console.warn("telephony.call.setCallWaiting interface mocked in the Previewer. How this interface works on the Previewer may" + 369 " be different from that on a real device.") 370 const len = args.length 371 if (typeof args[len - 1] === 'function') { 372 args[len - 1].call(this, paramMock.businessErrorMock); 373 } else { 374 return new Promise((resolve, reject) => { 375 resolve(); 376 }) 377 } 378 }, 379 startDTMF: function (...args) { 380 console.warn("telephony.call.startDTMF interface mocked in the Previewer. How this interface works on the Previewer may" + 381 " be different from that on a real device.") 382 const len = args.length 383 if (typeof args[len - 1] === 'function') { 384 args[len - 1].call(this, paramMock.businessErrorMock); 385 } else { 386 return new Promise((resolve, reject) => { 387 resolve(); 388 }) 389 } 390 }, 391 stopDTMF: function (...args) { 392 console.warn("telephony.call.stopDTMF interface mocked in the Previewer. How this interface works on the Previewer may" + 393 " be different from that on a real device.") 394 const len = args.length 395 if (typeof args[len - 1] === 'function') { 396 args[len - 1].call(this, paramMock.businessErrorMock); 397 } else { 398 return new Promise((resolve, reject) => { 399 resolve(); 400 }) 401 } 402 }, 403 isInEmergencyCall: function (...args) { 404 console.warn("telephony.call.isInEmergencyCall interface mocked in the Previewer. How this interface works on the Previewer may" + 405 " be different from that on a real device.") 406 const len = args.length 407 if (typeof args[len - 1] === 'function') { 408 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 409 } else { 410 return new Promise((resolve, reject) => { 411 resolve(paramMock.paramBooleanMock); 412 }) 413 } 414 }, 415 on: function (...args) { 416 console.warn("telephony.call.on interface mocked in the Previewer. How this interface works on the Previewer may " + 417 "be different from that on a real device.") 418 const len = args.length 419 if (typeof args[len - 1] === 'function') { 420 if (args[0] == 'callDetailsChange') { 421 args[len - 1].call(this, CallAttributeOptions); 422 } else if (args[0] == 'callEventChange') { 423 args[len - 1].call(this, paramMock.paramObjectMock); 424 } 425 } 426 }, 427 off: function (...args) { 428 console.warn("telephony.call.off interface mocked in the Previewer. How this interface works on the Previewer may" + 429 " be different from that on a real device.") 430 const len = args.length 431 if (typeof args[len - 1] === 'function') { 432 if (args[0] == 'callDetailsChange') { 433 args[len - 1].call(this, CallAttributeOptions); 434 } else if (args[0] == 'callEventChange') { 435 args[len - 1].call(this, paramMock.paramObjectMock); 436 } 437 } 438 }, 439 isNewCallAllowed: function (...args) { 440 console.warn("telephony.call.isNewCallAllowed interface mocked in the Previewer. How this interface works on the Previewer may" + 441 " be different from that on a real device.") 442 const len = args.length 443 if (typeof args[len - 1] === 'function') { 444 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 445 } else { 446 return new Promise((resolve, reject) => { 447 resolve(paramMock.paramBooleanMock); 448 }) 449 } 450 }, 451 separateConference: function (...args) { 452 console.warn("telephony.call.separateConference interface mocked in the Previewer. How this interface works on the Previewer may" + 453 " be different from that on a real device.") 454 const len = args.length 455 if (typeof args[len - 1] === 'function') { 456 args[len - 1].call(this, paramMock.businessErrorMock); 457 } else { 458 return new Promise((resolve, reject) => { 459 resolve(); 460 }) 461 } 462 }, 463 getCallRestrictionStatus: function (...args) { 464 console.warn("telephony.call.getCallRestrictionStatus interface mocked in the Previewer. How this interface works on the Previewer may" + 465 " be different from that on a real device.") 466 const len = args.length 467 if (typeof args[len - 1] === 'function') { 468 args[len - 1].call(this, paramMock.businessErrorMock, RestrictionStatus); 469 } else { 470 return new Promise((resolve, reject) => { 471 resolve(RestrictionStatus); 472 }) 473 } 474 }, 475 setCallRestriction: function (...args) { 476 console.warn("telephony.call.setCallRestriction interface mocked in the Previewer. How this interface works on the Previewer may" + 477 " be different from that on a real device.") 478 const len = args.length 479 if (typeof args[len - 1] === 'function') { 480 args[len - 1].call(this, paramMock.businessErrorMock); 481 } else { 482 return new Promise((resolve, reject) => { 483 resolve(); 484 }) 485 } 486 }, 487 setCallTransfer: function (...args) { 488 console.warn("telephony.call.setCallTransfer interface mocked in the Previewer. How this interface works on the Previewer may" + 489 " be different from that on a real device.") 490 const len = args.length 491 if (typeof args[len - 1] === 'function') { 492 args[len - 1].call(this, paramMock.businessErrorMock); 493 } else { 494 return new Promise((resolve, reject) => { 495 resolve(); 496 }) 497 } 498 }, 499 getCallTransferInfo: function (...args) { 500 console.warn("telephony.call.getCallTransferInfo interface mocked in the Previewer. How this interface works on the Previewer may" + 501 " be different from that on a real device.") 502 const len = args.length 503 if (typeof args[len - 1] === 'function') { 504 args[len - 1].call(this, paramMock.businessErrorMock, CallTransferResult); 505 } else { 506 return new Promise((resolve, reject) => { 507 resolve(CallTransferResult); 508 }) 509 } 510 }, 511 setCallTransferInfo: function (...args) { 512 console.warn("telephony.call.setCallTransferInfo interface mocked in the Previewer. How this interface works on the Previewer may" + 513 " be different from that on a real device.") 514 const len = args.length 515 if (typeof args[len - 1] === 'function') { 516 args[len - 1].call(this, paramMock.businessErrorMock); 517 } else { 518 return new Promise((resolve, reject) => { 519 resolve(); 520 }) 521 } 522 }, 523 isRinging: function (...args) { 524 console.warn("telephony.call.isRinging interface mocked in the Previewer. How this interface works on the Previewer may" + 525 " be different from that on a real device.") 526 const len = args.length 527 if (typeof args[len - 1] === 'function') { 528 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 529 } else { 530 return new Promise((resolve, reject) => { 531 resolve(paramMock.paramBooleanMock); 532 }) 533 } 534 }, 535 setMuted: function (...args) { 536 console.warn("telephony.call.setMuted interface mocked in the Previewer. How this interface works on the Previewer may" + 537 " be different from that on a real device.") 538 const len = args.length 539 if (typeof args[len - 1] === 'function') { 540 args[len - 1].call(this, paramMock.businessErrorMock); 541 } else { 542 return new Promise((resolve, reject) => { 543 resolve(); 544 }) 545 } 546 }, 547 setAudioDevice: function (...args) { 548 console.warn("telephony.call.setAudioDevice interface mocked in the Previewer. How this interface works on the Previewer may" + 549 " be different from that on a real device.") 550 const len = args.length 551 if (typeof args[len - 1] === 'function') { 552 args[len - 1].call(this, paramMock.businessErrorMock); 553 } else { 554 return new Promise((resolve, reject) => { 555 resolve(); 556 }) 557 } 558 } 559 } 560 return call 561}