• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 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
16const curves = requireNativeModule('ohos.curves');
17const PiPWindow = requireNapi('PiPWindow');
18const pip = requireNapi('pip');
19
20const TAG = "PiPCall";
21const TIMEOUT = 3e3;
22
23export class PiPCall extends ViewPU {
24    constructor(e, t, o, i = -1, n = void 0) {
25        super(e, o, i);
26        "function" == typeof n && (this.paramsGenerator_ = n);
27        this.xComponentId = "pip";
28        this.windowType = PiPWindow.PiPTemplateType.VIDEO_CALL;
29        this.hideEventId = -1;
30        this.__showControl = new ObservedPropertySimplePU(!1, this, "showControl");
31        this.xComponentController = new XComponentController;
32        this.surfaceId = "";
33        this.controlTransEffect = TransitionEffect.OPACITY;
34        this.__hideControlNow = new ObservedPropertySimplePU(!1, this, "hideControlNow");
35        this.addProvidedVar("hideControlNow", this.__hideControlNow);
36        this.__hideControlDelay = new ObservedPropertySimplePU(!1, this, "hideControlDelay");
37        this.addProvidedVar("hideControlDelay", this.__hideControlDelay);
38        this.setInitiallyProvidedValue(t);
39        this.declareWatch("hideControlNow", this.onHideControlNow);
40        this.declareWatch("hideControlDelay", this.onHideControlDelay)
41    }
42
43    setInitiallyProvidedValue(e) {
44        void 0 !== e.xComponentId && (this.xComponentId = e.xComponentId);
45        void 0 !== e.windowType && (this.windowType = e.windowType);
46        void 0 !== e.hideEventId && (this.hideEventId = e.hideEventId);
47        void 0 !== e.showControl && (this.showControl = e.showControl);
48        void 0 !== e.xComponentController && (this.xComponentController = e.xComponentController);
49        void 0 !== e.surfaceId && (this.surfaceId = e.surfaceId);
50        void 0 !== e.controlTransEffect && (this.controlTransEffect = e.controlTransEffect);
51        void 0 !== e.hideControlNow && (this.hideControlNow = e.hideControlNow);
52        void 0 !== e.hideControlDelay && (this.hideControlDelay = e.hideControlDelay)
53    }
54
55    updateStateVars(e) {
56    }
57
58    purgeVariableDependenciesOnElmtId(e) {
59        this.__showControl.purgeDependencyOnElmtId(e);
60        this.__hideControlNow.purgeDependencyOnElmtId(e);
61        this.__hideControlDelay.purgeDependencyOnElmtId(e)
62    }
63
64    aboutToBeDeleted() {
65        this.__showControl.aboutToBeDeleted();
66        this.__hideControlNow.aboutToBeDeleted();
67        this.__hideControlDelay.aboutToBeDeleted();
68        SubscriberManager.Get().delete(this.id__());
69        this.aboutToBeDeletedInternal()
70    }
71
72    get showControl() {
73        return this.__showControl.get()
74    }
75
76    set showControl(e) {
77        this.__showControl.set(e)
78    }
79
80    get hideControlNow() {
81        return this.__hideControlNow.get()
82    }
83
84    set hideControlNow(e) {
85        this.__hideControlNow.set(e)
86    }
87
88    get hideControlDelay() {
89        return this.__hideControlDelay.get()
90    }
91
92    set hideControlDelay(e) {
93        this.__hideControlDelay.set(e)
94    }
95
96    onHideControlNow() {
97        this.hideControlNow && this.switchToHideWithoutAnime();
98        this.hideControlNow = !1
99    }
100
101    onHideControlDelay() {
102        this.hideControlDelay && this.delayHide();
103        this.hideControlDelay = !1
104    }
105
106    switchToShow() {
107        Context.animateTo({ curve: curves.responsiveSpringMotion(0.25, 1) }, (() => {
108            this.showControl = !0
109        }));
110        this.delayHide()
111    }
112
113    switchToHide() {
114        -1 !== this.hideEventId && clearTimeout(this.hideEventId);
115        Context.animateTo({ curve: curves.responsiveSpringMotion(0.25, 1) }, (() => {
116            this.showControl = !1
117        }))
118    }
119
120    switchToHideWithoutAnime() {
121        -1 !== this.hideEventId && clearTimeout(this.hideEventId);
122        this.showControl = !1
123    }
124
125    delayHide() {
126        -1 !== this.hideEventId && clearTimeout(this.hideEventId);
127        this.hideEventId = this.showControl ? setTimeout((() => {
128            Context.animateTo({ curve: curves.responsiveSpringMotion(0.25, 1) }, (() => {
129                this.showControl = !1
130            }))
131        }), 3e3) : -1
132    }
133
134    initialRender() {
135        this.observeComponentCreation2(((e, t) => {
136            Stack.create();
137            Stack.size({ width: "100%", height: "100%" })
138        }), Stack);
139        this.observeComponentCreation2(((e, t) => {
140            XComponent.create({
141                id: this.xComponentId,
142                type: "surface",
143                controller: this.xComponentController
144            }, "pipXComponent");
145            XComponent.onLoad((() => {
146                pip.initXComponentController(this.xComponentController);
147                console.debug(TAG, "XComponent onLoad done")
148            }));
149            XComponent.size({ width: "100%", height: "100%" })
150        }), XComponent);
151        this.observeComponentCreation2(((e, t) => {
152            RelativeContainer.create();
153            RelativeContainer.size({ width: "100%", height: "100%" });
154            RelativeContainer.id("control");
155            Gesture.create(GesturePriority.Low);
156            GestureGroup.create(GestureMode.Exclusive);
157            TapGesture.create({ count: 2 });
158            TapGesture.onAction((e => {
159                this.switchToHideWithoutAnime();
160                pip.processScale()
161            }));
162            TapGesture.pop();
163            TapGesture.create({ count: 1 });
164            TapGesture.onAction((e => {
165                this.showControl ? this.switchToHide() : this.switchToShow()
166            }));
167            TapGesture.pop();
168            PanGesture.create();
169            PanGesture.onActionStart((e => {
170                this.switchToHide();
171                pip.startMove()
172            }));
173            PanGesture.pop();
174            GestureGroup.pop();
175            Gesture.pop()
176        }), RelativeContainer);
177        this.observeComponentCreation2(((e, t) => {
178            Stack.create();
179            Stack.size({ width: "100%", height: "100%" });
180            Stack.id("fill_stack")
181        }), Stack);
182        Stack.pop();
183        this.observeComponentCreation2(((e, t) => {
184            If.create();
185            this.showControl ? this.ifElseBranchUpdateFunction(0, (() => {
186                if (!If.canRetake("control_inner")) {
187                    this.observeComponentCreation2(((e, t) => {
188                        RelativeContainer.create();
189                        RelativeContainer.size({ width: "100%", height: "100%" });
190                        RelativeContainer.transition(this.controlTransEffect);
191                        RelativeContainer.alignRules({
192                            top: { anchor: "__container__", align: VerticalAlign.Top },
193                            right: { anchor: "__container__", align: HorizontalAlign.End }
194                        });
195                        RelativeContainer.id("control_inner")
196                    }), RelativeContainer);
197                    this.observeComponentCreation2(((e, t) => {
198                        if (t) {
199                            let t = () => ({});
200                            ViewPU.create(new DefaultControl(this, {}, void 0, e, t))
201                        } else this.updateStateVarsOfChildByElmtId(e, {})
202                    }), null);
203                    this.observeComponentCreation2(((e, t) => {
204                        if (t) {
205                            let t = () => ({});
206                            ViewPU.create(new CallControl(this, {}, void 0, e, t))
207                        } else this.updateStateVarsOfChildByElmtId(e, {})
208                    }), null);
209                    RelativeContainer.pop()
210                }
211            })) : this.ifElseBranchUpdateFunction(1, (() => {
212            }))
213        }), If);
214        If.pop();
215        RelativeContainer.pop();
216        Stack.pop()
217    }
218
219    rerender() {
220        this.updateDirtyElements()
221    }
222}
223
224class DefaultControl extends ViewPU {
225    constructor(e, t, o, i = -1, n = void 0) {
226        super(e, o, i);
227        "function" == typeof n && (this.paramsGenerator_ = n);
228        this.__hideControlNow = this.initializeConsume("hideControlNow", "hideControlNow");
229        this.setInitiallyProvidedValue(t)
230    }
231
232    setInitiallyProvidedValue(e) {
233    }
234
235    updateStateVars(e) {
236    }
237
238    purgeVariableDependenciesOnElmtId(e) {
239        this.__hideControlNow.purgeDependencyOnElmtId(e)
240    }
241
242    aboutToBeDeleted() {
243        this.__hideControlNow.aboutToBeDeleted();
244        SubscriberManager.Get().delete(this.id__());
245        this.aboutToBeDeletedInternal()
246    }
247
248    get hideControlNow() {
249        return this.__hideControlNow.get()
250    }
251
252    set hideControlNow(e) {
253        this.__hideControlNow.set(e)
254    }
255
256    initialRender() {
257        this.observeComponentCreation2(((e, t) => {
258            RelativeContainer.create();
259            RelativeContainer.width("100%");
260            RelativeContainer.height(48);
261            RelativeContainer.linearGradient({ angle: 180, colors: [["#30000000", 0], ["#00000000", 1]] });
262            RelativeContainer.alignRules({
263                top: { anchor: "__container__", align: VerticalAlign.Top },
264                left: { anchor: "__container__", align: HorizontalAlign.Start }
265            });
266            RelativeContainer.id("default_control")
267        }), RelativeContainer);
268        this.observeComponentCreation2(((e, t) => {
269            Button.createWithChild({ type: ButtonType.Circle });
270            Button.backgroundColor("#00FFFFFF");
271            Button.size({ width: 24, height: 24 });
272            Button.margin(12);
273            Button.alignRules({
274                center: { anchor: "__container__", align: VerticalAlign.Center },
275                left: { anchor: "__container__", align: HorizontalAlign.Start }
276            });
277            Button.id("control_exit");
278            Button.responseRegion({ x: "-50%", y: "-50%", width: "200%", height: "200%" });
279            Button.onClick((() => {
280                this.hideControlNow = !0;
281                pip.close();
282                console.debug(TAG, "action: exit")
283            }))
284        }), Button);
285        this.observeComponentCreation2(((e, t) => {
286            Image.create({
287                id: -1,
288                type: 2e4,
289                params: ["sys.media.ohos_ic_public_close"],
290                bundleName: "",
291                moduleName: ""
292            });
293            Image.size({ width: 24, height: 24 });
294            Image.fillColor({
295                id: -1,
296                type: 10001,
297                params: ["sys.color.ohos_id_color_primary_contrary"],
298                bundleName: "",
299                moduleName: ""
300            });
301            Image.objectFit(ImageFit.Contain)
302        }), Image);
303        Button.pop();
304        this.observeComponentCreation2(((e, t) => {
305            Button.createWithChild({ type: ButtonType.Circle });
306            Button.backgroundColor("#00FFFFFF");
307            Button.size({ width: 24, height: 24 });
308            Button.margin(12);
309            Button.alignRules({
310                center: { anchor: "__container__", align: VerticalAlign.Center },
311                right: { anchor: "__container__", align: HorizontalAlign.End }
312            });
313            Button.id("control_restore");
314            Button.responseRegion({ x: "-50%", y: "-50%", width: "200%", height: "200%" });
315            Button.onClick((() => {
316                this.hideControlNow = !0;
317                pip.restore();
318                console.debug(TAG, "action: restore")
319            }))
320        }), Button);
321        this.observeComponentCreation2(((e, t) => {
322            Image.create({
323                id: -1,
324                type: 2e4,
325                params: ["sys.media.ohos_ic_public_restore"],
326                bundleName: "",
327                moduleName: ""
328            });
329            Image.fillColor({
330                id: -1,
331                type: 10001,
332                params: ["sys.color.ohos_id_color_primary_contrary"],
333                bundleName: "",
334                moduleName: ""
335            });
336            Image.objectFit(ImageFit.Contain)
337        }), Image);
338        Button.pop();
339        RelativeContainer.pop()
340    }
341
342    rerender() {
343        this.updateDirtyElements()
344    }
345}
346
347const sizeArray = [1, 1.5];
348
349class CallControl extends ViewPU {
350    constructor(e, t, o, i = -1, n = void 0) {
351        super(e, o, i);
352        "function" == typeof n && (this.paramsGenerator_ = n);
353        this.__isMute = new ObservedPropertySimplePU(!0, this, "isMute");
354        this.__isRecord = new ObservedPropertySimplePU(!0, this, "isRecord");
355        this.__defaultMargin = new ObservedPropertySimplePU(8, this, "defaultMargin");
356        this.__defaultSize = new ObservedPropertySimplePU(12, this, "defaultSize");
357        this.__defaultBigSize = new ObservedPropertySimplePU(24, this, "defaultBigSize");
358        this.__sizeIndex = new ObservedPropertySimplePU(0, this, "sizeIndex");
359        this.__hideControlDelay = this.initializeConsume("hideControlDelay", "hideControlDelay");
360        this.setInitiallyProvidedValue(t)
361    }
362
363    setInitiallyProvidedValue(e) {
364        void 0 !== e.isMute && (this.isMute = e.isMute);
365        void 0 !== e.isRecord && (this.isRecord = e.isRecord);
366        void 0 !== e.defaultMargin && (this.defaultMargin = e.defaultMargin);
367        void 0 !== e.defaultSize && (this.defaultSize = e.defaultSize);
368        void 0 !== e.defaultBigSize && (this.defaultBigSize = e.defaultBigSize);
369        void 0 !== e.sizeIndex && (this.sizeIndex = e.sizeIndex)
370    }
371
372    updateStateVars(e) {
373    }
374
375    purgeVariableDependenciesOnElmtId(e) {
376        this.__isMute.purgeDependencyOnElmtId(e);
377        this.__isRecord.purgeDependencyOnElmtId(e);
378        this.__defaultMargin.purgeDependencyOnElmtId(e);
379        this.__defaultSize.purgeDependencyOnElmtId(e);
380        this.__defaultBigSize.purgeDependencyOnElmtId(e);
381        this.__sizeIndex.purgeDependencyOnElmtId(e);
382        this.__hideControlDelay.purgeDependencyOnElmtId(e)
383    }
384
385    aboutToBeDeleted() {
386        this.__isMute.aboutToBeDeleted();
387        this.__isRecord.aboutToBeDeleted();
388        this.__defaultMargin.aboutToBeDeleted();
389        this.__defaultSize.aboutToBeDeleted();
390        this.__defaultBigSize.aboutToBeDeleted();
391        this.__sizeIndex.aboutToBeDeleted();
392        this.__hideControlDelay.aboutToBeDeleted();
393        SubscriberManager.Get().delete(this.id__());
394        this.aboutToBeDeletedInternal()
395    }
396
397    get isMute() {
398        return this.__isMute.get()
399    }
400
401    set isMute(e) {
402        this.__isMute.set(e)
403    }
404
405    get isRecord() {
406        return this.__isRecord.get()
407    }
408
409    set isRecord(e) {
410        this.__isRecord.set(e)
411    }
412
413    get defaultMargin() {
414        return this.__defaultMargin.get()
415    }
416
417    set defaultMargin(e) {
418        this.__defaultMargin.set(e)
419    }
420
421    get defaultSize() {
422        return this.__defaultSize.get()
423    }
424
425    set defaultSize(e) {
426        this.__defaultSize.set(e)
427    }
428
429    get defaultBigSize() {
430        return this.__defaultBigSize.get()
431    }
432
433    set defaultBigSize(e) {
434        this.__defaultBigSize.set(e)
435    }
436
437    get sizeIndex() {
438        return this.__sizeIndex.get()
439    }
440
441    set sizeIndex(e) {
442        this.__sizeIndex.set(e)
443    }
444
445    get hideControlDelay() {
446        return this.__hideControlDelay.get()
447    }
448
449    set hideControlDelay(e) {
450        this.__hideControlDelay.set(e)
451    }
452
453    initialRender() {
454        this.observeComponentCreation2(((e, t) => {
455            RelativeContainer.create();
456            RelativeContainer.width("100%");
457            RelativeContainer.height(48);
458            RelativeContainer.onAreaChange(((e, t) => {
459                e.width != t.width && (this.sizeIndex = t.width >= 150 ? 1 : 0)
460            }));
461            RelativeContainer.alignRules({
462                bottom: { anchor: "__container__", align: VerticalAlign.Bottom },
463                left: { anchor: "__container__", align: HorizontalAlign.Start }
464            });
465            RelativeContainer.id("call_control")
466        }), RelativeContainer);
467        this.observeComponentCreation2(((e, t) => {
468            Button.createWithChild({ type: ButtonType.Circle });
469            Button.backgroundColor({
470                id: -1,
471                type: 10001,
472                params: ["sys.color.ohos_id_color_handup"],
473                bundleName: "",
474                moduleName: ""
475            });
476            Button.size({ width: 24 * sizeArray[this.sizeIndex], height: 24 * sizeArray[this.sizeIndex] });
477            Button.margin({
478                top: 12,
479                bottom: 12
480            });
481            Button.alignRules({
482                bottom: { anchor: "__container__", align: VerticalAlign.Bottom },
483                middle: { anchor: "__container__", align: HorizontalAlign.Center }
484            });
485            Button.id("control_hangup");
486            Button.onClick((() => {
487                this.hideControlDelay = !0;
488                pip.triggerAction("hangUp");
489                console.debug(TAG, "action: hangup")
490            }))
491        }), Button);
492        this.observeComponentCreation2(((e, t) => {
493            Image.create({
494                id: -1,
495                type: 2e4,
496                params: ["sys.media.ohos_ic_public_hang_up"],
497                bundleName: "",
498                moduleName: ""
499            });
500            Image.size({ width: 12 * sizeArray[this.sizeIndex], height: 12 * sizeArray[this.sizeIndex] });
501            Image.fillColor({
502                id: -1,
503                type: 10001,
504                params: ["sys.color.ohos_id_color_primary_contrary"],
505                bundleName: "",
506                moduleName: ""
507            });
508            Image.objectFit(ImageFit.Contain)
509        }), Image);
510        Button.pop();
511        this.observeComponentCreation2(((e, t) => {
512            Button.createWithChild({ type: ButtonType.Circle });
513            Button.backgroundColor({
514                id: -1,
515                type: 10001,
516                params: ["sys.color.ohos_id_color_floating_button_icon"],
517                bundleName: "",
518                moduleName: ""
519            });
520            Button.size({ width: 16 * sizeArray[this.sizeIndex], height: 16 * sizeArray[this.sizeIndex] });
521            Button.margin({
522                left: 8 * sizeArray[this.sizeIndex],
523                right: 8 * sizeArray[this.sizeIndex]
524            });
525            Button.alignRules({
526                center: { anchor: "control_hangup", align: VerticalAlign.Center },
527                right: { anchor: "control_hangup", align: HorizontalAlign.Start }
528            });
529            Button.id("control_mute");
530            Button.onClick((() => {
531                this.hideControlDelay = !0;
532                this.isMute = !this.isMute;
533                pip.triggerAction("micStateChanged");
534                console.debug(TAG, "action: mic enable or disable")
535            }))
536        }), Button);
537        this.observeComponentCreation2(((e, t) => {
538            Image.create(this.isMute ? {
539                id: -1,
540                type: 2e4,
541                params: ["sys.media.ohos_ic_public_voice"],
542                bundleName: "",
543                moduleName: ""
544            } : {
545                id: -1,
546                type: 2e4,
547                params: ["sys.media.ohos_ic_public_voice_off"],
548                bundleName: "",
549                moduleName: ""
550            });
551            Image.size({ width: 8 * sizeArray[this.sizeIndex], height: 8 * sizeArray[this.sizeIndex] });
552            Image.fillColor({
553                id: -1,
554                type: 10001,
555                params: ["sys.color.ohos_id_color_primary"],
556                bundleName: "",
557                moduleName: ""
558            });
559            Image.objectFit(ImageFit.Contain)
560        }), Image);
561        Button.pop();
562        this.observeComponentCreation2(((e, t) => {
563            Button.createWithChild({ type: ButtonType.Circle });
564            Button.backgroundColor({
565                id: -1,
566                type: 10001,
567                params: ["sys.color.ohos_id_color_floating_button_icon"],
568                bundleName: "",
569                moduleName: ""
570            });
571            Button.size({ width: 16 * sizeArray[this.sizeIndex], height: 16 * sizeArray[this.sizeIndex] });
572            Button.margin({
573                left: 8 * sizeArray[this.sizeIndex],
574                right: 8 * sizeArray[this.sizeIndex]
575            });
576            Button.alignRules({
577                center: { anchor: "control_hangup", align: VerticalAlign.Center },
578                left: { anchor: "control_hangup", align: HorizontalAlign.End }
579            });
580            Button.id("control_record");
581            Button.onClick((() => {
582                this.hideControlDelay = !0;
583                this.isRecord = !this.isRecord;
584                pip.triggerAction("videoStateChanged");
585                console.debug(TAG, "action: video enable or disable")
586            }))
587        }), Button);
588        this.observeComponentCreation2(((e, t) => {
589            Image.create(this.isRecord ? {
590                id: -1,
591                type: 2e4,
592                params: ["sys.media.ohos_ic_public_video"],
593                bundleName: "",
594                moduleName: ""
595            } : {
596                id: -1,
597                type: 2e4,
598                params: ["sys.media.ohos_ic_public_video_off"],
599                bundleName: "",
600                moduleName: ""
601            });
602            Image.size({ width: 8 * sizeArray[this.sizeIndex], height: 8 * sizeArray[this.sizeIndex] });
603            Image.fillColor({
604                id: -1,
605                type: 10001,
606                params: ["sys.color.ohos_id_color_primary"],
607                bundleName: "",
608                moduleName: ""
609            });
610            Image.objectFit(ImageFit.Contain)
611        }), Image);
612        Button.pop();
613        RelativeContainer.pop()
614    }
615
616    rerender() {
617        this.updateDirtyElements()
618    }
619}
620
621ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent());
622loadDocument(new PiPCall(void 0, {}));
623ViewStackProcessor.StopGetAccessRecording();