System.register("chunks:///_virtual/streamVideoPlayer.ts", ['./_rollupPluginModLoBabelHelpers.js', 'cc'], function (exports) {
  'use strict';

  var _applyDecoratedDescriptor, _inheritsLoose, _asyncToGenerator, _defineProperty, _assertThisInitialized, _initializerDefineProperty, cclegacy, _decorator, Node, find, log, VideoPlayer, UITransform, v2, Component;

  return {
    setters: [function (module) {
      _applyDecoratedDescriptor = module.applyDecoratedDescriptor;
      _inheritsLoose = module.inheritsLoose;
      _asyncToGenerator = module.asyncToGenerator;
      _defineProperty = module.defineProperty;
      _assertThisInitialized = module.assertThisInitialized;
      _initializerDefineProperty = module.initializerDefineProperty;
    }, function (module) {
      cclegacy = module.cclegacy;
      _decorator = module._decorator;
      Node = module.Node;
      find = module.find;
      log = module.log;
      VideoPlayer = module.VideoPlayer;
      UITransform = module.UITransform;
      v2 = module.v2;
      Component = module.Component;
    }],
    execute: function () {
      var _dec, _dec2, _dec3, _dec4, _dec5, _class, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _temp;

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

      var ccclass = _decorator.ccclass,
          property = _decorator.property;
      var streamVideoPlayer = exports('default', (_dec = property(Node), _dec2 = property(Node), _dec3 = property(Node), _dec4 = property(Node), _dec5 = property(Node), ccclass(_class = (_class2 = (_temp = /*#__PURE__*/function (_Component) {
        _inheritsLoose(streamVideoPlayer, _Component);

        function streamVideoPlayer() {
          var _this;

          for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
            args[_key] = arguments[_key];
          }

          _this = _Component.call.apply(_Component, [this].concat(args)) || this;

          _defineProperty(_assertThisInitialized(_this), "session", void 0);

          _defineProperty(_assertThisInitialized(_this), "roomList", null);

          _defineProperty(_assertThisInitialized(_this), "Youme", null);

          _defineProperty(_assertThisInitialized(_this), "playerGroup1", null);

          _defineProperty(_assertThisInitialized(_this), "playerGroup2", null);

          _defineProperty(_assertThisInitialized(_this), "playerList1", []);

          _defineProperty(_assertThisInitialized(_this), "playerList2", []);

          _defineProperty(_assertThisInitialized(_this), "windowModel", 0);

          _defineProperty(_assertThisInitialized(_this), "videoQuality", 1);

          _defineProperty(_assertThisInitialized(_this), "_Mute", 1);

          _defineProperty(_assertThisInitialized(_this), "frontOriginalPos", v2(0, 0));

          _initializerDefineProperty(_assertThisInitialized(_this), "changeNode", _descriptor, _assertThisInitialized(_this));

          _initializerDefineProperty(_assertThisInitialized(_this), "frontPlayer", _descriptor2, _assertThisInitialized(_this));

          _initializerDefineProperty(_assertThisInitialized(_this), "topPlayer", _descriptor3, _assertThisInitialized(_this));

          _initializerDefineProperty(_assertThisInitialized(_this), "tinyPosNode", _descriptor4, _assertThisInitialized(_this));

          _initializerDefineProperty(_assertThisInitialized(_this), "midPosNode", _descriptor5, _assertThisInitialized(_this));

          _defineProperty(_assertThisInitialized(_this), "_isYoumeInit", false);

          return _this;
        }

        var _proto = streamVideoPlayer.prototype;

        _proto.start = function start() {
          var canvas = find('Canvas');
          canvas.on(Node.EventType.TOUCH_START, this.onYoumeInit, this);
          this.changeNode.on(Node.EventType.TOUCH_START, this.onVideoModelClick, this);
        };

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

        _proto.onYoumeInit = function onYoumeInit() {
          var _this2 = this; // 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( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
            var users, element, streamListForFirst1, streamListForFirst2;
            return regeneratorRuntime.wrap(function _callee$(_context) {
              while (1) {
                switch (_context.prev = _context.next) {
                  case 0:
                    _context.next = 2;
                    return _this2.login();

                  case 2:
                    _this2.roomList = _context.sent;
                    console.log('roomList', _this2.roomList);
                    users = _this2.roomList[0].user_list; // 该房间内的所有成员列表

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

                    _context.next = 11;
                    return _this2.getStreamList(_this2.session, _this2.roomList[0].room_id, users[0]);

                  case 11:
                    streamListForFirst1 = _context.sent;
                    _context.next = 14;
                    return _this2.getStreamList(_this2.session, _this2.roomList[0].room_id, users[1]);

                  case 14:
                    streamListForFirst2 = _context.sent;
                    console.log('streamList for first user', streamListForFirst1);
                    console.log('streamList for second user', streamListForFirst2);
                    streamListForFirst1.forEach(function (item) {
                      var player = _this2.playerGroup1.createPlayClient(item.stream, "" + item.id); // 针对某一路流创建一个播放实例


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


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


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


                      console.log('player', player); //switchSecondShowText('id=1');
                      // this.playerList2[0].startPlay();
                    });

                    _this2.playStreamVideo();

                    return _context.abrupt("return", false);

                  case 21:
                  case "end":
                    return _context.stop();
                }
              }
            }, _callee);
          })))["catch"](function (e) {
            console.log('error1', e);
          });
        };

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

        _proto.login = /*#__PURE__*/function () {
          var _login = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
            var data;
            return regeneratorRuntime.wrap(function _callee2$(_context2) {
              while (1) {
                switch (_context2.prev = _context2.next) {
                  case 0:
                    _context2.prev = 0;
                    _context2.next = 3;
                    return this.Youme.login();

                  case 3:
                    this.session = _context2.sent;
                    _context2.next = 6;
                    return this.Youme.getRoomList(this.session);

                  case 6:
                    data = _context2.sent;
                    return _context2.abrupt("return", data);

                  case 10:
                    _context2.prev = 10;
                    _context2.t0 = _context2["catch"](0);
                    console.log(_context2.t0);

                  case 13:
                  case "end":
                    return _context2.stop();
                }
              }
            }, _callee2, this, [[0, 10]]);
          }));

          function login() {
            return _login.apply(this, arguments);
          }

          return login;
        }() // 获取某一房间内某一具体用户的所有视频流地址
        ;

        _proto.getStreamList = /*#__PURE__*/function () {
          var _getStreamList = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(session, room_id, user_id) {
            var streamList;
            return regeneratorRuntime.wrap(function _callee3$(_context3) {
              while (1) {
                switch (_context3.prev = _context3.next) {
                  case 0:
                    _context3.prev = 0;
                    _context3.next = 3;
                    return this.Youme.getStreamList(session, room_id, user_id);

                  case 3:
                    streamList = _context3.sent;
                    return _context3.abrupt("return", streamList);

                  case 7:
                    _context3.prev = 7;
                    _context3.t0 = _context3["catch"](0);
                    console.log(_context3.t0);

                  case 10:
                  case "end":
                    return _context3.stop();
                }
              }
            }, _callee3, this, [[0, 7]]);
          }));

          function getStreamList(_x, _x2, _x3) {
            return _getStreamList.apply(this, arguments);
          }

          return getStreamList;
        }() //视频声音
        ;

        _proto.changeMute = function 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);
          }
        } //右上角视频窗口按钮
        ;

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

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

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

          if (this.windowModel == 0) {
            this.playFrontVideo();
          } else if (this.windowModel == 1) {
            this.playTopVideo();
          } else {
            this.playFrontVideo();
            this.playTopVideo();
          }

          this.changeMute(this._Mute);
        } //改变视频窗口
        ;

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

          if (this.windowModel == 0) {
            this.frontPlayer.active = true;
            this.topPlayer.getComponent(VideoPlayer).stop();
            this.topPlayer.active = false;
            var 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);

            var tinyTransform = this.tinyPosNode.getComponent(UITransform);
            this.frontPlayer.getComponent(UITransform).contentSize = tinyTransform.contentSize;
            this.frontPlayer.position = this.tinyPosNode.position;
          } //this.playStreamVideo();

        } //播放正前方視頻
        ;

        _proto.playFrontVideo = function 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()_\u5F02\u5E38\u60C5\u51B5\uFF0C\u9ED8\u8BA4\u64AD\u653E \u4F4E\u753B\u8D28\u753B\u9762");
            this.playerList1[0].startPlay();
          } //this.frontPlayer.getComponent(VideoPlayer).play();

        } //播放頂部視頻
        ;

        _proto.playTopVideo = function 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()_\u5F02\u5E38\u60C5\u51B5\uFF0C\u9ED8\u8BA4\u64AD\u653E \u4F4E\u753B\u8D28\u753B\u9762");
            this.playerList2[0].startPlay();
          } //  this.topPlayer.getComponent(VideoPlayer).play();

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

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

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

        _proto.initAddEventListener = function 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);
        } //声音开启或关闭
        ;

        _proto.onvideoVoiceChange = function onvideoVoiceChange(mdata) {
          log("********:", mdata);

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

        _proto.onVideoQualityChange = function onVideoQualityChange(mdata) {
          log("this.videoQuality:" + this.videoQuality + "___ mdata.videoquality:" + mdata.videoquality);

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

        _proto.onVideoWindowChange = function onVideoWindowChange(mdata) {
          if (this.windowModel != mdata.windowmodel) {
            this.windowModel = mdata.windowmodel;
            this.changeVideoWindow();
            this.playStreamVideo();
          }
        } //链接关闭监听
        ;

        _proto.onDestroy = function onDestroy() {//this.removeEventListener();
        };

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

      cclegacy._RF.pop();
    }
  };
});

System.register("chunks:///_virtual/script", ['./streamVideoPlayer.ts'], function () {
  'use strict';

  return {
    setters: [null],
    execute: function () {}
  };
});

(function(r) {
  r('virtual:///prerequisite-imports/script', 'chunks:///_virtual/script'); 
})(function(mid, cid) {
    System.register(mid, [cid], function (_export, _context) {
    return {
        setters: [function(_m) {
            var _exportObj = {};

            for (var _key in _m) {
              if (_key !== "default" && _key !== "__esModule") _exportObj[_key] = _m[_key];
            }
      
            _export(_exportObj);
        }],
        execute: function () { }
    };
    });
});