1957 lines
122 KiB
JavaScript
1957 lines
122 KiB
JavaScript
"use strict";
|
|
var _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) {
|
|
return typeof e
|
|
} : function (e) {
|
|
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e
|
|
},
|
|
H5Live = {
|
|
version: "1.0.6",
|
|
debug: !1,
|
|
language: "zh_CN",
|
|
browserType: null,
|
|
windowObjects: null,
|
|
callObject: null,
|
|
talkObject: null,
|
|
gatherVideoStreamObject: null,
|
|
inited: !1,
|
|
cb: null,
|
|
video: null,
|
|
Plug: {
|
|
GetHtml: function (e) {
|
|
var e = e || {},
|
|
t = "";
|
|
return t += '<video muted id="' + e.domid + '_video" name="' + e.domname + '_video" style="width:0px;height:0px;object-fit:fill;"></video>', t += '<audio id="' + e.domid + '_audio" name="' + e.domname + '_audio" style="width:0px;height:0px;object-fit:fill;"></audio>'
|
|
},
|
|
end: !0
|
|
},
|
|
IsInited: function () {
|
|
return H5Live.inited || !1
|
|
},
|
|
ValidObjectLoad: function () {
|
|
try {
|
|
var e = "H5Live.ValidObjectLoad";
|
|
if (H5Live.IsInited()) return H5Live.Utils.Log(e, "H5Live has inited~"), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS);
|
|
var t = null,
|
|
i = "_h5live-xvideo-box";
|
|
document.getElementById(i) ? t = document.getElementById(i) : (t = document.createElement("DIV"), t.setAttribute("id", i), t.setAttribute("attention", "for h5live video verfifying..."), document.getElementsByTagName("body").item(0).appendChild(t)), t.style.display = "none", t.style.visibility = "hidden";
|
|
var r = [];
|
|
return r.push(H5Live.Plug.GetHtml({
|
|
domid: "_h5live-xvideo",
|
|
domname: "_h5live-xvideo"
|
|
})), (t.insertAdjacentHTML("beforeEnd", r.join("")), void 0 === document.getElementById("_h5live-xvideo_video").play) ? (H5Live.Utils.Log(e, "load h5video error~"), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_LOAD_H5VIDEO_OBJECT_FAILED)) : void 0 === document.getElementById("_h5live-xvideo_audio").play ? (H5Live.Utils.Log(e, "load h5audio error~"), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_LOAD_H5VIDEO_OBJECT_FAILED)) : (H5Live.inited = !0, new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS))
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excp error = " + t.name + "," + t.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
},
|
|
CheckBrowserType: function () {
|
|
try {
|
|
var e = window.navigator.userAgent.toLowerCase();
|
|
if (e.indexOf("MSIE") >= 0) {
|
|
var t = e.match(/msie ([\d.]+)/)[1];
|
|
parseInt(t)
|
|
} else if (e.indexOf("Firefox") >= 0) var t = e.match(/firefox\/([\d.]+)/)[1];
|
|
else if (e.indexOf("Chrome") >= 0) var t = e.match(/chrome\/([\d.]+)/)[1];
|
|
else if (e.indexOf("Opera") >= 0) var t = e.match(/opera.([\d.]+)/)[1];
|
|
else if (e.indexOf("Safari") >= 0) var t = e.match(/version\/([\d.]+)/)[1]
|
|
} catch (e) {
|
|
}
|
|
},
|
|
GlobalDestory: function () {
|
|
try {
|
|
var e = "H5Live.GlobalDestory";
|
|
this.DestoryWindows()
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excp error = " + t.name + "," + t.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
},
|
|
DestoryWindows: function (e) {
|
|
try {
|
|
var t = "H5Live.DestoryWindows",
|
|
i = this;
|
|
this.windowObjects instanceof H5Live.Utils.Hash && this.windowObjects.each(function (t, r) {
|
|
if (t.key === e || !e && t.key) {
|
|
var a = t.value;
|
|
a && (a.CloseVideo(), a.CloseAudio()), i.windowObjects.remove(t.key)
|
|
}
|
|
})
|
|
} catch (e) {
|
|
H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message)
|
|
}
|
|
},
|
|
Window: function (e, t) {
|
|
try {
|
|
var i = "H5Live.Window";
|
|
this.video = {
|
|
puid: null,
|
|
idx: null,
|
|
type: "IV",
|
|
ws: null,
|
|
containerId: null,
|
|
isPlaying: !1,
|
|
_cb: null
|
|
}, this.video_IA = {
|
|
puid: null,
|
|
idx: null,
|
|
type: "IV",
|
|
ws: null,
|
|
containerId: null,
|
|
isPlaying: !1,
|
|
_cb: null
|
|
}, this.audio = {
|
|
puid: null,
|
|
idx: null,
|
|
type: "IV",
|
|
containerId: null,
|
|
isPlaying: !1,
|
|
_cb: null
|
|
}, this.vod = {
|
|
ws: null,
|
|
isPlaying: !1,
|
|
type: "platform",
|
|
puid: "",
|
|
diskLetter: "",
|
|
idx: 0,
|
|
fileName: "",
|
|
beginTime: "",
|
|
endTime: "",
|
|
offsetTime: "",
|
|
speed: 1,
|
|
_cb: null
|
|
}, this.record = {
|
|
ws: null,
|
|
puid: null,
|
|
idx: null,
|
|
type: "IV",
|
|
containerId: null,
|
|
isRecording: !1,
|
|
_cb: null
|
|
}, this.videoMSE = new MediaSource, this.audioMSE = new MediaSource, this.videoSegments = {
|
|
video: []
|
|
}, this.audioSegments = {
|
|
audio: []
|
|
}, this.videosb = {
|
|
video: null
|
|
}, this.audiosb = {
|
|
audio: null
|
|
}, this.metadata = {
|
|
audioCodec: "mp4a.40.2",
|
|
videoCodec: "avc1.42E01E"
|
|
};
|
|
var r = this;
|
|
r.audioMSE.addEventListener("sourceopen", function (e) {
|
|
r.AddSourceBuffer("audio")
|
|
}), r.videoMSE.addEventListener("sourceopen", function (e) {
|
|
r.AddSourceBuffer("video")
|
|
});
|
|
var a = null;
|
|
if ("object" === (void 0 === e ? "undefined" : _typeof(e)) && void 0 !== e.id) a = e;
|
|
else {
|
|
if (null == e || void 0 === e || null == document.getElementById(e)) return H5Live.Utils.Log(i, "containerOrId error~"), !1;
|
|
a = document.getElementById(e)
|
|
}
|
|
if (null === H5Live.windowObjects && (H5Live.windowObjects = new H5Live.Utils.Hash), H5Live.windowObjects.containsKey(a.id)) return H5Live.Utils.Log(i, "The same containerOrId has existed error~"), !1;
|
|
var n = a.id,
|
|
o = n;
|
|
return a.innerHTML = H5Live.Plug.GetHtml({
|
|
pname: "wnd",
|
|
domid: o,
|
|
domname: n
|
|
}), (this.video_object = a.firstChild || document.getElementById(o + "_video"), this.video_object.setAttribute("x-webkit-airplay", "allow"), this.video_object.setAttribute("playsinline", ""), this.video_object.setAttribute("webkit-playsinline", ""), this.video_object.setAttribute("x5-playsinline", ""), this.video_object.setAttribute("x5-video-player-type", "h5"), this.video_object.setAttribute("x5-video-player-fullscreen", !0), this.video_object.preload = "none", this.audio_object = a.lastChild || document.getElementById(o + "_audio"), this.audio_object.preload = "none", this.set_object_fit = function (e) {
|
|
try {
|
|
var e = e || "fill";
|
|
return -1 == H5Live.Utils.Array.indexOf(["fill", "contain", "cover", "none", "scale-down"], e) ? new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_FAILED) : (this.video_object && (this.video_object.style.object_fit = e), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS))
|
|
} catch (e) {
|
|
return new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, t && "object" === (void 0 === t ? "undefined" : _typeof(t)) && this.set_object_fit(t.object_fit || "fill"), a.firstChild || a.firstChild.id == o || document.getElementById(o)) ? (this.audio_object.src = URL.createObjectURL(this.audioMSE), this.audio_object.load(), this.video_object.src = URL.createObjectURL(this.videoMSE), this.video_object.load(), this.container = a || null, this.key = this.container.id, this.event_callback = t.callback || function () {
|
|
},
|
|
this.OpenVideo = function (e) {
|
|
try {
|
|
var t = "WND#OpenVideo";
|
|
e = e || {}, r.video.isPlaying && r.CloseVideo(), r.vod.isPlaying && r.CloseVod(), r.video.containerId = r.audio.containerId = e.containerId, r.video.puid = r.audio.puid = e.puid, r.video.type = r.audio.type = "IV", r.video.idx = r.audio.idx = e.idx, r.video.streamType = r.audio.streamType = e.streamType || "REALTIME", r.video.ws = new WebSocket(e.wsPath), r.video.ws.binaryType = "arraybuffer", r.video.ws.onopen = function (t) {
|
|
console.log("连接服务器成功"), r.event_callback.call(r, {
|
|
action: "ws.open",
|
|
type: "video",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, t || null)
|
|
});
|
|
var i = '<DstRes Type="IV" Idx="' + e.idx + '" PUID="' + e.puid + '" OptID="CTL_COMMONRES_StartStream_PushMode"> <Param StreamType="' + e.streamType + '" Mixed="1" DstType="' + e.dstType + '"></Param></DstRes>',
|
|
a = H5Live._make_ws_send_buffer(1, i);
|
|
r.video.ws.send(a);
|
|
var n = r.video_object.play();
|
|
n && n.catch(function (e) {
|
|
}), r.AddSourceBuffer("audio"), r.AddSourceBuffer("video")
|
|
}, r.video.ws.onclose = function (e) {
|
|
console.log("服务器关闭"), r.event_callback.call(r, {
|
|
action: "ws.close",
|
|
type: "video",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, r.video.ws.onerror = function (e) {
|
|
console.log("连接出错"), r.event_callback.call(r, {
|
|
action: "ws.error",
|
|
type: "video",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, r.video.ws.onmessage = function (e) {
|
|
try {
|
|
var i = new Uint8Array(e.data),
|
|
a = 0,
|
|
n = i[a++];
|
|
switch (n) {
|
|
case 8:
|
|
case 9:
|
|
var o = 8 == n ? "audio" : "video",
|
|
s = new Uint8Array(e.data, a);
|
|
a += 4;
|
|
var l = "playeaseMp4Segment";
|
|
102 === i[a] && 116 === i[a + 1] && 121 === i[a + 2] && 112 === i[a + 3] && (l = "playeaseMp4InitSegment");
|
|
var i = {
|
|
data: s,
|
|
tp: o,
|
|
type: l
|
|
};
|
|
if ("audio" == i.tp)
|
|
if ("playeaseMp4Segment" == l) {
|
|
if (i.data.info = i.info, r.audioSegments[i.tp].push(i.data), 0 == r.audioSegments[i.tp].length) return;
|
|
var c = r.audiosb[i.tp];
|
|
if (!c || c.updating) return;
|
|
var s = r.audioSegments[i.tp].shift();
|
|
try {
|
|
c.appendBuffer(s)
|
|
} catch (e) {
|
|
}
|
|
} else "playeaseMp4InitSegment" == l && r.audioSegments[i.tp].push(i.data);
|
|
else if ("playeaseMp4Segment" == l) {
|
|
if (i.data.info = i.info, r.videoSegments[i.tp].push(i.data), 0 == r.videoSegments[i.tp].length) return;
|
|
var c = r.videosb[i.tp];
|
|
if (!c || c.updating) return;
|
|
var s = r.videoSegments[i.tp].shift();
|
|
try {
|
|
c.appendBuffer(s), r.video.isPlaying || (r.video.isPlaying = !0, r.event_callback.call(r, {
|
|
action: "stream.start",
|
|
type: "video",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
}))
|
|
} catch (e) {
|
|
}
|
|
} else "playeaseMp4InitSegment" == l && r.videoSegments[i.tp].push(i.data);
|
|
break;
|
|
default:
|
|
H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message)
|
|
}
|
|
} catch (e) {
|
|
H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message)
|
|
}
|
|
}
|
|
} catch (e) {
|
|
H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message)
|
|
}
|
|
}, this.CloseVideo = function () {
|
|
try {
|
|
var e = "WND#CloseVideo";
|
|
if (null != r.video_object && (r.record.isRecording && r.CloseRecord(), r.audio.isPlaying && r.CloseAudio(), r.video.isPlaying)) {
|
|
if (r.video.ws.close(), r.video.ws = null, r.video.isPlaying = !1, r.videoMSE && "open" == r.videoMSE.readyState) {
|
|
for (var t = r.videoMSE.sourceBuffers.length, i = 0; i < t; i++) r.videoMSE.removeSourceBuffer(r.videoMSE.sourceBuffers[0]);
|
|
r.videoMSE.endOfStream(), r.videosb = {
|
|
video: null
|
|
}
|
|
}
|
|
r.videoSegments = {
|
|
video: []
|
|
}, r.video_object.pause(), r.videoMSE && (r.video_object.src = URL.createObjectURL(r.videoMSE)), r.video_object.load(), r.event_callback.call(r, {
|
|
action: "stream.stop",
|
|
type: "video",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
})
|
|
}
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excp error = " + t.name + "," + t.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, this.OpenVideo_IA = function (e) {
|
|
try {
|
|
var t = "WND#OpenVideo_IA";
|
|
e = e || {}, r.video.isPlaying && r.CloseVideo(), r.video_IA.isPlaying && r.CloseVideo_IA(), r.vod.isPlaying && r.CloseVod(), r.video_IA.isPlaying || (r.video_IA.isPlaying = !0), r.video_IA.containerId = e.containerId, r.video_IA.puid = e.puid, r.video_IA.type = "IV", r.video_IA.idx = e.idx, r.video_IA.streamType = e.streamType || "REALTIME", r.video_IA.ws = new WebSocket(e.wsPath), r.video_IA.ws.binaryType = "arraybuffer", r.video_IA.ws.onopen = function (t) {
|
|
console.log("连接服务器成功"), r.event_callback.call(r, {
|
|
action: "ws.open",
|
|
type: "video_IA",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, t || null)
|
|
});
|
|
var i = '<DstRes Type="IV" Idx="0" PUID="' + r.video_IA.puid + '" OptID="CTL_StartIA_Schedule"> <Param StreamType="' + e.streamType + '" Mixed="1"> <Alg>IA_FaceAndPlateDetect_XX</Alg> <APP APPIndex="" APPName="" AlgServerIndex=""></APP> <Src Type="1" DataSrc="0" PUID="' + r.video_IA.puid + '" ResType="IV" ResIdx="' + r.video_IA.idx + '" StreamType="' + e.streamType + '" UserToken="' + e.sessionID + '" /> </Param></DstRes>',
|
|
a = H5Live._make_ws_send_buffer(1, i);
|
|
r.video_IA.ws.send(a)
|
|
}, r.video_IA.ws.onclose = function (e) {
|
|
console.log("服务器关闭"), r.event_callback.call(r, {
|
|
action: "ws.close",
|
|
type: "video_IA",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, r.video_IA.ws.onerror = function (e) {
|
|
console.log("连接出错"), r.event_callback.call(r, {
|
|
action: "ws.error",
|
|
type: "video_IA",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, r.video_IA.ws.onmessage = function (e) {
|
|
try {
|
|
var i = 0,
|
|
a = 0,
|
|
n = 0,
|
|
o = 0,
|
|
s = 0,
|
|
l = null,
|
|
c = null,
|
|
d = null,
|
|
u = null,
|
|
v = {},
|
|
f = H5Live.Utils.ArrayBufferDataView(e.data.slice(37, 41), 0, 1);
|
|
if (7 === f) {
|
|
var m = H5Live.Utils.ArrayBufferDataView(e.data.slice(53, 57), 0, 1);
|
|
i = 65 + 92 * m, a = H5Live.Utils.ArrayBufferDataView(e.data.slice(61, 65), 0, 1), n = H5Live.Utils.ArrayBufferDataView(e.data.slice(65, 69), 0, 1), o = H5Live.Utils.ArrayBufferDataView(e.data.slice(69, 73), 0, 1), s = H5Live.Utils.ArrayBufferDataView(e.data.slice(73, 77), 0, 1), l = new DataView(e.data.slice(i)), c = new Blob([l]), d = null, u = new FileReader, u.addEventListener("load", function () {
|
|
d = u.result, v = {
|
|
SubType: f,
|
|
coordinate_x: a,
|
|
coordinate_y: n,
|
|
coordinate_w: o,
|
|
coordinate_h: s,
|
|
Pic: d
|
|
}, r.event_callback.call(r, {
|
|
action: "stream.response",
|
|
type: "video_IA",
|
|
instance: r,
|
|
data: v
|
|
})
|
|
}, !1), u.readAsDataURL(c)
|
|
} else if (6 === f) {
|
|
var p = H5Live.Utils.ArrayBufferDataView(e.data.slice(53, 57), 0, 1);
|
|
i = 65 + 96 * p, a = H5Live.Utils.ArrayBufferDataView(e.data.slice(61, 65), 0, 1), n = H5Live.Utils.ArrayBufferDataView(e.data.slice(65, 69), 0, 1), o = H5Live.Utils.ArrayBufferDataView(e.data.slice(69, 73), 0, 1), s = H5Live.Utils.ArrayBufferDataView(e.data.slice(73, 77), 0, 1), l = new DataView(e.data.slice(i)), c = new Blob([l]), d = null, u = new FileReader, u.addEventListener("load", function () {
|
|
d = u.result, v = {
|
|
SubType: f,
|
|
coordinate_x: a,
|
|
coordinate_y: n,
|
|
coordinate_w: o,
|
|
coordinate_h: s,
|
|
Pic: d
|
|
}, r.event_callback.call(r, {
|
|
action: "stream.response",
|
|
type: "video_IA",
|
|
instance: r,
|
|
data: v
|
|
})
|
|
}, !1), u.readAsDataURL(c)
|
|
} else if (5 === f) {
|
|
var m = H5Live.Utils.ArrayBufferDataView(e.data.slice(53, 57), 0, 1);
|
|
i = 69 + 476 * m;
|
|
var h = H5Live.Utils.ArrayBufferDataViewFloat(e.data.slice(57, 61), 0, 1);
|
|
a = H5Live.Utils.ArrayBufferDataView(e.data.slice(61, 65), 0, 1), n = H5Live.Utils.ArrayBufferDataView(e.data.slice(65, 69), 0, 1), o = H5Live.Utils.ArrayBufferDataView(e.data.slice(69, 73), 0, 1), s = H5Live.Utils.ArrayBufferDataView(e.data.slice(73, 77), 0, 1);
|
|
for (var g = new Uint8Array(e.data.slice(81, 113)), S = new Uint8Array(e.data.slice(213, 277)), y = new Uint8Array(e.data.slice(181, 213)), L = new Uint8Array(e.data.slice(277, 325)), b = 0, _ = 0; _ < 32; _++)
|
|
if (0 === parseInt(g[_])) {
|
|
b = _;
|
|
break
|
|
}
|
|
for (var C = 0, _ = 0; _ < 64; _++)
|
|
if (0 === parseInt(S[_])) {
|
|
C = _;
|
|
break
|
|
}
|
|
for (var w = 0, _ = 0; _ < 32; _++)
|
|
if (0 === parseInt(y[_])) {
|
|
w = _;
|
|
break
|
|
}
|
|
for (var H = 0, _ = 0; _ < 48; _++)
|
|
if (0 === parseInt(L[_])) {
|
|
H = _;
|
|
break
|
|
}
|
|
var A = new DataView(e.data.slice(81, 81 + b)),
|
|
R = new Blob([A]),
|
|
T = "",
|
|
U = new FileReader;
|
|
U.addEventListener("load", function () {
|
|
T = U.result;
|
|
var t = new DataView(e.data.slice(181, 181 + w)),
|
|
l = new Blob([t]),
|
|
c = "",
|
|
m = new FileReader;
|
|
m.addEventListener("load", function () {
|
|
c = m.result;
|
|
var t = new DataView(e.data.slice(213, 213 + C)),
|
|
l = new Blob([t]),
|
|
p = "",
|
|
g = new FileReader;
|
|
g.addEventListener("load", function () {
|
|
p = g.result;
|
|
var t = new DataView(e.data.slice(277, 277 + H)),
|
|
l = new Blob([t]),
|
|
m = "",
|
|
S = new FileReader;
|
|
S.addEventListener("load", function () {
|
|
m = S.result;
|
|
var t = H5Live.Utils.DateFormat("HH:mm:ss", new Date),
|
|
l = new DataView(e.data.slice(i)),
|
|
g = new Blob([l]);
|
|
d = null, u = new FileReader, u.addEventListener("load", function () {
|
|
d = u.result, v = {
|
|
SubType: f,
|
|
FaceScore: h,
|
|
coordinate_x: a,
|
|
coordinate_y: n,
|
|
coordinate_w: o,
|
|
coordinate_h: s,
|
|
Sex: T,
|
|
IDNumber: c,
|
|
UserName: p,
|
|
imageID: m,
|
|
Pic: d,
|
|
Time: t
|
|
}, r.event_callback.call(r, {
|
|
action: "stream.response",
|
|
type: "video_IA",
|
|
instance: r,
|
|
data: v
|
|
})
|
|
}, !1), u.readAsDataURL(g)
|
|
}, !1), S.readAsText(l, "UTF-8")
|
|
}, !1), g.readAsText(l, "GBK")
|
|
}, !1), m.readAsText(l, "UTF-8")
|
|
}, !1), U.readAsText(R, "GBK")
|
|
}
|
|
} catch (e) {
|
|
H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message)
|
|
}
|
|
}
|
|
} catch (e) {
|
|
H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message)
|
|
}
|
|
}, this.CloseVideo_IA = function () {
|
|
try {
|
|
var e = "WND#CloseVideo";
|
|
null != r.video_object && r.video_IA.isPlaying && (r.video_IA.ws.close(), r.video_IA.ws = null, r.video_IA.isPlaying = !1, r.event_callback.call(r, {
|
|
action: "stream.stop",
|
|
type: "video_IA",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
}))
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excp error = " + t.name + "," + t.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, this.OpenAudio = function () {
|
|
try {
|
|
var e = "WND#OpenAudio";
|
|
if (!r.video.isPlaying) return;
|
|
r.audio.isPlaying && r.CloseAudio(), r.audio.isPlaying = !0, r.audioSegments = {
|
|
audio: []
|
|
};
|
|
var t = r.audio_object.play();
|
|
t && t.catch(function (e) {
|
|
}), r.event_callback.call(r, {
|
|
action: "stream.start",
|
|
type: "audio",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
})
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excp error = " + t.name + "," + t.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, this.CloseAudio = function () {
|
|
try {
|
|
var e = "WND#CloseAudio";
|
|
if (null != r.audio_object && r.audio.isPlaying) {
|
|
if (r.audio.isPlaying = !1, r.audioMSE && "open" == r.audioMSE.readyState) {
|
|
for (var t = r.audioMSE.sourceBuffers.length, i = 0; i < t; i++) r.audioMSE.removeSourceBuffer(r.audioMSE.sourceBuffers[0]);
|
|
r.audioMSE.endOfStream(), r.audiosb = {
|
|
audio: null
|
|
}
|
|
}
|
|
r.audioSegments = {
|
|
audio: []
|
|
}, r.audio_object.pause(), r.audioMSE && (r.audio_object.src = URL.createObjectURL(r.audioMSE)), r.audio_object.load(), r.event_callback.call(r, {
|
|
action: "stream.stop",
|
|
type: "audio",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
})
|
|
}
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excp error = " + t.name + "," + t.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, this.OpenVod = function (e) {
|
|
try {
|
|
var t = "WND#OpenVod";
|
|
e = e || {}, r.video.isPlaying && r.CloseVideo(), r.vod.isPlaying && r.CloseVod();
|
|
var i = r.vod;
|
|
i.type = e.type || "platform", void 0 !== e.diskLetter && void 0 !== e.idx && (i.type = "device"), i.puid = e.puid, i.beginTime = e.beginTime, i.endTime = e.endTime, i.speed = e.speed || 1, "platform" == i.type ? (i.puid = i.puid || i.csuPuid || "", i.offsetTime = e.offsetTime || 0, i.fileName = e.fileName) : (i.diskLetter = e.diskLetter, i.idx = e.idx || 0), i.ws = new WebSocket(e.wsPath), i.ws.binaryType = "arraybuffer", i.ws.onopen = function (e) {
|
|
console.log("连接服务器成功"), r.event_callback.call(r, {
|
|
action: "ws.open",
|
|
type: "vod",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
});
|
|
var t = "";
|
|
t = "platform" == i.type ? H5Live.Utils.tpl('<DstRes Type="SC" Idx="0" PUID="{#csuPuid}" OptID="CTL_FileVod_PushMode"> <Param DiskLetter="" FileSystem="FAT32" IVIdx="" FileName="{#fileName}" BeginTime="{#beginTime}" EndTime="{#endTime}" Speed="{#speed}" OffsetTime="{#offsetTime}" ></Param></DstRes>', {
|
|
csuPuid: i.puid,
|
|
fileName: i.fileName,
|
|
beginTime: i.beginTime,
|
|
endTime: i.endTime,
|
|
speed: i.speed,
|
|
offsetTime: i.offsetTime
|
|
}) : H5Live.Utils.tpl('<DstRes Type="SC" Idx="0" PUID="{#puid}" OptID="CTL_FileVod_PushMode"> <Param DiskLetter="{#diskLetter}" FileSystem="" IVIdx="" FileName="" BeginTime="{#beginTime}" EndTime="{#endTime}" Speed="{#speed}" OffsetTime="{#offsetTime}" ></Param></DstRes>', {
|
|
puid: i.puid,
|
|
diskLetter: i.diskLetter,
|
|
idx: i.idx,
|
|
beginTime: i.beginTime,
|
|
endTime: i.endTime,
|
|
speed: i.speed
|
|
});
|
|
var a = H5Live._make_ws_send_buffer(1, t);
|
|
i.ws.send(a);
|
|
var n = r.video_object.play();
|
|
n && n.catch(function (e) {
|
|
}), r.AddSourceBuffer("audio"), r.AddSourceBuffer("video")
|
|
}, i.ws.onclose = function (e) {
|
|
console.log("服务器关闭"), r.event_callback.call(r, {
|
|
action: "ws.close",
|
|
type: "vod",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, i.ws.onerror = function (e) {
|
|
r.event_callback.call(r, {
|
|
action: "ws.error",
|
|
type: "vod",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, i.ws.onmessage = function (e) {
|
|
try {
|
|
var i = new Uint8Array(e.data),
|
|
a = 0,
|
|
n = i[a++];
|
|
switch (n) {
|
|
case 8:
|
|
case 9:
|
|
var o = 8 == n ? "audio" : "video",
|
|
s = new Uint8Array(e.data, a);
|
|
a += 4;
|
|
var l = "playeaseMp4Segment";
|
|
102 === i[a] && 116 === i[a + 1] && 121 === i[a + 2] && 112 === i[a + 3] && (l = "playeaseMp4InitSegment");
|
|
var i = {
|
|
data: s,
|
|
tp: o,
|
|
type: l
|
|
};
|
|
if ("audio" == i.tp)
|
|
if ("playeaseMp4Segment" == l) {
|
|
if (i.data.info = i.info, r.audioSegments[i.tp].push(i.data), 0 == r.audioSegments[i.tp].length) return;
|
|
var c = r.audiosb[i.tp];
|
|
if (!c || c.updating) return;
|
|
var s = r.audioSegments[i.tp].shift();
|
|
try {
|
|
c.appendBuffer(s)
|
|
} catch (e) {
|
|
}
|
|
} else "playeaseMp4InitSegment" == l && r.audioSegments[i.tp].push(i.data);
|
|
else if ("playeaseMp4Segment" == l) {
|
|
if (i.data.info = i.info, r.videoSegments[i.tp].push(i.data), 0 == r.videoSegments[i.tp].length) return;
|
|
var c = r.videosb[i.tp];
|
|
if (!c || c.updating) return;
|
|
var s = r.videoSegments[i.tp].shift();
|
|
try {
|
|
c.appendBuffer(s), 1 != r.vod.isPlaying && (r.vod.isPlaying = !0, r.event_callback.call(r, {
|
|
action: "stream.start",
|
|
type: "vod",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
}))
|
|
} catch (e) {
|
|
}
|
|
} else "playeaseMp4InitSegment" == l && r.videoSegments[i.tp].push(i.data);
|
|
break;
|
|
default:
|
|
H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message)
|
|
}
|
|
} catch (e) {
|
|
H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message)
|
|
}
|
|
}
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excep error = " + e.name + "," + e.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, this.CloseVod = function () {
|
|
try {
|
|
var e = "WND#CloseVod";
|
|
if (null != r.video_object && null != r.audio_object) {
|
|
var t = r.vod;
|
|
if (t.isPlaying) {
|
|
if (null != t.ws && (t.ws.close(), t.ws = null), t.isPlaying = !1, r.audioMSE && "open" == r.audioMSE.readyState) {
|
|
for (var i = r.audioMSE.sourceBuffers.length, a = 0; a < i; a++) r.audioMSE.removeSourceBuffer(r.audioMSE.sourceBuffers[0]);
|
|
r.audioMSE.endOfStream(), r.audiosb = {
|
|
audio: null
|
|
}
|
|
}
|
|
if (r.videoMSE && "open" == r.videoMSE.readyState) {
|
|
for (var i = r.videoMSE.sourceBuffers.length, a = 0; a < i; a++) r.videoMSE.removeSourceBuffer(r.videoMSE.sourceBuffers[0]);
|
|
r.videoMSE.endOfStream(), r.videosb = {
|
|
video: null
|
|
}
|
|
}
|
|
r.audioSegments = {
|
|
audio: []
|
|
}, r.videoSegments = {
|
|
video: []
|
|
}, r.video_object.pause(), r.audio_object.pause(), r.audioMSE && (r.audio_object.src = URL.createObjectURL(r.audioMSE)), r.videoMSE && (r.video_object.src = URL.createObjectURL(r.videoMSE)), r.video_object.load(), r.audio_object.load(), r.event_callback.call(r, {
|
|
action: "stream.stop",
|
|
type: "vod",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
})
|
|
}
|
|
}
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excep error = " + t.name + "," + t.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, this.Resize = function (e, t) {
|
|
try {
|
|
var i = "WND#Resize",
|
|
r = null,
|
|
a = null;
|
|
r = null == e || void 0 === e ? null : e, a = null == t || void 0 === t ? null : t;
|
|
var n = {
|
|
width: parseInt(this.container.offsetWidth) || "100%",
|
|
height: parseInt(this.container.offsetHeight) || "100%"
|
|
};
|
|
return null == r && (r = n.width), null == a && (a = n.height), r = String(r || 0).toLowerCase(), a = String(a || 0).toLowerCase(), -1 == r.search("%") && -1 == r.search("px") && -1 == r.search("em") && (r += "px"), -1 == a.search("%") && -1 == a.search("px") && -1 == a.search("em") && (a += "px"), this.video_object && (this.video_object.style.width = r, this.video_object.style.height = a), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(i + " -> Resize", "excp error = " + e.name + "," + e.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, this.AddSourceBuffer = function (e) {
|
|
try {
|
|
var t = e + '/mp4; codecs="' + r.metadata[e + "Codec"] + '"';
|
|
if (!MediaSource.isTypeSupported(t)) return;
|
|
var i = null;
|
|
if ("audio" == e) {
|
|
if (null != r.audiosb[e]) return;
|
|
i = r.audiosb[e] = r.audioMSE.addSourceBuffer(t)
|
|
} else {
|
|
if (null != r.videosb[e]) return;
|
|
i = r.videosb[e] = r.videoMSE.addSourceBuffer(t)
|
|
}
|
|
i.type = e, i.addEventListener("updateend", function (e) {
|
|
var t = e.target.type;
|
|
if ("audio" == t) var i = r.audiosb[t];
|
|
else var i = r.videosb[t];
|
|
if (i && !i.updating) {
|
|
if ("audio" == t) var a = r.audioSegments[t].shift();
|
|
else var a = r.videoSegments[t].shift();
|
|
try {
|
|
i.appendBuffer(a)
|
|
} catch (e) {
|
|
}
|
|
}
|
|
}), i.addEventListener("error", function (e) {
|
|
H5Live.Utils.Log("source buffer error")
|
|
})
|
|
} catch (e) {
|
|
H5Live.Utils.Log("WND::AddSourceBuffer", "excp error = " + e.name + "," + e.message)
|
|
}
|
|
}, this.Snapshot = function (e) {
|
|
void 0 === e && (e = {}), void 0 === e.imageType && (e.imageType = "image/png"), e.saveAsName || (e.saveAsName = "Snapshot_" + (new Date).getTime());
|
|
var t = document.createElement("canvas"),
|
|
i = t.getContext("2d");
|
|
if (t.width = this.video_object.videoWidth || 1280, t.height = this.video_object.videoHeight || 768, i.drawImage(this.video_object, 0, 0, this.video_object.videoWidth, this.video_object.videoHeight, 0, 0, this.video_object.videoWidth, this.video_object.videoHeight), window.navigator.msSaveOrOpenBlob) {
|
|
var r = t.msToBlob(e.imageType),
|
|
a = new Blob([r]);
|
|
window.navigator.msSaveOrOpenBlob(a, e.saveAsName + ".PNG")
|
|
} else {
|
|
var n = t.toDataURL(e.imageType),
|
|
o = document.createElement("a");
|
|
o.href = n, o.download = e.saveAsName, o.style.display = "none", o.addEventListener("click", function (e) {
|
|
e.stopPropagation()
|
|
}, !1), document.body.appendChild(o), o.click(), document.body.removeChild(o)
|
|
}
|
|
}, this.OpenRecord = function (e) {
|
|
try {
|
|
var t = "WND#OpenRecord";
|
|
if (e = e || {}, !r.video.isPlaying || r.record.isRecording) return !1;
|
|
var i = r.record;
|
|
i.puid = r.video.puid, i.idx = r.video.idx || 0, i.session = e.sessionID + "-" + i.puid + "-" + i.idx + "-" + (new Date).getTime(), i.ws = r.video.ws, r.event_callback.call(r, {
|
|
action: "stream.start",
|
|
type: "vod",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
});
|
|
var a = H5Live.Utils.tpl('<DstRes Type="IV" Idx="{#idx}" PUID="{#puid}" OptID="CTL_HTTPLite_FileRecord"> <Param Token="{#session}" Status="Start" ></Param></DstRes>', {
|
|
puid: i.puid,
|
|
idx: i.idx,
|
|
session: i.session
|
|
}),
|
|
n = H5Live._make_ws_send_buffer(1, a);
|
|
i.ws.send(n), r.record.isRecording = !0
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excep error = " + e.name + "," + e.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, this.CloseRecord = function () {
|
|
try {
|
|
var e = "WND#OpenRecord";
|
|
if (!r.video.isPlaying || !r.record.isRecording) return !1;
|
|
var t = r.record;
|
|
r.event_callback.call(r, {
|
|
action: "stream.stop",
|
|
type: "vod",
|
|
instance: r,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
});
|
|
var i = H5Live.Utils.tpl('<DstRes Type="IV" Idx="{#idx}" PUID="{#puid}" OptID="CTL_HTTPLite_FileRecord"> <Param Token="{#session}" Status="Stop" ></Param></DstRes>', {
|
|
puid: t.puid,
|
|
idx: t.idx,
|
|
session: t.session
|
|
}),
|
|
a = H5Live._make_ws_send_buffer(1, i);
|
|
t.ws.send(a), r.record.isRecording = !1
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excep error = " + t.name + "," + t.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, this.customParams = t || {}, this.Resize("100%", "100%"), this.errorCode = H5Live.ErrorCode.NRCAP_SUCCESS, H5Live.windowObjects.set(this.key, this), !0) : (H5Live.Utils.Log(i, "include wnd plugin error~"), !1)
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(i, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
},
|
|
Call: function (e, t) {
|
|
try {
|
|
var i = "H5Live.Call";
|
|
this.call = {
|
|
containerId: null,
|
|
puid: null,
|
|
idx: null,
|
|
type: "OA",
|
|
ws: null,
|
|
isPlaying: !1,
|
|
_cb: null
|
|
}, this.call.containerId = t.containerOrId, this.ObjectStore = {
|
|
AudioContext: window.AudioContext
|
|
}, this.track = e.getTracks()[0], this.customParams = t || {};
|
|
var r = null;
|
|
if ("object" === _typeof(t.containerOrId) && void 0 !== t.containerOrId.id) r = t.containerOrId;
|
|
else {
|
|
if (null == t.containerOrId || void 0 === t.containerOrId || null == document.getElementById(t.containerOrId)) return H5Live.Utils.Log(i, "containerOrId error~"), !1;
|
|
r = document.getElementById(t.containerOrId)
|
|
}
|
|
if (this.container = r || null, this.event_callback = t.callback || function () {
|
|
}, this.deviceSampleRate = 48e3, this.audioChannels = 1, this.ObjectStore.AudioContextConstructor || (this.ObjectStore.AudioContextConstructor = new this.ObjectStore.AudioContext), this.deviceSampleRate = this.ObjectStore.AudioContextConstructor.sampleRate, this.leftchannel = [], this.rightchannel = [], this.scriptprocessornode = null, this.recording = !1, this.recordingLength = 0, this.sampleRate = this.deviceSampleRate, this.mimeType = "audio/wav", this.isPCM = this.mimeType.indexOf("audio/pcm") > -1, this.numChannels = this.audioChannels || 2, this.RequestData = function () {
|
|
try {
|
|
var e = "CALL#RequestData";
|
|
if (a.isPaused) return;
|
|
if (0 === a.recordingLength) return void (a.requestDataInvoked = !1);
|
|
a.requestDataInvoked = !0;
|
|
var t = a.leftchannel.slice(0),
|
|
i = a.rightchannel.slice(0),
|
|
r = a.recordingLength;
|
|
a.leftchannel.length = a.rightchannel.length = [], a.recordingLength = 0, a.requestDataInvoked = !1;
|
|
var n = a.MergeBuffers(t, r),
|
|
o = n;
|
|
if (2 === a.numChannels) {
|
|
var s = a.MergeBuffers(i, r);
|
|
o = a.Interleave(n, s)
|
|
}
|
|
if (a.isPCM) {
|
|
var l = new Blob([a.ConvertoFloat32ToInt16(o)], {
|
|
type: "audio/pcm"
|
|
});
|
|
return void a.OnDataAvailable(l)
|
|
}
|
|
var c = new ArrayBuffer(44 + 2 * o.length),
|
|
d = new DataView(c);
|
|
this.WriteUTFBytes(d, 0, "RIFF"), d.setUint32(4, 44 + 2 * o.length - 8, !0), this.WriteUTFBytes(d, 8, "WAVE"), this.WriteUTFBytes(d, 12, "fmt "), d.setUint32(16, 16, !0), d.setUint16(20, 1, !0), d.setUint16(22, this.numChannels, !0), d.setUint32(24, this.sampleRate, !0), d.setUint32(28, this.sampleRate * this.numChannels * 2, !0), d.setUint16(32, 2 * this.numChannels, !0), d.setUint16(34, 16, !0), this.WriteUTFBytes(d, 36, "data"), d.setUint32(40, 2 * o.length, !0);
|
|
for (var u = o.length, v = 44, f = 0; f < u; f++) d.setInt16(v, 32767 * o[f], !0), v += 2;
|
|
var l = new Blob([d], {
|
|
type: "audio/wav"
|
|
});
|
|
a.OnDataAvailable(l)
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excp error = " + t.name + "," + t.message), !1
|
|
}
|
|
}, this.OnDataAvailable = function (e) {
|
|
try {
|
|
var t = "CALL#OnDataAvailable";
|
|
e && 1 === parseInt(a.call.ws.readyState) && (a.blobs.push(e), a.call.ws.send(e), a.call.isPlaying = !0)
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.OpenCall = function (e) {
|
|
try {
|
|
var t = "CALL#OpenCall";
|
|
a.recording = !0, a.leftchannel.length = a.rightchannel.length = 0, a.recordingLength = 0, a.options = e || {}, a.timeSlice = 100, a.call.puid = e.puid, a.call.type = "OA", a.call.idx = e.idx, a.call.streamType = e.streamType || "REALTIME", a.call.ws = new WebSocket(a.options.wsPath), a.call.ws.binaryType = "arraybuffer", a.call.ws.onopen = function (e) {
|
|
console.log("连接服务器成功"), a.event_callback.call(a, {
|
|
action: "ws.open",
|
|
type: "call",
|
|
instance: a,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
});
|
|
var t = '<DstRes Type="OA" Idx="' + a.options.idx + '" PUID="' + a.options.puid + '" OptID="CTL_OA_StartCall_PushMode"> <Param StreamType="' + a.options.streamType + '" Mixed="1"></Param></DstRes>',
|
|
i = H5Live._make_ws_send_buffer(1, t);
|
|
a.call.ws.send(i), a.interval = setInterval(function () {
|
|
a.RequestData()
|
|
}, a.timeSlice), setInterval(function () {
|
|
a.call && 1 === parseInt(a.call.ws.readyState) && a.call.ws.send(H5Live._make_ws_send_buffer(4, "<KeepAlive></KeepAlive>"))
|
|
}, 5e3)
|
|
}, a.call.ws.onclose = function (e) {
|
|
console.log("连接关闭"), a.event_callback.call(a, {
|
|
action: "ws.close",
|
|
type: "call",
|
|
instance: a,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
}), a.call.isPlaying && (a.call.isPlaying = !1, a.CloseCall())
|
|
}, a.call.ws.onerror = function (e) {
|
|
a.event_callback.call(a, {
|
|
action: "ws.error",
|
|
type: "call",
|
|
instance: a,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
}), console.log("连接出错")
|
|
}, a.call.ws.onmessage = function (e) {
|
|
}, a.event_callback.call(a, {
|
|
action: "stream.start",
|
|
type: "call",
|
|
instance: a,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
})
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.CloseCall = function () {
|
|
try {
|
|
var e = "CALL#CloseCall";
|
|
a.call.isPlaying && (a.call.isPlaying = !1, a.call.ws.close()), a.recording = !1, clearInterval(a.interval), a.RequestData(), a.audioInput.disconnect(), a.onstop(), a.track.stop(), a.event_callback.call(a, {
|
|
action: "stream.stop",
|
|
type: "call",
|
|
instance: a,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
})
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excp error = " + t.name + "," + t.message), !1
|
|
}
|
|
}, this.BytesToSize = function (e) {
|
|
try {
|
|
var t = "CALL#BytesToSize",
|
|
i = ["Bytes", "KB", "MB", "GB", "TB"];
|
|
if (0 === e) return "0 Bytes";
|
|
var r = parseInt(Math.floor(Math.log(e) / Math.log(1e3)), 10);
|
|
return (e / Math.pow(1e3, r)).toPrecision(3) + " " + i[r]
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.MergeBuffers = function (e, t) {
|
|
try {
|
|
for (var i = "CALL#MergeBuffers", r = new Float32Array(t), a = 0, n = e.length, o = 0; o < n; o++) {
|
|
var s = e[o];
|
|
r.set(s, a), a += s.length
|
|
}
|
|
return r
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(i, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.WriteUTFBytes = function (e, t, i) {
|
|
try {
|
|
for (var r = "CALL#WriteUTFBytes", a = i.length, n = 0; n < a; n++) e.setUint8(t + n, i.charCodeAt(n))
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(r, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.ConvertoFloat32ToInt16 = function (e) {
|
|
try {
|
|
for (var t = "CALL#ConvertoFloat32ToInt16", i = e.length, r = new Int16Array(i); i--;) r[i] = 65535 * e[i];
|
|
return r.buffer
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.context = this.ObjectStore.AudioContextConstructor, this.ObjectStore.VolumeGainNode = this.context.createGain(), this.volume = this.ObjectStore.VolumeGainNode, this.ObjectStore.AudioInput = this.context.createMediaStreamSource(e), this.audioInput = this.ObjectStore.AudioInput, this.audioInput.connect(this.volume), this.bufferSize = 2048, 0 === this.bufferSize && (this.bufferSize = 0), this.context.createJavaScriptNode) this.scriptprocessornode = this.context.createJavaScriptNode(this.bufferSize, this.numChannels, this.numChannels);
|
|
else {
|
|
if (!this.context.createScriptProcessor) throw "WebAudio API has no support on this browser.";
|
|
this.scriptprocessornode = this.context.createScriptProcessor(this.bufferSize, this.numChannels, this.numChannels)
|
|
}
|
|
this.bufferSize = this.scriptprocessornode.bufferSize, console.debug("using audio buffer-size:", this.bufferSize), this.requestDataInvoked = !1, window.scriptprocessornode = this.scriptprocessornode, 1 === this.numChannels && console.debug("All right-channels are skipped."), this.isPaused = !1, this.onstop = function () {
|
|
console.log("stopped..")
|
|
}, this.scriptprocessornode.onaudioprocess = function (e) {
|
|
if (a.recording && !a.requestDataInvoked && !a.isPaused) {
|
|
var t = e.inputBuffer.getChannelData(0);
|
|
if (a.leftchannel.push(new Float32Array(t)), 2 === a.numChannels) {
|
|
var i = e.inputBuffer.getChannelData(1);
|
|
a.rightchannel.push(new Float32Array(i))
|
|
}
|
|
a.recordingLength += a.bufferSize
|
|
}
|
|
}, this.volume.connect(this.scriptprocessornode), this.scriptprocessornode.connect(this.context.destination), this.options = {}, this.ws = null, this.blobs = [], this.interval = null;
|
|
var a = this
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(i, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
},
|
|
Talk: function (e, t) {
|
|
try {
|
|
var i = "H5Live.Talk";
|
|
this.talk = {
|
|
containerId: null,
|
|
puid: null,
|
|
idx: null,
|
|
type: "OA",
|
|
ws: null,
|
|
isPlaying: !1,
|
|
_cb: null
|
|
}, this.audio = {
|
|
containerId: null,
|
|
isPlaying: !1,
|
|
_cb: null
|
|
}, this.ObjectStore = {
|
|
AudioContext: window.AudioContext
|
|
}, this.track = e.getTracks()[0], this.talk.containerId = t.containerOrId, this.audioMSE = new MediaSource, this.audioSegments = {
|
|
audio: []
|
|
}, this.audiosb = {
|
|
audio: null
|
|
}, this.metadata = {
|
|
audioCodec: "mp4a.40.2"
|
|
}, this.audioMSE.addEventListener("sourceopen", function (e) {
|
|
n.AddSourceBuffer("audio")
|
|
}), this.customParams = t || {};
|
|
var r = null;
|
|
if ("object" === _typeof(t.containerOrId) && void 0 !== t.containerOrId.id) r = t.containerOrId;
|
|
else {
|
|
if (null == t.containerOrId || void 0 === t.containerOrId || null == document.getElementById(t.containerOrId)) return H5Live.Utils.Log(i, "containerOrId error~"), !1;
|
|
r = document.getElementById(t.containerOrId)
|
|
}
|
|
this.container = r || null, this.event_callback = t.callback || function () {
|
|
};
|
|
var a = r.id;
|
|
r.id;
|
|
if (this.audio_object = r.lastChild || document.getElementById(a + "_audio"), this.audio_object.src = URL.createObjectURL(this.audioMSE), this.audio_object.load(), this.deviceSampleRate = 48e3, this.audioChannels = 1, this.ObjectStore.AudioContextConstructor || (this.ObjectStore.AudioContextConstructor = new this.ObjectStore.AudioContext), this.deviceSampleRate = this.ObjectStore.AudioContextConstructor.sampleRate, this.leftchannel = [], this.rightchannel = [], this.scriptprocessornode = null, this.recording = !1, this.recordingLength = 0, this.sampleRate = this.deviceSampleRate, this.mimeType = "audio/wav", this.isPCM = this.mimeType.indexOf("audio/pcm") > -1, this.numChannels = this.audioChannels || 2, this.RequestData = function () {
|
|
try {
|
|
var e = "TALK#RequestData";
|
|
if (n.isPaused) return;
|
|
if (0 === n.recordingLength) return void (n.requestDataInvoked = !1);
|
|
n.requestDataInvoked = !0;
|
|
var t = n.leftchannel.slice(0),
|
|
i = n.rightchannel.slice(0),
|
|
r = n.recordingLength;
|
|
n.leftchannel.length = n.rightchannel.length = [], n.recordingLength = 0, n.requestDataInvoked = !1;
|
|
var a = n.MergeBuffers(t, r),
|
|
o = a;
|
|
if (2 === n.numChannels) {
|
|
var s = n.MergeBuffers(i, r);
|
|
o = n.Interleave(a, s)
|
|
}
|
|
if (n.isPCM) {
|
|
var l = new Blob([n.ConvertoFloat32ToInt16(o)], {
|
|
type: "audio/pcm"
|
|
});
|
|
return void n.OnDataAvailable(l)
|
|
}
|
|
var c = new ArrayBuffer(44 + 2 * o.length),
|
|
d = new DataView(c);
|
|
this.WriteUTFBytes(d, 0, "RIFF"), d.setUint32(4, 44 + 2 * o.length - 8, !0), this.WriteUTFBytes(d, 8, "WAVE"), this.WriteUTFBytes(d, 12, "fmt "), d.setUint32(16, 16, !0), d.setUint16(20, 1, !0), d.setUint16(22, this.numChannels, !0), d.setUint32(24, this.sampleRate, !0), d.setUint32(28, this.sampleRate * this.numChannels * 2, !0), d.setUint16(32, 2 * this.numChannels, !0), d.setUint16(34, 16, !0), this.WriteUTFBytes(d, 36, "data"), d.setUint32(40, 2 * o.length, !0);
|
|
for (var u = o.length, v = 44, f = 0; f < u; f++) d.setInt16(v, 32767 * o[f], !0), v += 2;
|
|
var l = new Blob([d], {
|
|
type: "audio/wav"
|
|
});
|
|
n.OnDataAvailable(l)
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excp error = " + t.name + "," + t.message), !1
|
|
}
|
|
}, this.OnDataAvailable = function (e) {
|
|
try {
|
|
var t = "TALK#OnDataAvailable";
|
|
e && n.talk.ws && 1 === parseInt(n.talk.ws.readyState) && (n.blobs.push(e), n.talk.ws.send(e), n.talk.isPlaying = !0)
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.OpenTalk = function (e) {
|
|
try {
|
|
var t = "TALK#OpenTalk";
|
|
n.audio.isPlaying && n.CloseAudio(), n.audio.isPlaying = !0, n.audioSegments = {
|
|
audio: []
|
|
}, n.recording = !0, n.leftchannel.length = n.rightchannel.length = 0, n.recordingLength = 0, n.options = e || {}, n.timeSlice = 100, n.talk.puid = e.puid, n.talk.type = "OA", n.talk.idx = e.idx, n.talk.streamType = e.streamType || "REALTIME", n.talk.ws = new WebSocket(n.options.wsPath), n.talk.ws.binaryType = "arraybuffer", n.talk.ws.onopen = function (e) {
|
|
console.log("连接服务器成功"), n.event_callback.call(n, {
|
|
action: "ws.open",
|
|
type: "talk",
|
|
instance: n,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
});
|
|
var t = '<DstRes Type="OA" Idx="' + n.options.idx + '" PUID="' + n.options.puid + '" OptID="CTL_OA_StartTalk_PushMode"> <Param StreamType="' + n.options.streamType + '" Mixed="1"></Param></DstRes>',
|
|
i = H5Live._make_ws_send_buffer(1, t);
|
|
n.talk.ws.send(i), setInterval(function () {
|
|
n.talk.ws && 1 === n.talk.ws.readyState && n.talk.ws.send(H5Live._make_ws_send_buffer(4, "<KeepAlive></KeepAlive>"))
|
|
}, 5e3);
|
|
var r = n.audio_object.play();
|
|
r && r.catch(function (e) {
|
|
}), n.AddSourceBuffer("audio"), n.event_callback.call(n, {
|
|
action: "stream.start",
|
|
type: "talk",
|
|
instance: n,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
}), n.interval = setInterval(function () {
|
|
n.RequestData()
|
|
}, n.timeSlice)
|
|
}, n.talk.ws.onclose = function (e) {
|
|
console.log("连接关闭"), n.event_callback.call(n, {
|
|
action: "ws.close",
|
|
type: "talk",
|
|
instance: n,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
}), n.talk.isPlaying && (n.talk.isPlaying = !1, n.CloseTalk())
|
|
}, n.talk.ws.onerror = function (e) {
|
|
n.event_callback.call(n, {
|
|
action: "ws.error",
|
|
type: "talk",
|
|
instance: n,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
}), console.log("连接出错")
|
|
}, n.talk.ws.onmessage = function (e) {
|
|
console.log(e.data);
|
|
var i = new Uint8Array(e.data),
|
|
r = 0,
|
|
a = i[r++];
|
|
switch (a) {
|
|
case 8:
|
|
var o = a = "audio",
|
|
s = new Uint8Array(e.data, r);
|
|
r += 4;
|
|
var l = "playeaseMp4Segment";
|
|
102 === i[r] && 116 === i[r + 1] && 121 === i[r + 2] && 112 === i[r + 3] && (l = "playeaseMp4InitSegment");
|
|
var i = {
|
|
data: s,
|
|
tp: o,
|
|
type: l
|
|
};
|
|
if ("playeaseMp4Segment" == l) {
|
|
if (i.data.info = i.info, n.audioSegments[i.tp].push(i.data), 0 == n.audioSegments[i.tp].length) return;
|
|
var c = n.audiosb[i.tp];
|
|
if (!c || c.updating) return;
|
|
var s = n.audioSegments[i.tp].shift();
|
|
try {
|
|
c.appendBuffer(s)
|
|
} catch (e) {
|
|
}
|
|
} else "playeaseMp4InitSegment" == l && n.audioSegments[i.tp].push(i.data);
|
|
break;
|
|
default:
|
|
H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message)
|
|
}
|
|
}
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.CloseTalk = function () {
|
|
try {
|
|
var e = "TALK#CloseTalk";
|
|
if (null != n.audio_object && n.audio.isPlaying) {
|
|
if (n.talk.ws.close(), n.talk.ws = null, n.audio.isPlaying = !1, n.audioMSE && "open" == n.audioMSE.readyState) {
|
|
for (var t = n.audioMSE.sourceBuffers.length, i = 0; i < t; i++) n.audioMSE.removeSourceBuffer(n.audioMSE.sourceBuffers[0]);
|
|
n.audioMSE.endOfStream(), n.audiosb = {
|
|
audio: null
|
|
}
|
|
}
|
|
n.audioSegments = {
|
|
audio: []
|
|
}, n.audio_object.pause(), n.audioMSE && (n.audio_object.src = URL.createObjectURL(n.audioMSE)), n.audio_object.load(), n.recording = !1, clearInterval(n.interval), n.RequestData(), n.audioInput.disconnect(), n.onstop(), n.track.stop(), n.event_callback.call(n, {
|
|
action: "stream.stop",
|
|
type: "talk",
|
|
instance: n,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS)
|
|
})
|
|
}
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excp error = " + t.name + "," + t.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, this.AddSourceBuffer = function (e) {
|
|
try {
|
|
var t = e + '/mp4; codecs="' + n.metadata[e + "Codec"] + '"';
|
|
if (!MediaSource.isTypeSupported(t)) return;
|
|
var i = null;
|
|
if (null != n.audiosb[e]) return;
|
|
i = n.audiosb[e] = n.audioMSE.addSourceBuffer(t), i.type = e, i.addEventListener("updateend", function (e) {
|
|
var t = e.target.type,
|
|
i = n.audiosb[t];
|
|
if (i && !i.updating) {
|
|
var r = n.audioSegments[t].shift();
|
|
try {
|
|
i.appendBuffer(r)
|
|
} catch (e) {
|
|
}
|
|
}
|
|
}), i.addEventListener("error", function (e) {
|
|
H5Live.Utils.Log("source buffer error")
|
|
})
|
|
} catch (e) {
|
|
H5Live.Utils.Log("WND::AddSourceBuffer", "excp error = " + e.name + "," + e.message)
|
|
}
|
|
}, this.Interleave = function (e, t) {
|
|
try {
|
|
for (var i = "TALK#Interleave", r = e.length + t.length, a = new Float32Array(r), n = 0, o = 0; o < r;) a[o++] = e[n], a[o++] = t[n], n++;
|
|
return a
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(i, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.MergeBuffers = function (e, t) {
|
|
try {
|
|
for (var i = "TALK#MergeBuffers", r = new Float32Array(t), a = 0, n = e.length, o = 0; o < n; o++) {
|
|
var s = e[o];
|
|
r.set(s, a), a += s.length
|
|
}
|
|
return r
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(i, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.WriteUTFBytes = function (e, t, i) {
|
|
try {
|
|
for (var r = "TALK#WriteUTFBytes", a = i.length, n = 0; n < a; n++) e.setUint8(t + n, i.charCodeAt(n))
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(r, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.ConvertoFloat32ToInt16 = function (e) {
|
|
try {
|
|
for (var t = "TALK#ConvertoFloat32ToInt16", i = e.length, r = new Int16Array(i); i--;) r[i] = 65535 * e[i];
|
|
return r.buffer
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.context = this.ObjectStore.AudioContextConstructor, this.ObjectStore.VolumeGainNode = this.context.createGain(), this.volume = this.ObjectStore.VolumeGainNode, this.ObjectStore.AudioInput = this.context.createMediaStreamSource(e), this.audioInput = this.ObjectStore.AudioInput, this.audioInput.connect(this.volume), this.bufferSize = 2048, 0 === this.bufferSize && (this.bufferSize = 0), this.context.createJavaScriptNode) this.scriptprocessornode = this.context.createJavaScriptNode(this.bufferSize, this.numChannels, this.numChannels);
|
|
else {
|
|
if (!this.context.createScriptProcessor) throw "WebAudio API has no support on this browser.";
|
|
this.scriptprocessornode = this.context.createScriptProcessor(this.bufferSize, this.numChannels, this.numChannels)
|
|
}
|
|
this.bufferSize = this.scriptprocessornode.bufferSize, console.debug("using audio buffer-size:", this.bufferSize), this.requestDataInvoked = !1, window.scriptprocessornode = this.scriptprocessornode, 1 === this.numChannels && console.debug("All right-channels are skipped."), this.isPaused = !1, this.onstop = function () {
|
|
console.log("stopped..")
|
|
}, this.scriptprocessornode.onaudioprocess = function (e) {
|
|
if (n.recording && !n.requestDataInvoked && !n.isPaused) {
|
|
var t = e.inputBuffer.getChannelData(0);
|
|
if (n.leftchannel.push(new Float32Array(t)), 2 === n.numChannels) {
|
|
var i = e.inputBuffer.getChannelData(1);
|
|
n.rightchannel.push(new Float32Array(i))
|
|
}
|
|
n.recordingLength += n.bufferSize
|
|
}
|
|
}, this.volume.connect(this.scriptprocessornode), this.scriptprocessornode.connect(this.context.destination), this.options = {}, this.ws = null, this.blobs = [], this.interval = null;
|
|
var n = this
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(i, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
},
|
|
CommandCommunicate: function (e) {
|
|
try {
|
|
var t = "H5Live.CommandCommunicate";
|
|
this.CommandWS = new WebSocket(e.wsPath), this.CommandWS.binaryType = "arraybuffer", this.event_callback = e.callback, this.CommandWS.onopen = function (t) {
|
|
console.log("连接服务器成功");
|
|
var r = '<Register SessionID="' + e.sessionID + '" UserName="' + e.chatName + '" ></Register>',
|
|
a = H5Live._make_ws_send_buffer(14, r);
|
|
i.CommandWS.send(a), setInterval(function () {
|
|
i.CommandWS && 1 === i.CommandWS.readyState && i.CommandWS.send(H5Live._make_ws_send_buffer(4, "<KeepAlive></KeepAlive>"))
|
|
}, 5e3), i.event_callback.call(i, {
|
|
action: "ws.open",
|
|
type: "command",
|
|
instance: i,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, t || null)
|
|
})
|
|
}, this.CommandWS.onclose = function (e) {
|
|
console.log("服务器关闭"), i.event_callback.call(i, {
|
|
action: "ws.close",
|
|
type: "command",
|
|
instance: i,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, this.CommandWS.onerror = function (e) {
|
|
console.log("连接出错"), i.event_callback.call(i, {
|
|
action: "ws.error",
|
|
type: "command",
|
|
instance: i,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, this.CommandWS.onmessage = function (e) {
|
|
var t = new DataView(e.data.slice(7, e.data.byteLength - 1)),
|
|
r = new Blob([t]),
|
|
a = new FileReader;
|
|
a.addEventListener("load", function () {
|
|
var e = a.result,
|
|
t = new DOMParser,
|
|
r = t.parseFromString(e, "text/xml");
|
|
switch (r.getElementsByTagName("DstRes")[0].getAttribute("OptID")) {
|
|
case "CTL_HTTPLite_P2PRequest":
|
|
var n = r.getElementsByTagName("Param")[0];
|
|
i.event_callback.call(i, {
|
|
action: "VideoChatRequest",
|
|
type: "command",
|
|
instance: i,
|
|
data: {
|
|
connect: n.getAttribute("Connect"),
|
|
srcID: n.getAttribute("SrcID"),
|
|
srcType: n.getAttribute("SrcType"),
|
|
dstID: n.getAttribute("DstID"),
|
|
dstType: n.getAttribute("DstType"),
|
|
resType: n.getAttribute("ResType"),
|
|
resIdx: n.getAttribute("ResIdx")
|
|
}
|
|
});
|
|
break;
|
|
case "CTL_HTTPLite_P2PResponse":
|
|
var n = r.getElementsByTagName("Param")[0];
|
|
i.event_callback.call(i, {
|
|
action: "VideoChatResponse",
|
|
type: "command",
|
|
instance: i,
|
|
data: {
|
|
connect: n.getAttribute("Connect"),
|
|
srcID: n.getAttribute("SrcID"),
|
|
srcType: n.getAttribute("SrcType"),
|
|
dstID: n.getAttribute("DstID"),
|
|
dstType: n.getAttribute("DstType"),
|
|
resType: n.getAttribute("ResType"),
|
|
resIdx: n.getAttribute("ResIdx"),
|
|
errorCode: n.getAttribute("ErrorCode")
|
|
}
|
|
});
|
|
break;
|
|
case "CTL_COMMONRES_ReqWebStream_PushMode":
|
|
var n = r.getElementsByTagName("Param")[0];
|
|
2 == parseInt(n.getAttribute("Mixed")) ? i.event_callback.call(i, {
|
|
action: "StartTalk",
|
|
type: "command",
|
|
instance: i,
|
|
data: {
|
|
streamType: n.getAttribute("StreamType"),
|
|
mixed: n.getAttribute("Mixed"),
|
|
dstType: n.getAttribute("DstType"),
|
|
ip: n.getAttribute("IP"),
|
|
port: n.getAttribute("Port"),
|
|
token: n.getAttribute("Token")
|
|
}
|
|
}) : i.event_callback.call(i, {
|
|
action: "ReqWebStream",
|
|
type: "command",
|
|
instance: i,
|
|
data: {
|
|
xml: e,
|
|
streamType: n.getAttribute("StreamType"),
|
|
mixed: n.getAttribute("Mixed"),
|
|
dstType: n.getAttribute("DstType"),
|
|
ip: n.getAttribute("IP"),
|
|
port: n.getAttribute("Port"),
|
|
token: n.getAttribute("Token")
|
|
}
|
|
});
|
|
break;
|
|
case "CTL_HTTPLite_GetH5ClientList":
|
|
var n = r.getElementsByTagName("H5Client"),
|
|
o = [];
|
|
n.each(function (e, t) {
|
|
o.push({
|
|
sessionID: t.getAttribute("SessionID"),
|
|
chatName: t.getAttribute("UserName"),
|
|
status: t.getAttribute("Status"),
|
|
nuid: t.getAttribute("NUID")
|
|
})
|
|
}), i.event_callback.call(i, {
|
|
action: "GetH5ClientList",
|
|
type: "command",
|
|
instance: i,
|
|
data: o
|
|
})
|
|
}
|
|
}, !1), a.readAsText(r, "UTF-8")
|
|
}, this.GetH5ClientList = function () {
|
|
try {
|
|
var e = "CommandCommunicate#GetH5ClientList",
|
|
t = H5Live._make_ws_send_buffer(1, '<DstRes OptID="CTL_HTTPLite_GetH5ClientList"></DstRes>');
|
|
i.CommandWS.send(t)
|
|
} catch (t) {
|
|
return H5Live.Utils.Log(e, "excp error = " + t.name + "," + t.message), !1
|
|
}
|
|
}, this.VideoChatRequest = function (e) {
|
|
try {
|
|
var t = "CommandCommunicate#VideoChatRequest",
|
|
r = '<DstRes Type="IV" Idx="' + e.resIdx + '" PUID="' + e.dstID + '" OptID="CTL_HTTPLite_P2PRequest"> <Param Connect="' + e.connect + '" SrcID="' + e.srcID + '" SrcType="' + e.srcType + '" DstID="' + e.dstID + '" DstType="' + e.dstType + '" ResType="' + e.resType + '" ResIdx="' + e.resIdx + '"></Param></DstRes>',
|
|
a = H5Live._make_ws_send_buffer(1, r);
|
|
i.CommandWS.send(a)
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.VideoChatResponse = function (e) {
|
|
try {
|
|
var t = "CommandCommunicate#VideoChatResponse",
|
|
r = '<DstRes Type="IV" Idx="' + e.resIdx + '" PUID="' + e.dstID + '" OptID="CTL_HTTPLite_P2PResponse"> <Param Connect="' + e.connect + '" SrcID="' + e.srcID + '" SrcType="' + e.srcType + '" DstID="' + e.dstID + '" DstType="' + e.dstType + '" ResType="' + e.resType + '" ResIdx="' + e.resIdx + '" ErrorCode="' + e.errorCode + '"></Param></DstRes>',
|
|
a = H5Live._make_ws_send_buffer(1, r);
|
|
i.CommandWS.send(a)
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
};
|
|
var i = this
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
},
|
|
GatherVideoStream: function (t, i) {
|
|
try {
|
|
var r = "H5Live.GatherVideoStream";
|
|
this.videoData = {
|
|
domID: null,
|
|
isPlaying: !1,
|
|
chunks: [],
|
|
ws: null,
|
|
_cb: null
|
|
}, this.videoObject = {
|
|
track: null,
|
|
mediaRecorder: null
|
|
}, this.videoObject.track = t.getTracks()[0], this.OpenGatherVideoStream = function (i) {
|
|
try {
|
|
var r = "GatherVideoStream#OpenGatherVideoStream";
|
|
if ("function" != typeof MediaRecorder.isTypeSupported) return alert("浏览器不支持"), !1;
|
|
if (MediaRecorder.isTypeSupported("video/webm;codecs=vp9")) var n = {
|
|
mimeType: "video/webm;codecs=h264"
|
|
};
|
|
else {
|
|
if (!MediaRecorder.isTypeSupported("video/webm;codecs=h264")) return !!MediaRecorder.isTypeSupported("video/webm;codecs=vp8") && (alert("浏览器不支持"), !1);
|
|
var n = {
|
|
mimeType: "video/webm;codecs=h264"
|
|
}
|
|
}
|
|
a.videoObject.mediaRecorder = new MediaRecorder(t, n), a.videoData.ws = new WebSocket(i.wsPath), a.videoData.ws.binaryType = "arraybuffer", a.videoData.ws.onopen = function (e) {
|
|
console.log("连接服务器成功");
|
|
var t = H5Live._make_ws_send_buffer(1, i.xml);
|
|
a.videoData.ws.send(t), a.event_callback.call(this, {
|
|
action: "ws.open",
|
|
type: "gatherVideo",
|
|
instance: this,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, a.videoData.ws.onclose = function (e) {
|
|
console.log("连接关闭"), a.event_callback.call(this, {
|
|
action: "ws.close",
|
|
type: "gatherVideo",
|
|
instance: this,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
}), a.videoData.isPlaying && (a.videoData.isPlaying = !1, a.CloseGatherVideo())
|
|
}, a.videoData.ws.onerror = function (e) {
|
|
a.event_callback.call(this, {
|
|
action: "ws.error",
|
|
type: "gatherVideo",
|
|
instance: this,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
}), console.log("连接出错")
|
|
}, a.videoData.ws.onmessage = function (e) {
|
|
}, a.videoData.domID = i.domID;
|
|
var o = document.getElementById(i.domID + "_video");
|
|
o.srcObject = t, o.play(), a.videoObject.mediaRecorder.start(25), a.videoObject.mediaRecorder.ondataavailable = function (e) {
|
|
a.videoData.chunks.push(e.data);
|
|
var t = new FileReader;
|
|
t.addEventListener("loadend", function () {
|
|
new Uint8Array(t.result);
|
|
if (t.result.byteLength > 0 && 1 == parseInt(a.videoData.ws.readyState)) {
|
|
var e = H5Live._make_ws_send_buffer(9, t.result, "gatherVideoStream");
|
|
a.videoData.ws.send(e)
|
|
}
|
|
}), t.readAsArrayBuffer(e.data)
|
|
}, a.event_callback.call(a, {
|
|
action: "stream.start",
|
|
type: "gatherVideo",
|
|
instance: a,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
}), a.videoObject.mediaRecorder.onerror = function (e) {
|
|
console.log("Error: " + e)
|
|
}, a.videoObject.mediaRecorder.onstart = function () {
|
|
console.log("Started & state = " + a.videoObject.mediaRecorder.state)
|
|
}, a.videoObject.mediaRecorder.onstop = function () {
|
|
console.log("Stopped & state = " + a.videoObject.mediaRecorder.state), a.videoData.chunks = []
|
|
}, a.videoObject.mediaRecorder.onpause = function () {
|
|
console.log("Paused & state = " + a.videoObject.mediaRecorder.state)
|
|
}, a.videoObject.mediaRecorder.onresume = function () {
|
|
console.log("Resumed & state = " + a.videoObject.mediaRecorder.state)
|
|
}, a.videoData.videoObject.onwarning = function (e) {
|
|
console.log("Warning: " + e)
|
|
}
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(r, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
}, this.CloseGatherVideoStream = function () {
|
|
try {
|
|
var t = "GatherVideoStream#CloseGatherVideo";
|
|
a.videoObject.mediaRecorder.stop(), a.videoObject.track.stop(), a.videoData.ws.close(), a.event_callback.call(a, {
|
|
action: "stream.stop",
|
|
type: "gatherVideo",
|
|
instance: a,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_ERROR_THREAD)
|
|
}
|
|
}, this.event_callback = i.callback || function () {
|
|
}, this.customParams = i || {};
|
|
var a = this;
|
|
return !0
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(r, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
},
|
|
DataNotify: function (e) {
|
|
try {
|
|
var t = "H5Live.DataNotify";
|
|
this.identity = e.identity || "admin", this.epId = e.epId || "system", this.NotifyWS = new WebSocket(e.wsPath), this.NotifyWS.binaryType = "arraybuffer", this.event_callback = e.callback, this.eventGPStore = [], this.NotifyWS.onopen = function (e) {
|
|
if (console.log("连接服务器成功"), setInterval(function () {
|
|
i.NotifyWS && 1 === i.NotifyWS.readyState && i.NotifyWS.send(H5Live._make_ws_send_buffer(4, "<KeepAlive></KeepAlive>"))
|
|
}, 5e3), -1 != jQuery.inArray(options.mode, ["event", "both"])) {
|
|
var t = '<DstRes Type="EVT" Flag="1"> <Param Identity="' + i.identity + '" EPID="' + i.epId + '"></Param></DstRes>';
|
|
H5Live._make_ws_send_buffer(12, t);
|
|
i.NotifyWS.send(send_buffer)
|
|
}
|
|
if (-1 != jQuery.inArray(options.mode, ["gps", "both"])) {
|
|
var t = '<DstRes Type="GPS" Flag="1"> <Param Identity="' + i.identity + '" EPID="' + i.epId + '"></Param></DstRes>';
|
|
H5Live._make_ws_send_buffer(12, t);
|
|
i.NotifyWS.send(send_buffer)
|
|
}
|
|
i.event_callback.call(i, {
|
|
action: "ws.open",
|
|
type: "notify",
|
|
instance: i,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, this.NotifyWS.onclose = function (e) {
|
|
console.log("服务器关闭"), i.event_callback.call(i, {
|
|
action: "ws.close",
|
|
type: "notify",
|
|
instance: i,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, this.NotifyWS.onerror = function (e) {
|
|
console.log("连接出错"), i.event_callback.call(i, {
|
|
action: "ws.error",
|
|
type: "notify",
|
|
instance: i,
|
|
data: new H5Live.Struct.ReturnValueStruct(H5Live.ErrorCode.NRCAP_SUCCESS, e || null)
|
|
})
|
|
}, this.NotifyWS.onmessage = function (e) {
|
|
var t = new DataView(e.data.slice(7, e.data.byteLength - 1)),
|
|
r = new Blob([t]),
|
|
a = new FileReader;
|
|
a.addEventListener("load", function () {
|
|
var e = a.result,
|
|
t = new DOMParser,
|
|
r = t.parseFromString(e, "text/xml");
|
|
r.getElementsByTagName("Msg")[0];
|
|
switch (dst.getAttribute("Name")) {
|
|
case "Event":
|
|
var n = r.getElementsByTagName("ID")[0],
|
|
o = r.getElementsByTagName("Time")[0],
|
|
s = r.getElementsByTagName("Level")[0],
|
|
l = r.getElementsByTagName("Src")[0],
|
|
c = r.getElementsByTagName("Description")[0];
|
|
i.event_callback.call(i, {
|
|
action: "EventNotify",
|
|
type: "notify",
|
|
instance: i,
|
|
data: {
|
|
id: n.val(),
|
|
time: o.val(),
|
|
level: s.val(),
|
|
srcIDType: l.getAttribute("SrcIDType"),
|
|
srcID: l.getAttribute("SrcID"),
|
|
resType: l.getAttribute("ResType"),
|
|
resIdx: l.getAttribute("ResIdx"),
|
|
description: c.val()
|
|
}
|
|
});
|
|
break;
|
|
case "GPS":
|
|
var d = r.getElementsByTagName("Param")[0],
|
|
u = r.getElementsByTagName("GPS"),
|
|
v = [];
|
|
u.each(function (e, t) {
|
|
v.push({
|
|
latitude: t.getAttribute("Latitude"),
|
|
longitude: t.getAttribute("Longitude"),
|
|
bearing: t.getAttribute("Bearing"),
|
|
speed: t.getAttribute("Speed"),
|
|
altitude: t.getAttribute("Altitude"),
|
|
gNNSType: t.getAttribute("GNNSType"),
|
|
offlineFlag: t.getAttribute("OfflineFlag"),
|
|
state: t.getAttribute("State"),
|
|
utc: t.getAttribute("UTC")
|
|
})
|
|
}), i.event_callback.call(i, {
|
|
action: "GPSNotify",
|
|
type: "notify",
|
|
instance: i,
|
|
data: {
|
|
puid: d.getAttribute("PUID"),
|
|
gpsData: v
|
|
}
|
|
})
|
|
}
|
|
}, !1), a.readAsText(r, "UTF-8")
|
|
}, this.OpenEventNotify = function () {
|
|
var e = '<DstRes Type="EVT" Flag="1"> <Param Identity="' + i.identity + '" EPID="' + i.epId + '"></Param></DstRes>';
|
|
H5Live._make_ws_send_buffer(12, e);
|
|
i.NotifyWS.send(send_buffer)
|
|
}, this.CloseEventNotify = function () {
|
|
var e = '<DstRes Type="EVT" Flag="0"> <Param Identity="' + i.identity + '" EPID="' + i.epId + '"></Param></DstRes>';
|
|
H5Live._make_ws_send_buffer(12, e);
|
|
i.NotifyWS.send(send_buffer)
|
|
}, this.OpenGPSNotify = function () {
|
|
var e = '<DstRes Type="GPS" Flag="1"> <Param Identity="' + i.identity + '" EPID="' + i.epId + '"></Param></DstRes>';
|
|
H5Live._make_ws_send_buffer(12, e);
|
|
i.NotifyWS.send(send_buffer)
|
|
}, this.CloseEventNotify = function () {
|
|
var e = '<DstRes Type="GPS" Flag="0"> <Param Identity="' + i.identity + '" EPID="' + i.epId + '"></Param></DstRes>';
|
|
H5Live._make_ws_send_buffer(12, e);
|
|
i.NotifyWS.send(send_buffer)
|
|
};
|
|
var i = this
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(t, "excp error = " + e.name + "," + e.message), !1
|
|
}
|
|
},
|
|
Struct: {
|
|
ReturnValueStruct: function (e, t) {
|
|
this.rv = e !== H5Live.ErrorCode.NRCAP_SUCCESS ? e || H5Live.ErrorCode.NRCAP_ERROR : H5Live.ErrorCode.NRCAP_SUCCESS, this.response = void 0 !== t ? t : ""
|
|
},
|
|
end: !0
|
|
},
|
|
ErrorCode: {
|
|
language: "zh_CN",
|
|
NRCAP_SUCCESS: 0,
|
|
NRCAP_FAILED: -1,
|
|
NRCAP_ERROR: 513,
|
|
NRCAP_ERROR_THREAD: 515,
|
|
NRCAP_LOAD_H5VIDEO_OBJECT_FAILED: 769,
|
|
NRCAP_ERROR_INTERFACE_UNDEFINED: 789,
|
|
end: !0
|
|
},
|
|
Utils: {
|
|
Log: function () {
|
|
},
|
|
stringFormatter: function (e) {
|
|
try {
|
|
var e = e || "";
|
|
if (!e) return e;
|
|
for (var t = 1; t <= arguments.length - 1; t++) {
|
|
var i = new RegExp("\\{" + (t - 1) + "\\}", "gm");
|
|
e = e.replace(i, arguments[t])
|
|
}
|
|
} catch (e) {
|
|
} finally {
|
|
return e || ""
|
|
}
|
|
},
|
|
template: function (e, t) {
|
|
try {
|
|
var e = e || "";
|
|
if (!e) return e;
|
|
for (var i in t) {
|
|
var r = t[i],
|
|
a = new RegExp("\\{#?" + i + "\\}", "gm");
|
|
e = e.replace(a, r)
|
|
}
|
|
} catch (e) {
|
|
} finally {
|
|
return e || ""
|
|
}
|
|
},
|
|
Timer: {
|
|
interval: 100,
|
|
count: 0,
|
|
timer: null,
|
|
events: null,
|
|
Start: function () {
|
|
try {
|
|
var e = "H5Live.Utils.Timer.Start";
|
|
return null == H5Live.Utils.Timer.timer && (H5Live.Utils.Timer.timer = setInterval(H5Live.Utils.Timer.Call, H5Live.Utils.Timer.interval)), !0
|
|
} catch (t) {
|
|
return H5Live.Utils.Log && H5Live.Utils.Log(e, "excp error = " + t.message + "::" + t.name), !1
|
|
}
|
|
},
|
|
Stop: function () {
|
|
try {
|
|
var e = "Utils.Timer.Stop";
|
|
return null != H5Live.Utils.Timer.timer && (clearInterval(H5Live.Utils.Timer.timer), H5Live.Utils.Timer.timer = null, H5Live.Utils.Timer.events = new H5Live.Utils.Hash, H5Live.Utils.Timer.count = 0), !0
|
|
} catch (t) {
|
|
return H5Live.Utils.Log && H5Live.Utils.Log(e, "excp error = " + t.message + "::" + t.name), !1
|
|
}
|
|
},
|
|
Set: function (e, t) {
|
|
try {
|
|
var i = "H5Live.Utils.Timer.Set";
|
|
return null != H5Live.Utils.Timer.events && H5Live.Utils.Timer.events instanceof H5Live.Utils.Hash || (H5Live.Utils.Timer.events = new H5Live.Utils.Hash), void 0 === H5Live.Utils.Timer.events ? (H5Live.Utils.Log && H5Live.Utils.Log(i, "H5Live.Utils.Timer.events undefined"), !1) : "object" !== (void 0 === t ? "undefined" : _typeof(t)) || "string" != typeof t.name || "function" != typeof t.fu ? (H5Live.Utils.Log && H5Live.Utils.Log(i, "cb struct error"), !1) : (H5Live.Utils.Timer.events.get(e) || H5Live.Utils.Timer.events.set(e, new H5Live.Utils.Hash), H5Live.Utils.Timer.events.get(e) && H5Live.Utils.Timer.events.get(e).set(t.name, {
|
|
name: t.name,
|
|
fu: t.fu,
|
|
interval: t.interval
|
|
}), !0)
|
|
} catch (e) {
|
|
return H5Live.Utils.Log && H5Live.Utils.Log(i, "excp error = " + e.message + "::" + e.name), !1
|
|
}
|
|
},
|
|
ContainsKey: function (e, t) {
|
|
try {
|
|
var i = "H5Live.Utils.Timer.ContainsKey";
|
|
return null != H5Live.Utils.Timer.events && H5Live.Utils.Timer.events instanceof H5Live.Utils.Hash || (H5Live.Utils.Timer.events = new H5Live.Utils.Hash), void 0 === H5Live.Utils.Timer.events ? (H5Live.Utils.Log && H5Live.Utils.Log(i, "H5Live.Utils.Timer.events undefined"), !1) : !!(H5Live.Utils.Timer.events.get(e) && t && H5Live.Utils.Timer.events.get(e).get(t)) || (H5Live.Utils.Log && H5Live.Utils.Log(i, "ev or cbName not exists"), !1)
|
|
} catch (e) {
|
|
return H5Live.Utils.Log && H5Live.Utils.Log(i, "excp error = " + e.message + "::" + e.name), !1
|
|
}
|
|
},
|
|
UnSet: function (e, t) {
|
|
try {
|
|
var i = "H5Live.Utils.Timer.UnSet";
|
|
return void 0 === H5Live.Utils.Timer.events ? (H5Live.Utils.Log && H5Live.Utils.Log(i, "H5Live.Utils.Timer.events undefined"), !1) : H5Live.Utils.Timer.events.get(e) ? "string" != typeof t ? (H5Live.Utils.Log && H5Live.Utils.Log(i, "cb name undefined"), !1) : (H5Live.Utils.Timer.events.get(e).unset(t), !0) : (H5Live.Utils.Log && H5Live.Utils.Log(i, "ev undefined"), !1)
|
|
} catch (e) {
|
|
return H5Live.Utils.Log && H5Live.Utils.Log(i, "excp error = " + e.message + "::" + e.name), !1
|
|
}
|
|
},
|
|
Call: function () {
|
|
try {
|
|
var e = "H5Live.Utils.Timer.Call";
|
|
return H5Live.Utils.Timer.count++, H5Live.Utils.Timer.events.each(function (e) {
|
|
var t = e.value;
|
|
t && "function" == typeof t.each && t.each(function (e) {
|
|
var t = e.value;
|
|
H5Live.Utils.Timer.count * H5Live.Utils.Timer.interval % t.interval == 0 && "function" == typeof t.fu && t.fu()
|
|
})
|
|
}), 1e8 == H5Live.Utils.Timer.count && (H5Live.Utils.Timer.count = 0), !0
|
|
} catch (t) {
|
|
return H5Live.Utils.Log && H5Live.Utils.Log(e, "excp error = " + t.message + "::" + t.name), !1
|
|
}
|
|
},
|
|
end: !0
|
|
},
|
|
Hash: function () {
|
|
var e = 0,
|
|
t = new Object;
|
|
this.set = function (i, r) {
|
|
if (void 0 === i || null == i || "" == i) return !1;
|
|
this.containsKey(i) || e++, t[i] = void 0 !== r ? r : null
|
|
}, this.unset = function (e) {
|
|
this.containsKey(e) && this.remove(e)
|
|
}, this.get = function (e) {
|
|
return this.containsKey(e) ? t[e] : null
|
|
}, this.remove = function (i) {
|
|
this.containsKey(i) && delete t[i] && e--
|
|
}, this.containsKey = function (e) {
|
|
return e in t
|
|
}, this.containsValue = function (e) {
|
|
for (var i in t)
|
|
if (t[i] == e) return !0;
|
|
return !1
|
|
}, this.keys = function () {
|
|
var e = new Array;
|
|
for (var i in t) e.push(i);
|
|
return e
|
|
}, this.values = function () {
|
|
var e = new Array;
|
|
for (var i in t) e.push(t[i]);
|
|
return e
|
|
}, this.size = function () {
|
|
return e || 0
|
|
}, this.clear = function () {
|
|
e = 0, t = new Object
|
|
}, this.inf = this._self = function () {
|
|
return t
|
|
}, this.each = function (e, i) {
|
|
var e = e || function () {
|
|
},
|
|
i = i || this,
|
|
r = 0;
|
|
for (var a in t) {
|
|
var n = {
|
|
key: a,
|
|
value: t[a]
|
|
};
|
|
if (e.call(i, n, r++)) break
|
|
}
|
|
r = 0
|
|
}, this.any = function (e, i) {
|
|
var e = e || function () {
|
|
},
|
|
i = i || this,
|
|
r = 0;
|
|
for (var a in t) {
|
|
var n = {
|
|
key: a,
|
|
value: t[a]
|
|
};
|
|
if (e.call(i, n, r++)) return !0
|
|
}
|
|
return !1
|
|
}, this.all = function (e, i) {
|
|
var e = e || function () {
|
|
},
|
|
i = i || this,
|
|
r = 0;
|
|
for (var a in t) {
|
|
var n = {
|
|
key: a,
|
|
value: t[a]
|
|
};
|
|
if (!e.call(i, n, r++)) return !1
|
|
}
|
|
return !0
|
|
}
|
|
},
|
|
Array: {
|
|
indexOf: function (e, t, i) {
|
|
try {
|
|
if (e && e.constructor == Array) {
|
|
var i = Number(i) || 0;
|
|
i = i < 0 ? Math.ceil(i) : Math.floor(i), i < 0 && (i += e.length);
|
|
for (var r = !1; i < e.length; i++)
|
|
if (i in e && e[i] === t) {
|
|
r = !0;
|
|
break
|
|
}
|
|
return r ? i : -1
|
|
}
|
|
return -1
|
|
} catch (e) {
|
|
return -1
|
|
}
|
|
},
|
|
lastIndexOf: function (e, t, i) {
|
|
try {
|
|
if (e && e.constructor == Array) {
|
|
var i = Number(i) || 0;
|
|
i = i < 0 ? Math.ceil(i) : Math.floor(i), isNaN(i) ? i = e.length - 1 : i < 0 ? i += e.length : i >= len && (i = e.length - 1);
|
|
for (var r = !1; i > -1; i--)
|
|
if (i in e && e[i] === t) {
|
|
r = !0;
|
|
break
|
|
}
|
|
return r ? i : -1
|
|
}
|
|
return -1
|
|
} catch (e) {
|
|
return -1
|
|
}
|
|
},
|
|
end: !0
|
|
},
|
|
DateFormat: function (e, t) {
|
|
return void 0 !== t && t instanceof Date || (t = new Date), void 0 !== e && "" != e && null != e || (e = "yyyy-MM-dd HH:mm:ss"), e.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|[m|M]{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function (e) {
|
|
var i = H5Live.Utils.Zeroize || function (e) {
|
|
return e
|
|
};
|
|
switch (e) {
|
|
case "d":
|
|
return t.getDate();
|
|
case "dd":
|
|
return i(t.getDate());
|
|
case "ddd":
|
|
return ["Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat"][t.getDay()];
|
|
case "dddd":
|
|
return ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"][t.getDay()];
|
|
case "M":
|
|
return t.getMonth() + 1;
|
|
case "MM":
|
|
return i(t.getMonth() + 1);
|
|
case "MMM":
|
|
return ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][t.getMonth()];
|
|
case "MMMM":
|
|
return ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][t.getMonth()];
|
|
case "yy":
|
|
return String(t.getFullYear()).substr(2);
|
|
case "yyyy":
|
|
return t.getFullYear();
|
|
case "h":
|
|
return t.getHours() % 12 || 12;
|
|
case "hh":
|
|
return i(t.getHours() % 12 || 12);
|
|
case "H":
|
|
return t.getHours();
|
|
case "HH":
|
|
return i(t.getHours());
|
|
case "m":
|
|
return t.getMinutes();
|
|
case "mm":
|
|
return i(t.getMinutes());
|
|
case "s":
|
|
return t.getSeconds();
|
|
case "ss":
|
|
return i(t.getSeconds());
|
|
case "l":
|
|
return i(t.getMilliseconds(), 3);
|
|
case "L":
|
|
var r = t.getMilliseconds();
|
|
return r > 99 && (r = Math.round(r / 10)), i(r);
|
|
case "tt":
|
|
return t.getHours() < 12 ? "am" : "pm";
|
|
case "TT":
|
|
return t.getHours() < 12 ? "AM" : "PM";
|
|
case "Z":
|
|
return t.toUTCString().match(/[A-Z]+$/);
|
|
default:
|
|
return e.substr(1, e.length - 2)
|
|
}
|
|
})
|
|
},
|
|
GetDateTimeUTCSeconds: function (e) {
|
|
return void 0 !== e && e instanceof Date || (e = new Date), e.getTime() / 1e3
|
|
},
|
|
DTStrToTimestamp: function (e) {
|
|
e = e.strip();
|
|
var t = new Date;
|
|
return /^((((1[6-9]|[2-9]\d)\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\d|3[01]))|(((1[6-9]|[2-9]\d)\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\d|30))|(((1[6-9]|[2-9]\d)\d{2})-0?2-(0?[1-9]|1\d|2[0-8]))|(((1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29)) (20|21|22|23|[0-1]?\d):[0-5]?\d:[0-5]?\d$/.test(e) ? new Date(e.substr(0, 4), parseInt(e.substr(5, 2), 10) - 1, e.substr(8, 2), e.substr(11, 2), e.substr(14, 2), e.substr(17, 2)) : t
|
|
},
|
|
Zeroize: function (e, t) {
|
|
t || (t = 2), e = String(e);
|
|
for (var i = 0, r = ""; i < t - e.length; i++) r += "0";
|
|
return r + e
|
|
},
|
|
NetToHost16: function (e) {
|
|
return (e = parseInt(e, 10)) << 8 & 65280 | e >> 8
|
|
},
|
|
NetToHost32: function (e) {
|
|
return (e = parseInt(e, 10)) << 24 | e << 8 & 16711680 | e >> 8 & 65280 | 255 & e >> 24
|
|
},
|
|
CheckByteLength: function (e, t, r) {
|
|
e || (e = "");
|
|
var a = e.length,
|
|
n = 0;
|
|
for (i = 0; i < a; i++) 0 != (65280 & e.charCodeAt(i)) && n++, n++;
|
|
return !(n > r || n < t)
|
|
},
|
|
GetStringRealLength: function (e) {
|
|
try {
|
|
var t = "H5Live.Utils.GetStringRealLength",
|
|
e = e || "",
|
|
r = e.length,
|
|
a = 0;
|
|
for (i = 0; i < r; i++) a++, 0 != (65280 & e.charCodeAt(i)) && a++;
|
|
return a
|
|
} catch (e) {
|
|
return H5Live.Utils.Log && H5Live.Utils.Log(t, "exception, error = " + e.name + "::" + e.message), ""
|
|
}
|
|
},
|
|
Regexs: {
|
|
domain: "^((https|http|ftp|rtsp|mms)?://)?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?(([0-9]{1,3}.){3}[0-9]{1,3}|([0-9a-z_!~*'()-]+.)*([0-9a-z][0-9a-z-]{0,61})?[0-9a-z].[a-z]{2,6})(:[0-9]{1,5})?((/?)|(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$",
|
|
guid: /^0x[a-z0-9]{32}$/i,
|
|
uint: /^[0-9]*$/,
|
|
puid: /^[A-Za-z0-9]+$/i,
|
|
strip: /(^\s*)|(\s*$)/g,
|
|
end: !0
|
|
},
|
|
UnicodetoUTF8: function (e) {
|
|
for (var t, i = "", r = 0; r < e.length; r++) t = e.charCodeAt(r), t <= 127 ? i += e.charAt(r) : t >= 128 && t <= 2047 ? (i += String.fromCharCode(t >> 6 & 31 | 192), i += String.fromCharCode(63 & t | 128)) : (i += String.fromCharCode(t >> 12 | 224), i += String.fromCharCode(t >> 6 & 63 | 128), i += String.fromCharCode(63 & t | 128));
|
|
return i
|
|
},
|
|
UTF8toUnicode: function (e) {
|
|
for (var t, i, r = "", a = 0, n = 0; n < e.length; n++) t = e.charCodeAt(n), 0 == a ? 224 == (224 & t) ? (a = 2, i = (15 & t) << 12) : 192 == (192 & t) ? (a = 1, i = (31 & t) << 6) : 0 == (128 & t) ? r += e.charAt(n) : a = 0 : 1 == a ? (a = 0, r += String.fromCharCode(i | 63 & t)) : 2 == a ? (a = 3, i |= (63 & t) << 6) : 3 == a ? (a = 0, r += String.fromCharCode(i | 63 & t)) : a = 0;
|
|
return r
|
|
},
|
|
UnicodetoGB2312: function (e) {
|
|
return unescape(e.replace(/\\u/gi, "%u"))
|
|
},
|
|
GB2312toUnicode: function (e) {
|
|
return escape(e).toLocaleLowerCase().replace(/%u/gi, "\\u")
|
|
},
|
|
ArrayBufferDataView: function (e, t, i) {
|
|
var r = new DataView(e);
|
|
return r.getUint32(t, i)
|
|
},
|
|
ArrayBufferDataViewFloat: function (e, t, i) {
|
|
var r = new DataView(e);
|
|
return r.getFloat32(t, i)
|
|
},
|
|
ReadAsArrayBuffer: function (e, t) {
|
|
var i = new FileReader;
|
|
i.onload = function () {
|
|
t(i.result)
|
|
}, i.readAsArrayBuffer(e)
|
|
},
|
|
end: !0
|
|
},
|
|
end: !0
|
|
};
|
|
!function () {
|
|
if (null === H5Live.windowObjects && (H5Live.windowObjects = new H5Live.Utils.Hash), H5Live.Utils.sf = H5Live.Utils.stringFormatter || {}, H5Live.Utils.tpl = H5Live.Utils.template || {}, String.prototype.Format = function () {
|
|
try {
|
|
for (var e = this || "", t = 0; t <= arguments.length - 1; t++) {
|
|
var i = new RegExp("\\{" + t + "\\}", "gm");
|
|
e = e.replace(i, arguments[t])
|
|
}
|
|
} catch (e) {
|
|
} finally {
|
|
return e || this || ""
|
|
}
|
|
}, String.Template = function (e) {
|
|
try {
|
|
var t = this || "";
|
|
for (var i in e) {
|
|
var r = e[i],
|
|
a = new RegExp("\\{#?" + i + "\\}", "gm");
|
|
t = t.replace(a, r)
|
|
}
|
|
} catch (e) {
|
|
} finally {
|
|
return t || this || ""
|
|
}
|
|
}, H5Live._make_ws_send_buffer = function (e, t, i) {
|
|
try {
|
|
var r = "H5Live._make_ws_send_buffer";
|
|
if (!e && 0 != e || !t) return null;
|
|
if (e = Number(e) || 0, i && "recorder" == i) var a = t.byteLength;
|
|
else if (i && "gatherVideoStream" == i) var a = t.byteLength;
|
|
else var a = t.length;
|
|
var n = new ArrayBuffer(5 + a);
|
|
new Uint8Array(n, 0, 1)[0] = 255 & e;
|
|
var o = new Uint8Array(n, 1, 4);
|
|
o[3] = a >> 24 & 255, o[2] = a >> 16 & 255, o[1] = a >> 8 & 255, o[0] = 255 & a;
|
|
var s = new Uint8Array(n, 5, a);
|
|
if (i && "recorder" == i)
|
|
for (var l = 0; l < a; l++) s[l] = t[l];
|
|
else if (i && "gatherVideoStream" == i)
|
|
for (var c = new Uint8Array(t), l = 0; l < a; l++) s[l] = c[l];
|
|
else
|
|
for (var l = 0; l < a; l++) s[l] = t.charCodeAt(l);
|
|
return n || null
|
|
} catch (e) {
|
|
return H5Live.Utils.Log(r, "excp error = " + e.name + "," + e.message), null
|
|
}
|
|
}, void 0 !== H5Live.Utils.Timer) {
|
|
var e = H5Live.Utils.Timer;
|
|
e.Start(), e.ContainsKey("_this_h5live", "ws") || e.Set("_this_h5live", {
|
|
name: "ws",
|
|
fu: function () {
|
|
H5Live.windowObjects && H5Live.windowObjects instanceof H5Live.Utils.Hash && H5Live.windowObjects.each(function (e) {
|
|
try {
|
|
var t = e.value;
|
|
if (null != t.video && null != t.video.ws && void 0 !== t.video.ws) {
|
|
var i = t.video.ws;
|
|
1 === i.readyState && i.send(H5Live._make_ws_send_buffer(4, "<KeepAlive></KeepAlive>"))
|
|
}
|
|
if (null != t.video_IA && null != t.video_IA.ws && void 0 !== t.video_IA.ws) {
|
|
var i = t.video_IA.ws;
|
|
1 === i.readyState && i.send(H5Live._make_ws_send_buffer(4, "<KeepAlive></KeepAlive>"))
|
|
}
|
|
if (null != t.vod && null != t.vod.ws && void 0 !== t.vod.ws) {
|
|
var i = t.vod.ws;
|
|
1 === i.readyState && i.send(H5Live._make_ws_send_buffer(4, "<KeepAlive></KeepAlive>"))
|
|
}
|
|
if (null != t.call && null != t.call.ws && void 0 !== t.call.ws) {
|
|
var i = t.call.ws;
|
|
1 === i.readyState && i.send(H5Live._make_ws_send_buffer(4, "<KeepAlive></KeepAlive>"))
|
|
}
|
|
if (null != t.talk && null != t.talk.ws && void 0 !== t.talk.ws) {
|
|
var i = t.talk.ws;
|
|
1 === i.readyState && i.send(H5Live._make_ws_send_buffer(4, "<KeepAlive></KeepAlive>"))
|
|
}
|
|
if (null != t.videoData && null != t.videoData.ws && void 0 !== t.videoData.ws) {
|
|
var i = t.videoData.ws;
|
|
1 === i.readyState && i.send(H5Live._make_ws_send_buffer(4, "<KeepAlive></KeepAlive>"))
|
|
}
|
|
} catch (e) {
|
|
H5Live.Utils.Log && H5Live.Utils.Log("_this_h5live::ws", H5Live.Utils.sf("excep, error = {0},{1}", e.name, e.message))
|
|
}
|
|
})
|
|
},
|
|
interval: 1e4
|
|
})
|
|
}
|
|
}(); |