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 mockMultimediaAVSession() { 19 const AVMetadata = { 20 assetId: "[PC Preview] unknow assetId", 21 title: "[PC Preview] unknow title", 22 artist: "[PC Preview] unknow artist", 23 author: "[PC Preview] unknow author", 24 album: "[PC Preview] unknow album", 25 writer: "[PC Preview] unknow writer", 26 composer: "[PC Preview] unknow composer", 27 duration: "[PC Preview] unknow duration", 28 mediaImage: "[PC Preview] unknow mediaImage", 29 publishDate: "[PC Preview] unknow publishDate", 30 subtitle: "[PC Preview] unknow subtitle", 31 description: "[PC Preview] unknow description", 32 lyric: "[PC Preview] unknow lyric", 33 previousAssetId: "[PC Preview] unknow previousAssetId", 34 nextAssetId: "[PC Preview] unknow nextAssetId" 35 } 36 37 const AVPlaybackState = { 38 state: "[PC Preview] unknow state", 39 speed: "[PC Preview] unknow speed", 40 position: PlaybackPosition, 41 bufferedTime: "[PC Preview] unknow bufferedTime", 42 loopMode: "[PC Preview] unknow loopMode", 43 isFavorite: "[PC Preview] unknow isFavorite" 44 } 45 46 const PlaybackPosition = { 47 elapsedTime: "[PC Preview] unknow elapsedTime", 48 updateTime: "[PC Preview] unknow updateTime" 49 } 50 51 const OutputDeviceInfo = { 52 isRemote: "[PC Preview] unknow isRemote", 53 deviceId: [paramMock.paramStringMock], 54 deviceName: [paramMock.paramStringMock] 55 } 56 57 const AVSessionDescriptor = { 58 sessionId: "[PC Preview] unknow sessionId", 59 type: "[PC Preview] unknow type", 60 sessionTag: "[PC Preview] unknow sessionTag", 61 elementName: "[PC Preview] unknow elementName", 62 isActive: "[PC Preview] unknow isActive", 63 isTopSession: "[PC Preview] unknow isTopSession", 64 outputDevice: 65 "[PC Preview] unknow outputDevice" 66 } 67 68 const AVControlCommandType = ['play', 'pause', 'stop', 'playNext', 'playPrevious', 'fastForward', 'rewind', 'seek', 'setSpeed', 'setLoopMode', 'toggleFavorite']; 69 70 const AVSession = { 71 sessionId: "[PC Preview] unknow sessionId", 72 setAVMetadata: function (...args) { 73 console.warn("AVSession.setAVMetadata interface mocked in the Previewer. How this interface works on the Previewer" + 74 " may be different from that on a real device.") 75 const len = args.length 76 if (typeof args[len - 1] === 'function') { 77 args[len - 1].call(this, paramMock.businessErrorMock); 78 } else { 79 return new Promise((resolve, reject) => { 80 resolve(); 81 }) 82 } 83 }, 84 setAVPlaybackState: function (...args) { 85 console.warn("AVSession.setAVPlaybackState interface mocked in the Previewer. How this interface works on the Previewer" + 86 " may be different from that on a real device.") 87 const len = args.length 88 if (typeof args[len - 1] === 'function') { 89 args[len - 1].call(this, paramMock.businessErrorMock); 90 } else { 91 return new Promise((resolve, reject) => { 92 resolve(); 93 }) 94 } 95 }, 96 setLaunchAbility: function (...args) { 97 console.warn("AVSession.setLaunchAbility interface mocked in the Previewer. How this interface works on the Previewer" + 98 " may be different from that on a real device.") 99 const len = args.length 100 if (typeof args[len - 1] === 'function') { 101 args[len - 1].call(this, paramMock.businessErrorMock); 102 } else { 103 return new Promise((resolve, reject) => { 104 resolve(); 105 }) 106 } 107 }, 108 setAudioStreamId: function (...args) { 109 console.warn("AVSession.setAudioStreamId interface mocked in the Previewer. How this interface works on the Previewer" + 110 " may be different from that on a real device.") 111 const len = args.length 112 if (typeof args[len - 1] === 'function') { 113 args[len - 1].call(this, paramMock.businessErrorMock); 114 } else { 115 return new Promise((resolve, reject) => { 116 resolve(); 117 }) 118 } 119 }, 120 getController: function (...args) { 121 console.warn("AVSession.getController interface mocked in the Previewer. How this interface works on the Previewer" + 122 " 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, AVSessionController); 126 } else { 127 return new Promise((resolve, reject) => { 128 resolve(AVSessionController); 129 }) 130 } 131 }, 132 getOutputDevice: function (...args) { 133 console.warn("AVSession.getOutputDevice interface mocked in the Previewer. How this interface works on the Previewer" + 134 " 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, OutputDeviceInfo); 138 } else { 139 return new Promise((resolve, reject) => { 140 resolve(OutputDeviceInfo); 141 }) 142 } 143 }, 144 on: function (...args) { 145 console.warn("AVSession.on interface mocked in the Previewer. How this interface works on the Previewer" + 146 " may be different from that on a real device.") 147 const len = args.length 148 if (args[0] == 'play' || args[0] == 'pause' ||args[0] == 'stop' ||args[0] == 'playNext' 149 ||args[0] == 'playPrevious' ||args[0] == 'fastForward' ||args[0] == 'rewind') { 150 args[len - 1].call(this); 151 } else if(args[0] == 'seek' || args[0] == 'setSpeed') { 152 args[len - 1].call(this, paramMock.paramNumberMock); 153 } else if(args[0] == 'setLoopMode') { 154 var loopMode = "[PC Preview] unknow LoopMode"; 155 args[len - 1].call(this, loopMode); 156 } else if(args[0] == 'toggleFavorite') { 157 args[len - 1].call(this, paramMock.paramStringMock); 158 } else if(args[0] == 'handleKeyEvent') { 159 args[len - 1].call(this, paramMock.paramObjectMock); 160 } else if(args[0] == 'outputDeviceChanged') { 161 args[len - 1].call(this, OutputDeviceInfo); 162 } 163 }, 164 off: function (...args) { 165 console.warn("AVSession.off interface mocked in the Previewer. How this interface works on the Previewer" + 166 " may be different from that on a real device.") 167 }, 168 activate: function (...args) { 169 console.warn("AVSession.activate interface mocked in the Previewer. How this interface works on the Previewer" + 170 " 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, reject) => { 176 resolve(); 177 }) 178 } 179 }, 180 deactivate: function (...args) { 181 console.warn("AVSession.deactivate interface mocked in the Previewer. How this interface works on the Previewer" + 182 " 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); 186 } else { 187 return new Promise((resolve, reject) => { 188 resolve(); 189 }) 190 } 191 }, 192 destroy: function (...args) { 193 console.warn("AVSession.destroy interface mocked in the Previewer. How this interface works on the Previewer" + 194 " 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); 198 } else { 199 return new Promise((resolve, reject) => { 200 resolve(); 201 }) 202 } 203 } 204 } 205 206 const AVSessionController = { 207 sessionId: "[PC Preview] unknow sessionId", 208 getAVPlaybackState: function (...args) { 209 console.warn("AVSessionController.getAVPlaybackState interface mocked in the Previewer. How this interface works on the Previewer" + 210 " may be different from that on a real device.") 211 const len = args.length 212 if (typeof args[len - 1] === 'function') { 213 args[len - 1].call(this, paramMock.businessErrorMock, AVPlaybackState); 214 } else { 215 return new Promise((resolve, reject) => { 216 resolve(AVPlaybackState); 217 }) 218 } 219 }, 220 getAVMetadata: function (...args) { 221 console.warn("AVSessionController.getAVMetadata interface mocked in the Previewer. How this interface works on the Previewer" + 222 " may be different from that on a real device.") 223 const len = args.length 224 if (typeof args[len - 1] === 'function') { 225 args[len - 1].call(this, paramMock.businessErrorMock, AVMetadata); 226 } else { 227 return new Promise((resolve, reject) => { 228 resolve(AVMetadata); 229 }) 230 } 231 }, 232 getOutputDevice: function (...args) { 233 console.warn("AVSessionController.getOutputDevice interface mocked in the Previewer. How this interface works on the Previewer" + 234 " may be different from that on a real device.") 235 const len = args.length 236 if (typeof args[len - 1] === 'function') { 237 args[len - 1].call(this, paramMock.businessErrorMock, OutputDeviceInfo); 238 } else { 239 return new Promise((resolve, reject) => { 240 resolve(OutputDeviceInfo); 241 }) 242 } 243 }, 244 sendAVKeyEvent: function (...args) { 245 console.warn("AVSessionController.sendAVKeyEvent interface mocked in the Previewer. How this interface works on the Previewer" + 246 " may be different from that on a real device.") 247 const len = args.length 248 if (typeof args[len - 1] === 'function') { 249 args[len - 1].call(this, paramMock.businessErrorMock); 250 } else { 251 return new Promise((resolve, reject) => { 252 resolve(); 253 }) 254 } 255 }, 256 getLaunchAbility: function (...args) { 257 console.warn("AVSessionController.getLaunchAbility interface mocked in the Previewer. How this interface works on the Previewer" + 258 " may be different from that on a real device.") 259 const len = args.length 260 if (typeof args[len - 1] === 'function') { 261 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); 262 } else { 263 return new Promise((resolve, reject) => { 264 resolve(paramMock.paramObjectMock); 265 }) 266 } 267 }, 268 getRealPlaybackPositionSync: function (...args) { 269 console.warn("AVSessionController.getRealPlaybackPositionSync interface mocked in the Previewer. How this interface works on the Previewer" + 270 " may be different from that on a real device.") 271 return paramMock.paramNumberMock; 272 }, 273 isActive: function (...args) { 274 console.warn("AVSessionController.isActive interface mocked in the Previewer. How this interface works on the Previewer" + 275 " may be different from that on a real device.") 276 const len = args.length 277 if (typeof args[len - 1] === 'function') { 278 args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramBooleanMock); 279 } else { 280 return new Promise((resolve, reject) => { 281 resolve(paramMock.paramBooleanMock); 282 }) 283 } 284 }, 285 destroy: function (...args) { 286 console.warn("AVSessionController.destroy interface mocked in the Previewer. How this interface works on the Previewer" + 287 " may be different from that on a real device.") 288 const len = args.length 289 if (typeof args[len - 1] === 'function') { 290 args[len - 1].call(this, paramMock.businessErrorMock); 291 } else { 292 return new Promise((resolve, reject) => { 293 resolve(); 294 }) 295 } 296 }, 297 getValidCommands: function (...args) { 298 console.warn("AVSessionController.getValidCommands interface mocked in the Previewer. How this interface works on the Previewer" + 299 " may be different from that on a real device.") 300 const len = args.length 301 if (typeof args[len - 1] === 'function') { 302 args[len - 1].call(this, paramMock.businessErrorMock, AVControlCommandType); 303 } else { 304 return new Promise((resolve, reject) => { 305 resolve(AVControlCommandType); 306 }) 307 } 308 }, 309 sendControlCommand: function (...args) { 310 console.warn("AVSessionController.sendControlCommand interface mocked in the Previewer. How this interface works on the Previewer" + 311 " may be different from that on a real device.") 312 const len = args.length 313 if (typeof args[len - 1] === 'function') { 314 args[len - 1].call(this, paramMock.businessErrorMock); 315 } else { 316 return new Promise((resolve, reject) => { 317 resolve(); 318 }) 319 } 320 }, 321 on: function (...args) { 322 console.warn("AVSessionController.on interface mocked in the Previewer. How this interface works on the Previewer" + 323 " may be different from that on a real device.") 324 const len = args.length 325 if (args[0] == 'metadataChanged') { 326 args[len-1].call(this, AVMetadata); 327 } else if (args[0] == 'playbackStateChanged') { 328 args[len-1].call(this, AVPlaybackState); 329 } else if (args[0] == 'sessionDestroyed') { 330 args[len-1].call(this); 331 } else if (args[0] == 'activeStateChanged') { 332 args[len-1].call(this, paramMock.paramBooleanMock); 333 } else if (args[0] == 'validCommandChanged') { 334 args[len-1].call(this, AVControlCommandType); 335 } else if (args[0] == 'outputDeviceChanged') { 336 args[len-1].call(this, OutputDeviceInfo); 337 } 338 }, 339 off: function (...args) { 340 console.warn("AVSessionController.off interface mocked in the Previewer. How this interface works on the Previewer" + 341 " may be different from that on a real device.") 342 } 343 } 344 345 const avsession = { 346 createAVSession: function (...args) { 347 console.warn("AVSession.createAVSession interface mocked in the Previewer. How this interface works on the Previewer" + 348 " may be different from that on a real device.") 349 const len = args.length 350 if (typeof args[len - 1] === 'function') { 351 args[len - 1].call(this, paramMock.businessErrorMock, AVSession); 352 } else { 353 return new Promise((resolve, reject) => { 354 resolve(AVSession); 355 }) 356 } 357 358 }, 359 getAllSessionDescriptors: function (...args) { 360 console.warn("AVSession.getAllSessionDescriptors interface mocked in the Previewer. How this interface works on the Previewer" + 361 " may be different from that on a real device.") 362 const len = args.length 363 var desArr = Array(AVSessionDescriptor); 364 if (typeof args[len - 1] === 'function') { 365 args[len - 1].call(this, paramMock.businessErrorMock, desArr); 366 } else { 367 return new Promise((resolve, reject) => { 368 resolve(desArr); 369 }) 370 } 371 }, 372 createController: function (...args) { 373 console.warn("AVSession.createController interface mocked in the Previewer. How this interface works on the Previewer" + 374 " may be different from that on a real device.") 375 const len = args.length 376 if (typeof args[len - 1] === 'function') { 377 args[len - 1].call(this, paramMock.businessErrorMock, AVSessionController); 378 } else { 379 return new Promise((resolve, reject) => { 380 resolve(AVSessionController); 381 }) 382 } 383 }, 384 castAudio: function (...args) { 385 console.warn("AVSession.castAudio interface mocked in the Previewer. How this interface works on the Previewer" + 386 " 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, reject) => { 392 resolve(); 393 }) 394 } 395 }, 396 on: function (...args) { 397 console.warn("AVSession.on interface mocked in the Previewer. How this interface works on the Previewer" + 398 " may be different from that on a real device.") 399 const len = args.length 400 if (args[0] == 'sessionCreated' || args[0] == 'sessionDestroyed' || args[0] == 'topSessionChanged') { 401 args[len - 1].call(this, AVSessionDescriptor); 402 } else if (args[0] == 'sessionServiceDied') { 403 args[len - 1].call(this); 404 } 405 }, 406 off: function (...args) { 407 console.warn("AVSession.off interface mocked in the Previewer. How this interface works on the Previewer" + 408 " may be different from that on a real device.") 409 }, 410 sendSystemAVKeyEvent: function (...args) { 411 console.warn("AVSession.sendSystemAVKeyEvent interface mocked in the Previewer. How this interface works on the Previewer" + 412 " may be different from that on a real device.") 413 const len = args.length 414 if (typeof args[len - 1] === 'function') { 415 args[len - 1].call(this, paramMock.businessErrorMock); 416 } else { 417 return new Promise((resolve, reject) => { 418 resolve(); 419 }) 420 } 421 }, 422 sendSystemControlCommand: function (...args) { 423 console.warn("AVSession.sendSystemControlCommand interface mocked in the Previewer. How this interface works on the Previewer" + 424 " may be different from that on a real device.") 425 const len = args.length 426 if (typeof args[len - 1] === 'function') { 427 args[len - 1].call(this, paramMock.businessErrorMock); 428 } else { 429 return new Promise((resolve, reject) => { 430 resolve(); 431 }) 432 } 433 } 434 } 435 return avsession 436} 437