System.register(["cc"], function (_export, _context) {
  "use strict";

  var _cclegacy, find, v2, VideoPlayer, _decorator, Component, Node, tween, log, _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _temp, _crd, ccclass, property, streamVideoPlayer;

  function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }

  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

  function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }

  function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'proposal-class-properties is enabled and runs after the decorators transform.'); }

  return {
    setters: [function (_cc) {
      _cclegacy = _cc.cclegacy;
      find = _cc.find;
      v2 = _cc.v2;
      VideoPlayer = _cc.VideoPlayer;
      _decorator = _cc._decorator;
      Component = _cc.Component;
      Node = _cc.Node;
      tween = _cc.tween;
      log = _cc.log;
    }],
    execute: function () {
      _crd = true;

      _cclegacy._RF.push({}, "45e20eUJedIfYU7x+ii9vZn", "streamVideoPlayer", undefined);

      ({
        ccclass,
        property
      } = _decorator);

      _export("default", streamVideoPlayer = (_dec = property(Node), _dec2 = property(Node), _dec3 = property(Node), _dec4 = property(Node), _dec5 = property(Node), ccclass(_class = (_class2 = (_temp = class streamVideoPlayer extends Component {
        constructor(...args) {
          super(...args);

          _defineProperty(this, "session", void 0);

          _defineProperty(this, "roomList", null);

          _defineProperty(this, "Youme", null);

          _defineProperty(this, "playerGroup1", null);

          _defineProperty(this, "playerGroup2", null);

          _defineProperty(this, "playerList1", []);

          _defineProperty(this, "playerList2", []);

          _defineProperty(this, "windowModel", 0);

          _defineProperty(this, "videoQuality", 1);

          _defineProperty(this, "_Mute", 1);

          _defineProperty(this, "frontOriginalPos", v2(0, 0));

          _initializerDefineProperty(this, "changeNode", _descriptor, this);

          _initializerDefineProperty(this, "frontPlayer", _descriptor2, this);

          _initializerDefineProperty(this, "topPlayer", _descriptor3, this);

          _initializerDefineProperty(this, "tinyPosNode", _descriptor4, this);

          _initializerDefineProperty(this, "midPosNode", _descriptor5, this);

          _defineProperty(this, "_isYoumeInit", false);

          _defineProperty(this, "_frontVideo", null);

          _defineProperty(this, "_topVideo", null);
        }

        start() {
          let canvas = find('Canvas'); // canvas.on(Node.EventType.TOUCH_START, this.onYoumeInit, this);

          this.changeNode.on(Node.EventType.TOUCH_START, this.onVideoModelClick, this);
          tween(this.node).delay(0.1).call(() => {
            this.onYoumeInit();
          }).start();
        }

        onLoad() {
          this.Youme = new YMFLV(214, 'YOUME5BE427937AF216E88E0F84C0EF148BD29B691556');
          this.initAddEventListener();
          this.changeVideoWindow(); //游戏一进来，就先做出窗口的变化
        }

        onYoumeInit() {
          // if(1){
          //     this.playStreamVideo();
          //     return;
          // }
          log("________________________onYoumeInit");
          if (this._isYoumeInit) return;
          this._isYoumeInit = true; // 初始化实例

          this.Youme.init('ws://120.25.226.133:8800/media_live').then(async () => {
            this.roomList = await this.login();
            console.log('roomList', this.roomList);
            let users = this.roomList[0].user_list; // 该房间内的所有成员列表

            console.log('users', users);
            let element = document.getElementsByClassName('cocosVideo');
            this.playerGroup1 = this.Youme.createPlayerGroup(element[0]);
            this.playerGroup2 = this.Youme.createPlayerGroup(element[1]); // 获取每一个用户对应的视频流列表

            const streamListForFirst1 = await this.getStreamList(this.session, this.roomList[0].room_id, users[0]);
            const streamListForFirst2 = await this.getStreamList(this.session, this.roomList[0].room_id, users[1]);
            console.log('streamList for first user', streamListForFirst1);
            console.log('streamList for second user', streamListForFirst2);
            streamListForFirst1.forEach(item => {
              const player = this.playerGroup1.createPlayClient(item.stream, `${item.id}`); // 针对某一路流创建一个播放实例

              this.playerList1.push(player); // 形成某一用户的所有播放实例的数组

              console.log('player', player);
              this.playerList1[0].startPlay();
            });
            streamListForFirst2.forEach(item => {
              const player = this.playerGroup2.createPlayClient(item.stream, `${item.id}`); // 针对某一路流创建一个播放实例

              this.playerList2.push(player); // 形成某一用户的所有播放实例的数组

              console.log('player', player); //switchSecondShowText('id=1');

              this.playerList2[0].startPlay();
            }); // this.playStreamVideo();

            return false;
          }).catch(e => {
            console.log('error1', e);
          });
        }

        onYoumeClose() {
          this.Youme.onClose(() => {
            console.log('close callback');
          });
        } // 登录


        async login() {
          try {
            this.session = await this.Youme.login();
            const data = await this.Youme.getRoomList(this.session);
            return data;
          } catch (e) {
            console.log(e);
          }
        } // 获取某一房间内某一具体用户的所有视频流地址


        async getStreamList(session, room_id, user_id) {
          try {
            const streamList = await this.Youme.getStreamList(session, room_id, user_id);
            return streamList;
          } catch (e) {
            console.log(e);
          }
        } //视频声音


        changeMute(isMute) {
          this._Mute = isMute;
          log("_________________mute:" + this._Mute);

          if (this.windowModel == 0) {
            this.setTopVideoMute(false);
            this.setFrontVideoMute(this._Mute == 1);
          } else if (this.windowModel == 1) {
            this.setTopVideoMute(this._Mute);
            this.setFrontVideoMute(false);
          } else {
            //第三种情况，两个视频采取一个视频流音效就好
            this.setTopVideoMute(this._Mute == 1);
            this.setFrontVideoMute(false);
          }
        } //右上角视频窗口按钮


        onVideoModelClick() {
          this.windowModel++;
          this.windowModel = this.windowModel > 2 ? 0 : this.windowModel;
          this.changeVideoWindow();
          this.playStreamVideo();
        } //视频清晰度


        changeVideoHd(videoquality) {
          this.videoQuality = videoquality;
          this.playStreamVideo();
        } //播放视频流


        playStreamVideo() {
          log("********************************playStreamVideo():" + this.windowModel);

          if (this.windowModel == 0) {
            this.playFrontVideo();
          } else if (this.windowModel == 1) {
            tween(this.node).delay(0.2).call(() => {
              this.playTopVideo();
            }).start();
          } else {
            this.playFrontVideo();
            tween(this.node).delay(0.2).call(() => {
              this.playTopVideo();
            }).start();
          } //this.changeMute(this._Mute);

        } //改变视频窗口


        changeVideoWindow() {
          log("_____changeWindow:" + this.windowModel);

          if (this.windowModel == 0) {
            this.frontPlayer.active = true; // this.topPlayer.getComponent(VideoPlayer).stop();

            this.topPlayer.active = false; // let midTransform = this.midPosNode.getComponent(UITransform);
            // this.frontPlayer.getComponent(UITransform).contentSize = midTransform.contentSize;
            // this.frontPlayer.position = this.midPosNode.position;
          } else if (this.windowModel == 1) {
            // this.frontPlayer.getComponent(VideoPlayer).stop();
            this.frontPlayer.active = false;
            this.topPlayer.active = true;
          } else {
            this.frontPlayer.active = true;
            this.topPlayer.active = true; // let fTransform = this.frontPlayer.getComponent(UITransform);
            // let tinyTransform = this.tinyPosNode.getComponent(UITransform);
            // this.frontPlayer.getComponent(UITransform).contentSize = tinyTransform.contentSize;
            // this.frontPlayer.position = this.tinyPosNode.position;
          } //this.playStreamVideo();

        } //播放正前方視頻


        playFrontVideo() {
          log(`Ethan____playFrontVideo()_this.playerList1.length:${this.playerList1.length}___this.videoQuality:${this.videoQuality}`);

          if (this.playerList1.length > 0 && this.videoQuality < this.playerList1.length) {
            this.playerList1[this.videoQuality].startPlay();
          }

          if (this.playerList1.length > 0 && this.videoQuality >= this.playerList1.length) {
            //异常情况播放0
            log(`Ethan____playFrontVideo()_异常情况，默认播放 低画质画面`);
            this.playerList1[0].startPlay();
          } //this.frontPlayer.getComponent(VideoPlayer).play();

        } //播放頂部視頻


        playTopVideo() {
          log(`Ethan____playTopVideo()_this.playerList2.length:${this.playerList2.length}___this.videoQuality:${this.videoQuality}`);

          if (this.playerList2.length > 0 && this.videoQuality < this.playerList2.length) {
            this.playerList2[this.videoQuality].startPlay();
          }

          if (this.playerList2.length > 0 && this.videoQuality >= this.playerList2.length) {
            //异常情况播放0
            log(`Ethan____playTopVideo()_异常情况，默认播放 低画质画面`);
            this.playerList2[0].startPlay();
          } //  this.topPlayer.getComponent(VideoPlayer).play();

        } //设置顶部视频流音效


        setTopVideoMute(isMute) {
          let topVpCmp = this.topPlayer.getComponent(VideoPlayer);
          topVpCmp.mute = isMute;
        } //设置正前方视频流音效


        setFrontVideoMute(isMute) {
          let frontVpCmp = this.frontPlayer.getComponent(VideoPlayer);
          frontVpCmp.mute = isMute;
        } //初始化事件监听


        initAddEventListener() {// this.addEventListener(EventName.VIDEO_WINDOW_CHANGE,this.onVideoWindowChange);
          // this.addEventListener(EventName.VIDEO_QUALITY_CHANGE,this.onVideoQualityChange);
          // this.addEventListener(EventName.VIDEO_VOICE_CHANGE,this.onvideoVoiceChange);
        } //声音开启或关闭


        onvideoVoiceChange(mdata) {
          log("********:", mdata);

          if (this._Mute != mdata.mute) {
            this.changeMute(mdata.mute);
          }
        } //画面品质发生变化


        onVideoQualityChange(mdata) {
          log(`this.videoQuality:${this.videoQuality}___ mdata.videoquality:${mdata.videoquality}`);

          if (this.videoQuality != mdata.videoquality) {
            this.changeVideoHd(mdata.videoquality);
          }
        } //视频窗口变化


        onVideoWindowChange(mdata) {
          if (this.windowModel != mdata.windowmodel) {
            this.windowModel = mdata.windowmodel; // this.changeVideoWindow();

            this.playStreamVideo();
          }
        } //链接关闭监听


        onDestroy() {//this.removeEventListener();
        }

      }, _temp), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "changeNode", [_dec], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: function () {
          return null;
        }
      }), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "frontPlayer", [_dec2], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: function () {
          return null;
        }
      }), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "topPlayer", [_dec3], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: function () {
          return null;
        }
      }), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "tinyPosNode", [_dec4], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: function () {
          return null;
        }
      }), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "midPosNode", [_dec5], {
        configurable: true,
        enumerable: true,
        writable: true,
        initializer: function () {
          return null;
        }
      })), _class2)) || _class));

      _cclegacy._RF.pop();

      _crd = false;
    }
  };
});
//# sourceMappingURL=streamVideoPlayer.js.map