//应模块主要作用是 ws链接进行，发送到解码模块
//了解当前模块请搜索关键字 》》》TDDE《《《 了解注意注释
(function() {
	var e = {}.hasOwnProperty,
		t = function(t, r) {
			function o() {
				this.constructor = t
			}
			for (var n in r) e.call(r, n) && (t[n] = r[n]);
			return o.prototype = r.prototype, t.prototype = new o, t.__super__ = r.prototype, t
		};
	AV.WebSocketSource = function(e) {
		function r(e, t) {
			return this.serverUrl = e, this.fileName = t, "undefined" == typeof WebSocket || null === WebSocket ? this.emit(
				"error", "此浏览器不支持WebSocket.") : (this.socket = new WebSocket(this.serverUrl), null ==
				this.socket.binaryType ? (this.socket.close(), this.emit("error",
					"此浏览器不支持二进制WebSocket.")) : (this.bytesLoaded = 0, this._setupSocket(), void 0))
		}
		return t(r, e), r.prototype.start = function() {
						return this._send(JSON.stringify({
							resume: !0
						}))
		}, r.prototype.pause = function() {
			return
		}, r.prototype.reset = function() {
			return this._send(JSON.stringify({
				reset: !0
			}))
		}, r.prototype._send = function(e) {
			return this.open ? this.socket.send(e) : this._bufferMessage = e
		}, r.prototype._setupSocket = function() {
			var e = this;
			return this.socket.binaryType = "arraybuffer", 
			this.socket.onopen = function() {
				return e.open = !0, e.fileName && e.socket.send(JSON.stringify({
					fileName: e.fileName
				})), e._bufferMessage ? (e.socket.send(e._bufferMessage), e._bufferMessage = null) : void 0
			}, 
			this.socket.onmessage = function(t) {
				var r, o;
				r = new AV.Buffer(new Uint8Array(o))
				var se = t.data
				//TDDE 这里是发送每一帧到decode
				// console.log("这里是发送每一帧到decode",new Uint8Array(se));
				if (new Uint8Array(se)[0] == 0) {

					var messageData = new Uint8Array(se)
					player.decode(messageData); //视频播放
					console.log('黄飞5')
					return
				} else if (new Uint8Array(se)[1] == 241) {

					return o = t.data, "string" != typeof o ? (r = new AV.Buffer(new Uint8Array(o)), e.bytesLoaded += r.length, e.length &&
						e.emit("progress", 100 * (e.bytesLoaded / e.length)), e.emit("data", r)) : (o = JSON.parse(o), null != o.fileSize ?
						e.length = o.fileSize : null != o.error ? e.emit("error", o.error) : o.end ? e.socket.close() : void 0)
				} else {
					var ssep = JSON.parse(se)
					if (ssep.errorCode == 8006) {
						alert(ssep.errorMsg)
					} else if (ssep.errorCode == 8007) {
						alert(ssep.errorMsg)
					} else if (ssep.errorCode == 8008) {
						alert(ssep.errorMsg)
					} else if (ssep.errorCode == 8009) {
						alert(ssep.errorMsg)
					} else if (ssep.errorCode == 8010) {
						alert(ssep.errorMsg)
					} else if (ssep.errorCode == 8003) {
						console.log("分享过期啦========")

						$(".leftmains").css({
							"right": "0"
						})
						$('.leftmains').show()
						$('.bottommains').show()
						$('#btnMuted').show()
						alert(ssep.errorMsg)
					}
				}
			}, this.socket.onclose = function(t) {
				//			 	 console.log('黄飞5')
				return e.open = !1, t.wasClean ? e.emit("end") : e.emit("error", "WebSocket closed uncleanly with code " + t.code +
					".")
			}, this.socket.onerror = function(t) {
				alert("你访问的屏幕已经过期")
				console.log('黄飞>>>6', t)
				return e.emit("error", t)
			}
		}, r
	}(AV.EventEmitter), AV.Asset.fromWebSocket = function(e, t) {
		var r;
		console.log('黄飞1')
		return r = new AV.WebSocketSource(e, t), new AV.Asset(r)

	}, AV.Player.fromWebSocket = function(e, t) {
		var r;
		console.log('黄飞2')
		return r = AV.Asset.fromWebSocket(e, t), new AV.Player(r)
	}
}).call(this);
