1/* 2 * Copyright (c) 2023-2024 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 16if (!('finalizeConstruction' in ViewPU.prototype)) { 17 Reflect.set(ViewPU.prototype, 'finalizeConstruction', () => { }); 18} 19 20const TAG = 'avcastpicker_component '; 21 22export let AVCastPickerState; 23(function(l11) { 24 l11[l11.STATE_APPEARING = 0] = 'STATE_APPEARING'; 25 l11[l11.STATE_DISAPPEARING = 1] = 'STATE_DISAPPEARING'; 26})(AVCastPickerState || (AVCastPickerState = {})); 27 28export let AVCastPickerStyle; 29(function(k11) { 30 k11[k11.STYLE_PANEL = 0] = 'STYLE_PANEL'; 31 k11[k11.STYLE_MENU = 1] = 'STYLE_MENU'; 32})(AVCastPickerStyle || (AVCastPickerStyle = {})); 33 34export let DeviceSource; 35(function(j11) { 36 j11[j11.LOCAL = 0] = 'LOCAL'; 37 j11[j11.CAST = 1] = 'CAST'; 38})(DeviceSource || (DeviceSource = {})); 39 40export let ConfigurationColorMode; 41(function(u11) { 42 u11[u11.COLOR_MODE_NOT_SET = -1] = 'COLOR_MODE_NOT_SET'; 43 u11[u11.COLOR_MODE_DARK = 0] = 'COLOR_MODE_DARK'; 44 u11[u11.COLOR_MODE_LIGHT = 1] = 'COLOR_MODE_LIGHT'; 45})(ConfigurationColorMode || (ConfigurationColorMode = {})); 46 47export let AVCastPickerColorMode; 48(function(v11) { 49 v11[v11.AUTO = 0] = 'AUTO'; 50 v11[v11.DARK = 1] = 'DARK'; 51 v11[v11.LIGHT = 2] = 'LIGHT'; 52})(AVCastPickerColorMode || (AVCastPickerColorMode = {})); 53 54export class AVCastPicker extends ViewPU { 55 constructor(d11, e11, f11, g11 = -1, h11 = undefined, i11) { 56 super(d11, f11, g11, i11); 57 if (typeof h11 === 'function') { 58 this.paramsGenerator_ = h11; 59 } 60 this.__normalColor = new ObservedPropertySimplePU(undefined, this, 'normalColor'); 61 this.__activeColor = new ObservedPropertySimplePU(undefined, this, 'activeColor'); 62 this.__colorMode = new ObservedPropertySimplePU(AVCastPickerColorMode.AUTO, this, 'colorMode'); 63 this.__deviceList = new ObservedPropertyObjectPU([], this, 'deviceList'); 64 this.__sessionType = new ObservedPropertySimplePU('audio', this, 'sessionType'); 65 this.__pickerStyle = new ObservedPropertySimplePU(AVCastPickerStyle.STYLE_PANEL, this, 'pickerStyle'); 66 this.__pickerStyleFromMediaController = 67 new ObservedPropertySimplePU(AVCastPickerStyle.STYLE_PANEL, this, 'pickerStyleFromMediaController'); 68 this.__isMenuShow = new ObservedPropertySimplePU(false, this, 'isMenuShow'); 69 this.__touchMenuItemIndex = new ObservedPropertySimplePU(-1, this, 'touchMenuItemIndex'); 70 this.onStateChange = undefined; 71 this.extensionProxy = null; 72 this.pickerClickTime = -1; 73 this.customPicker = undefined; 74 this.__configurationColorMode = 75 new ObservedPropertySimplePU(ConfigurationColorMode.COLOR_MODE_NOT_SET, this, 'configurationColorMode'); 76 this.__deviceInfoType = new ObservedPropertySimplePU('', this, 'deviceInfoType'); 77 this.maxFontSizeScale = 2; 78 this.__accessibilityConnectedStr = new ObservedPropertySimplePU('已连接', this, 'accessibilityConnectedStr'); 79 this.__accessibilityAudioControlStr = new ObservedPropertySimplePU('音视频投播', this, 'accessibilityAudioControlStr'); 80 this.setInitiallyProvidedValue(e11); 81 this.declareWatch('isMenuShow', this.MenuStateChange); 82 this.finalizeConstruction(); 83 } 84 85 setInitiallyProvidedValue(c11) { 86 if (c11.normalColor !== undefined) { 87 this.normalColor = c11.normalColor; 88 } 89 if (c11.activeColor !== undefined) { 90 this.activeColor = c11.activeColor; 91 } 92 if (c11.colorMode !== undefined) { 93 this.colorMode = c11.colorMode; 94 } 95 if (c11.deviceList !== undefined) { 96 this.deviceList = c11.deviceList; 97 } 98 if (c11.sessionType !== undefined) { 99 this.sessionType = c11.sessionType; 100 } 101 if (c11.pickerStyle !== undefined) { 102 this.pickerStyle = c11.pickerStyle; 103 } 104 if (c11.pickerStyleFromMediaController !== undefined) { 105 this.pickerStyleFromMediaController = c11.pickerStyleFromMediaController; 106 } 107 if (c11.isMenuShow !== undefined) { 108 this.isMenuShow = c11.isMenuShow; 109 } 110 if (c11.touchMenuItemIndex !== undefined) { 111 this.touchMenuItemIndex = c11.touchMenuItemIndex; 112 } 113 if (c11.onStateChange !== undefined) { 114 this.onStateChange = c11.onStateChange; 115 } 116 if (c11.extensionProxy !== undefined) { 117 this.extensionProxy = c11.extensionProxy; 118 } 119 if (c11.pickerClickTime !== undefined) { 120 this.pickerClickTime = c11.pickerClickTime; 121 } 122 if (c11.customPicker !== undefined) { 123 this.customPicker = c11.customPicker; 124 } 125 if (c11.configurationColorMode !== undefined) { 126 this.configurationColorMode = c11.configurationColorMode; 127 } 128 if (c11.deviceInfoType !== undefined) { 129 this.deviceInfoType = c11.deviceInfoType; 130 } 131 if (c11.maxFontSizeScale !== undefined) { 132 this.maxFontSizeScale = c11.maxFontSizeScale; 133 } 134 if (c11.accessibilityConnectedStr !== undefined) { 135 this.accessibilityConnectedStr = c11.accessibilityConnectedStr; 136 } 137 if (c11.__accessibilityAudioControlStr !== undefined) { 138 this.accessibilityAudioControlStr = c11.accessibilityAudioControlStr; 139 } 140 } 141 142 updateStateVars(b11) { 143 } 144 145 purgeVariableDependenciesOnElmtId(a11) { 146 this.__normalColor.purgeDependencyOnElmtId(a11); 147 this.__activeColor.purgeDependencyOnElmtId(a11); 148 this.__colorMode.purgeDependencyOnElmtId(a11); 149 this.__deviceList.purgeDependencyOnElmtId(a11); 150 this.__sessionType.purgeDependencyOnElmtId(a11); 151 this.__pickerStyle.purgeDependencyOnElmtId(a11); 152 this.__pickerStyleFromMediaController.purgeDependencyOnElmtId(a11); 153 this.__isMenuShow.purgeDependencyOnElmtId(a11); 154 this.__touchMenuItemIndex.purgeDependencyOnElmtId(a11); 155 this.__configurationColorMode.purgeDependencyOnElmtId(a11); 156 this.__deviceInfoType.purgeDependencyOnElmtId(a11); 157 this.__accessibilityConnectedStr.purgeDependencyOnElmtId(a11); 158 this.__accessibilityAudioControlStr.purgeDependencyOnElmtId(a11); 159 } 160 161 aboutToBeDeleted() { 162 this.__normalColor.aboutToBeDeleted(); 163 this.__activeColor.aboutToBeDeleted(); 164 this.__colorMode.aboutToBeDeleted(); 165 this.__deviceList.aboutToBeDeleted(); 166 this.__sessionType.aboutToBeDeleted(); 167 this.__pickerStyle.aboutToBeDeleted(); 168 this.__pickerStyleFromMediaController.aboutToBeDeleted(); 169 this.__isMenuShow.aboutToBeDeleted(); 170 this.__touchMenuItemIndex.aboutToBeDeleted(); 171 this.__configurationColorMode.aboutToBeDeleted(); 172 this.__deviceInfoType.aboutToBeDeleted(); 173 this.__accessibilityConnectedStr.aboutToBeDeleted(); 174 this.__accessibilityAudioControlStr.aboutToBeDeleted(); 175 SubscriberManager.Get().delete(this.id__()); 176 this.aboutToBeDeletedInternal(); 177 } 178 179 get normalColor() { 180 return this.__normalColor.get(); 181 } 182 183 set normalColor(z10) { 184 this.__normalColor.set(z10); 185 } 186 187 get activeColor() { 188 return this.__activeColor.get(); 189 } 190 191 set activeColor(y10) { 192 this.__activeColor.set(y10); 193 } 194 195 get colorMode() { 196 return this.__colorMode.get(); 197 } 198 199 set colorMode(b1) { 200 this.__colorMode.set(b1); 201 } 202 203 get deviceList() { 204 return this.__deviceList.get(); 205 } 206 207 set deviceList(x10) { 208 this.__deviceList.set(x10); 209 } 210 211 get sessionType() { 212 return this.__sessionType.get(); 213 } 214 215 set sessionType(w10) { 216 this.__sessionType.set(w10); 217 } 218 219 get pickerStyle() { 220 return this.__pickerStyle.get(); 221 } 222 223 set pickerStyle(v10) { 224 this.__pickerStyle.set(v10); 225 } 226 227 get pickerStyleFromMediaController() { 228 return this.__pickerStyleFromMediaController.get(); 229 } 230 231 set pickerStyleFromMediaController(b1) { 232 this.__pickerStyleFromMediaController.set(b1); 233 } 234 235 get isMenuShow() { 236 return this.__isMenuShow.get(); 237 } 238 239 set isMenuShow(u10) { 240 this.__isMenuShow.set(u10); 241 } 242 243 get touchMenuItemIndex() { 244 return this.__touchMenuItemIndex.get(); 245 } 246 247 set touchMenuItemIndex(t10) { 248 this.__touchMenuItemIndex.set(t10); 249 } 250 251 get configurationColorMode() { 252 return this.__configurationColorMode.get(); 253 } 254 255 set configurationColorMode(a1) { 256 this.__configurationColorMode.set(a1); 257 } 258 259 get deviceInfoType() { 260 return this.__deviceInfoType.get(); 261 } 262 263 set deviceInfoType(b1) { 264 this.__deviceInfoType.set(b1); 265 } 266 267 get accessibilityConnectedStr() { 268 return this.__accessibilityConnectedStr.get(); 269 } 270 271 set accessibilityConnectedStr(c1) { 272 this.__accessibilityConnectedStr.set(c1); 273 } 274 275 get accessibilityAudioControlStr() { 276 return this.__accessibilityAudioControlStr.get(); 277 } 278 279 set accessibilityAudioControlStr(d1) { 280 this.__accessibilityAudioControlStr.set(d1); 281 } 282 283 MenuStateChange() { 284 if (this.extensionProxy != null) { 285 this.extensionProxy.send({ 'isMenuShow': this.isMenuShow }); 286 } 287 } 288 289 initialRender() { 290 this.observeComponentCreation2((r10, s10) => { 291 Column.create(); 292 Column.size({ width: '100%', height: '100%'}); 293 }, Column); 294 this.observeComponentCreation2((n10, o10) => { 295 If.create(); 296 if (this.customPicker === undefined) { 297 this.ifElseBranchUpdateFunction(0, () => { 298 this.buildDefaultPicker.bind(this)(false); 299 }); 300 } else { 301 this.ifElseBranchUpdateFunction(1, () => { 302 this.buildCustomPicker.bind(this)(); 303 }); 304 } 305 }, If); 306 If.pop(); 307 Column.pop(); 308 } 309 310 buildIcon(b3, c3, d3 = null) { 311 this.observeComponentCreation2((f3, g3) => { 312 If.create(); 313 if (this.deviceInfoType === 'true') { 314 this.ifElseBranchUpdateFunction(0, () => { 315 this.observeComponentCreation2((n3, o3) => { 316 SymbolGlyph.create(!c3 ? { 'id': -1, 'type': -1, params: [b3.deviceIconName], 317 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } : 318 { 'id': -1, 'type': -1, params: [b3.selectedIconName], 319 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 320 SymbolGlyph.fontSize('24vp'); 321 SymbolGlyph.fontColor((c3 && this.configurationColorMode !== 322 ConfigurationColorMode.COLOR_MODE_DARK) ? 323 [{ 'id': -1, 'type': 10001, params: ['sys.color.comp_background_emphasize'], 324 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }] : 325 [{ 'id': -1, 'type': 10001, params: ['sys.color.icon_primary'], 326 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }]); 327 SymbolGlyph.renderingStrategy(2); 328 }, SymbolGlyph); 329 }); 330 } else { 331 this.ifElseBranchUpdateFunction(1, () => { 332 this.observeComponentCreation2((j3, k3) => { 333 Image.create(!c3 ? { 'id': -1, 'type': -1, 334 params: [b3.deviceIconName], 'bundleName': '__harDefaultBundleName__', 335 'moduleName': '__harDefaultModuleName__' } : { 'id': -1, 'type': -1, params: [b3.selectedIconName], 336 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 337 Image.width(24); 338 Image.height(24); 339 Image.fillColor((c3 && this.configurationColorMode !== ConfigurationColorMode.COLOR_MODE_DARK) ? 340 { 'id': -1, 'type': 10001, params: ['sys.color.comp_background_emphasize'], 341 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } : 342 { 'id': -1, 'type': 10001, params: ['sys.color.icon_primary'], 343 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 344 }, Image); 345 }); 346 } 347 }, If); 348 If.pop(); 349 } 350 351 deviceMenu(o8 = null) { 352 this.observeComponentCreation2((j10, k10) => { 353 Column.create(); 354 Column.width(216); 355 }, Column); 356 this.observeComponentCreation2((r8, s8) => { 357 ForEach.create(); 358 const t8 = (v8, w8) => { 359 const x8 = v8; 360 this.observeComponentCreation2((g10, h10) => { 361 Flex.create({ 362 direction: FlexDirection.Column, 363 justifyContent: FlexAlign.SpaceBetween, 364 alignItems: ItemAlign.End 365 }); 366 Flex.width('100%'); 367 Flex.onClick(() => { 368 if (this.extensionProxy != null && !x8.isConnected) { 369 this.extensionProxy.send({ 'selectedDeviceInfo': x8 }); 370 } 371 }); 372 }, Flex); 373 this.observeComponentCreation2((c10, d10) => { 374 Flex.create({ 375 direction: FlexDirection.Row, 376 justifyContent: FlexAlign.SpaceBetween, 377 alignItems: ItemAlign.Center 378 }); 379 Flex.constraintSize({ minHeight: 48 }); 380 Flex.padding({ left: 12, right: 12 }); 381 Flex.onTouch((f10) => { 382 if (f10.type === TouchType.Down) { 383 this.touchMenuItemIndex = w8; 384 } 385 else if (f10.type === TouchType.Up) { 386 this.touchMenuItemIndex = -1; 387 } 388 }); 389 Flex.backgroundColor(this.touchMenuItemIndex === w8 ? { 'id': -1, 'type': 10001, 390 params: ['sys.color.interactive_click'], 'bundleName': '__harDefaultModuleName__', 391 'moduleName': '__harDefaultModuleName__' } : '#00FFFFFF'); 392 Flex.borderRadius(this.touchMenuItemIndex === w8 ? { 'id': -1, 'type': 10002, 393 params: ['sys.float.corner_radius_level8'], 'bundleName': '__harDefaultModuleName__', 394 'moduleName': '__harDefaultModuleName__' } : 0); 395 }, Flex); 396 this.observeComponentCreation2((a10, b10) => { 397 Row.create(); 398 Row.justifyContent(FlexAlign.Start); 399 Row.alignItems(VerticalAlign.Center); 400 }, Row); 401 this.buildIcon.bind(this)(x8, false); 402 this.observeComponentCreation2((w9, x9) => { 403 Text.create(x8.deviceName); 404 Text.fontSize({ 'id': -1, 'type': 10002, 405 params: ['sys.float.ohos_id_text_size_body2'], 'bundleName': '__harDefaultModuleName__', 406 'moduleName': '__harDefaultModuleName__' }); 407 Text.fontColor(x8.isConnected ? 408 (this.configurationColorMode !== ConfigurationColorMode.COLOR_MODE_DARK ? 409 { 'id': -1, 'type': 10001, params: ['sys.color.comp_background_emphasize'], 410 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } : 411 { 'id': -1, 'type': 10001, params: ['sys.color.font_primary'], 412 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }) : 413 (this.configurationColorMode !== ConfigurationColorMode.COLOR_MODE_DARK ? 414 { 'id': -1, 'type': 10001, params: ['sys.color.font_primary'], 415 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' } : 416 { 'id': -1, 'type': 10001, params: ['sys.color.font_secondary'], 417 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' })); 418 Text.width(144); 419 Text.padding({ 420 left: 8, 421 top: 12, 422 right: 8, 423 bottom: 12 424 }); 425 Text.textOverflow({ overflow: TextOverflow.Ellipsis }); 426 Text.maxLines(2); 427 Text.wordBreak(WordBreak.BREAK_ALL); 428 Text.maxFontScale(this.maxFontSizeScale); 429 }, Text); 430 Text.pop(); 431 Row.pop(); 432 this.observeComponentCreation2((m9, n9) => { 433 If.create(); 434 if (x8.isConnected && x8.selectedIconName !== null && x8.selectedIconName !== undefined) { 435 this.ifElseBranchUpdateFunction(0, () => { 436 this.observeComponentCreation2((u9, v9) => { 437 Row.create(); 438 Row.justifyContent(FlexAlign.Start); 439 Row.alignItems(VerticalAlign.Center); 440 Row.accessibilityLevel('yes'); 441 Row.accessibilityText(this.accessibilityConnectedStr); 442 }, Row); 443 this.buildIcon.bind(this)(x8, true); 444 Row.pop(); 445 }); 446 } else { 447 this.ifElseBranchUpdateFunction(1, () => { 448 }); 449 } 450 }, If); 451 If.pop(); 452 Flex.pop(); 453 this.observeComponentCreation2((f9, g9) => { 454 If.create(); 455 if (w8 !== this.deviceList.length - 1) { 456 this.ifElseBranchUpdateFunction(0, () => { 457 this.observeComponentCreation2((k9, l9) => { 458 Divider.create(); 459 Divider.height(1); 460 Divider.width(172); 461 Divider.color({ 'id': -1, 'type': 10001, params: ['sys.color.comp_divider'], 462 'bundleName': '__harDefaultBundleName__', 'moduleName': '__harDefaultModuleName__' }); 463 Divider.padding({ right: 12 }); 464 }, Divider); 465 }); 466 } 467 else { 468 this.ifElseBranchUpdateFunction(1, () => { 469 }); 470 } 471 }, If); 472 If.pop(); 473 Flex.pop(); 474 }; 475 this.forEachUpdateFunction(r8, this.deviceList, t8, undefined, true, false); 476 }, ForEach); 477 ForEach.pop(); 478 Column.pop(); 479 } 480 481 buildDefaultPicker(c8, d8 = null) { 482 this.observeComponentCreation2((f8, g8) => { 483 UIExtensionComponent.create({ 484 abilityName: 'UIExtAbility', 485 bundleName: 'com.hmos.mediacontroller', 486 parameters: { 487 'normalColor': this.normalColor, 488 'activeColor': this.activeColor, 489 'pickerColorMode': this.colorMode, 490 'avCastPickerStyle': this.pickerStyle, 491 'ability.want.params.uiExtensionType': 'sysPicker/mediaControl', 492 'isCustomPicker': c8, 493 } 494 }); 495 UIExtensionComponent.onRemoteReady((n8) => { 496 console.info(TAG, 'onRemoteReady'); 497 this.extensionProxy = n8; 498 }); 499 UIExtensionComponent.onReceive((l8) => { 500 if (JSON.stringify(l8.deviceInfoType) !== undefined) { 501 console.info(TAG, `deviceInfoType : ${JSON.stringify(l8.deviceInfoType)}`); 502 this.deviceInfoType = l8.deviceInfoType; 503 } 504 505 if (JSON.stringify(l8.pickerStyle) !== undefined) { 506 console.info(TAG, `picker style : ${JSON.stringify(l8.pickerStyle)}`); 507 this.pickerStyleFromMediaController = l8.pickerStyle; 508 } 509 510 if (JSON.stringify(l8.deviceList) !== undefined) { 511 console.info(TAG, `picker device list : ${JSON.stringify(l8.deviceList)}`); 512 this.deviceList = JSON.parse(JSON.stringify(l8.deviceList)); 513 let u = this.deviceList.length === 2 && !this.hasExtDevice(ObservedObject.GetRawObject(this.deviceList)); 514 let v = this.deviceList === null || this.deviceList.length === 0; 515 let w = this.sessionType === 'voice_call' || this.sessionType === 'video_call'; 516 let x = w && (v || u); 517 let b21 = !w && (this.pickerStyle === AVCastPickerStyle.STYLE_PANEL && 518 this.pickerStyleFromMediaController === AVCastPickerStyle.STYLE_PANEL); 519 if (x || b21) { 520 this.isMenuShow = false; 521 } 522 } 523 524 if (JSON.stringify(l8.state) !== undefined) { 525 console.info(TAG, `picker state change : ${JSON.stringify(l8.state)}`); 526 let w = this.sessionType === 'voice_call' || this.sessionType === 'video_call'; 527 let b21 = !w && (this.pickerStyle === AVCastPickerStyle.STYLE_PANEL && 528 this.pickerStyleFromMediaController === AVCastPickerStyle.STYLE_PANEL); 529 if (this.onStateChange != null && b21) { 530 if (parseInt(JSON.stringify(l8.state)) === AVCastPickerState.STATE_APPEARING) { 531 this.onStateChange(AVCastPickerState.STATE_APPEARING); 532 } 533 else { 534 this.onStateChange(AVCastPickerState.STATE_DISAPPEARING); 535 } 536 } 537 } 538 539 if (JSON.stringify(l8.sessionType) !== undefined) { 540 console.info(TAG, `session type : ${JSON.stringify(l8.sessionType)}`); 541 this.sessionType = l8.sessionType; 542 } 543 544 if (JSON.stringify(l8.isShowMenu) !== undefined) { 545 console.info(TAG, `isShowMenu : ${l8.isShowMenu}`); 546 this.isMenuShow = l8.isShowMenu; 547 } 548 549 if (JSON.stringify(l8.configurationColorMode) !== undefined) { 550 console.info(TAG, `configurationColorMode : ${l8.configurationColorMode}`); 551 this.configurationColorMode = l8.configurationColorMode; 552 } 553 554 if (JSON.stringify(l8.accessConnected) !== undefined) { 555 console.info(TAG, `accessibilityConnectedStr : ${l8.accessConnected}`); 556 this.accessibilityConnectedStr = l8.accessConnected; 557 } 558 559 560 if (JSON.stringify(l8.accessAudioControl) !== undefined) { 561 console.info(TAG, `accessibilityAudioControlStr : ${l8.accessAudioControl}`); 562 this.accessibilityAudioControlStr = l8.accessAudioControl; 563 } 564 }); 565 UIExtensionComponent.size({ width: '100%', height: '100%' }); 566 UIExtensionComponent.bindMenu(this.isMenuShow, { builder: () => { this.deviceMenu.call(this); }}, { 567 placement: Placement.TopRight, 568 onDisappear: () => { 569 this.isMenuShow = false; 570 this.menuShowStateCallback(this.isMenuShow); 571 }, 572 onAppear: () => { 573 if (this.extensionProxy != null && this.pickerClickTime !== -1) { 574 this.extensionProxy.send({ 'timeCost': new Date().getTime() - this.pickerClickTime }); 575 this.pickerClickTime = -1; 576 } 577 this.menuShowStateCallback(this.isMenuShow); 578 } 579 }); 580 UIExtensionComponent.onClick(() => { 581 let u = this.deviceList.length === 2 && 582 !this.hasExtDevice(ObservedObject.GetRawObject(this.deviceList)); 583 let v = this.deviceList === null || this.deviceList.length === 0; 584 let w = this.sessionType === 'voice_call' || this.sessionType === 'video_call'; 585 let x = w && (v || u); 586 let y = !w && (this.pickerStyle === AVCastPickerStyle.STYLE_PANEL && 587 this.pickerStyleFromMediaController === AVCastPickerStyle.STYLE_PANEL); 588 if (x || y) { 589 this.isMenuShow = false; 590 if (this.extensionProxy != null) { 591 this.extensionProxy.send({'clickEvent': true}); 592 } 593 } else { 594 this.isMenuShow = !this.isMenuShow; 595 if (this.isMenuShow) { 596 this.pickerClickTime = new Date().getTime(); 597 } 598 } 599 }); 600 UIExtensionComponent.accessibilityLevel('yes'); 601 UIExtensionComponent.accessibilityText(this.__accessibilityAudioControlStr); 602 }, UIExtensionComponent); 603 } 604 605 hasExtDevice(a) { 606 for (let b = 0; b < a.length; b++) { 607 if (a[b].deviceType !== 1 && // 1 is audio.DeviceType.EARPIECE 608 a[b].deviceType !== 2) { // 2 is audio.DeviceType.SPEAKER 609 return true; 610 } 611 } 612 return false; 613 } 614 615 menuShowStateCallback(k) { 616 if (this.onStateChange != null && (this.pickerStyle === AVCastPickerStyle.STYLE_MENU || 617 this.pickerStyleFromMediaController === AVCastPickerStyle.STYLE_MENU)) { 618 let l = k ? AVCastPickerState.STATE_APPEARING : AVCastPickerState.STATE_DISAPPEARING; 619 this.onStateChange(l); 620 } 621 } 622 623 buildCustomPicker(s7 = null) { 624 this.observeComponentCreation2((a8, b8) => { 625 Stack.create({ alignContent: Alignment.Center}); 626 Stack.size({ width: '100%', height: '100%' }); 627 }, Stack); 628 this.observeComponentCreation2((y7, z7) => { 629 Column.create(); 630 Column.alignItems(HorizontalAlign.Center); 631 Column.justifyContent(FlexAlign.Center); 632 Column.size({ width: '100%', height: '100%' }); 633 Column.zIndex(0); 634 }, Column); 635 this.customPicker.bind(this)(); 636 Column.pop(); 637 this.observeComponentCreation2((w7, x7) => { 638 Column.create(); 639 Column.alignItems(HorizontalAlign.Center); 640 Column.justifyContent(FlexAlign.Center); 641 Column.size({ width: '100%', height: '100%' }); 642 Column.zIndex(1); 643 }, Column); 644 this.buildDefaultPicker.bind(this)(true); 645 Column.pop(); 646 Stack.pop(); 647 } 648 649 rerender() { 650 this.updateDirtyElements(); 651 } 652 653 static getEntryName() { 654 return 'AVCastPicker'; 655 } 656} 657 658export default AVCastPicker;