System.register(["cc"], function (_export, _context4) {
  "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 asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }

  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }

  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 _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

  function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }

  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

  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 = _decorator.ccclass;
      property = _decorator.property;

      _export("default", streamVideoPlayer = (_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);

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

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

          return _this;
        }

        var _proto = streamVideoPlayer.prototype;

        _proto.start = function start() {
          var _this2 = this;

          var 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(function () {
            _this2.onYoumeInit();
          }).start();
        };

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

        _proto.onYoumeInit = function onYoumeInit() {
          var _this3 = 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 _this3.login();

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

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

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

                  case 11:
                    streamListForFirst1 = _context.sent;
                    _context.next = 14;
                    return _this3.getStreamList(_this3.session, _this3.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 = _this3.playerGroup1.createPlayClient(item.stream, "" + item.id); // 针对某一路流创建一个播放实例


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


                      console.log('player', player);

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


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


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

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

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

                  case 20:
                  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();
          this.playStreamVideo();
        } //视频清晰度
        ;

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

        _proto.playStreamVideo = function playStreamVideo() {
          var _this4 = this;

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

          if (this.windowModel == 0) {
            this.playFrontVideo();
          } else if (this.windowModel == 1) {
            tween(this.node).delay(0.2).call(function () {
              _this4.playTopVideo();
            }).start();
          } else {
            this.playFrontVideo();
            tween(this.node).delay(0.2).call(function () {
              _this4.playTopVideo();
            }).start();
          } //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; // 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();

        } //播放正前方視頻
        ;

        _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();

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