define(function (require, exports, module) {
function e() {
this.m_iCurPage = 0, this.m_aPlugins = [], h = 0, f = "", v = ""
}
var a, t, n, i, o, r, s, l, c, d, m, u, p, g, h, f, v;
a = require("jquery"), require("quickTime"), t = require("common"), n = require("service"), i = require("translator"), o = require("isapi/device"), r = require("utils"), s = require("dialog"), l = require("common/header"), m = require("common/tool"), c = require("common/channel"), d = require("common/plugin"), u = require("common/ptz"), p = require("isapi/response"), g = require("base64"), e.prototype = {
init: function () {
var e = this, a = i.getLanguage("Preview");
i.appendLanguage(a, t.m_oLanCommon), document.title = i.getValue("preview"), e.initLayout(), e.initController(), e.checkLoaded()
}, checkLoaded: function () {
var e = this;
setTimeout(function () {
if (n.m_oLoaded.bPlugin) {
var t = d.getLocalConfig(), i = r.parseXmlFromStr(t);
a(i).find("CaptureFileFormat").length > 0 && (h = r.nodeValue(i, "CaptureFileFormat", "i")), f = r.nodeValue(i, "CapturePath"), v = r.nodeValue(i, "RecordPath"), n.m_iStreamType = !o.m_oDeviceCapa.bSupportTransCode && r.nodeValue(a(i), "StreamType", "i") > 1 ? 0 : r.nodeValue(a(i), "StreamType", "i");
for (var s = 0; n.m_aChannelList.length > s; s++) n.m_aChannelList[s].iStreamType = n.m_iStreamType;
if (n.isSingleChannel()) {
var l = e.checkPlugins();
if (0 == l.length) return n.m_iPluginType = 4, void 0;
n.m_iPluginType = -1 != a.inArray("webcomponents", l) ? 4 : -1 != a.inArray("quicktime", l) ? 1 : -1 != a.inArray("vlc", l) ? 2 : -1 != a.inArray("mjpeg", l) ? 3 : 4
}
var p = r.nodeValue(a(i), "RealPlayAll", "i");
(1 === p || n.isSingleChannel()) && (e.startPlayAll(), 4 !== n.m_iPluginType && e.pluginChange(n.m_iPluginType)), c.update(), m.update(), u.update();
var g = decodeURI(document.URL);
if (g.indexOf("?") > -1) {
var y = r.getURIParam("open", g);
"" !== y && (y = y.match(/\{(.+)\}/), null !== y && setTimeout(function () {
for (var a = y[1].split(","), t = 0; a.length > t; t++) e.startPlay(parseInt(a[t], 10) - 1, t, !0);
c.update(), m.update(), u.update()
}, 100))
}
} else e.checkLoaded()
}, 10)
}, initLayout: function () {
var e = this, i = {
defaults: {spacing_open: 0, spacing_closed: 0},
north: {paneSelector: ".layout-north", size: 40},
west: {
paneSelector: ".layout-west", size: n.isSingleChannel() ? 15 : 200, onresize_end: function () {
c.resize()
}
},
center: {
paneSelector: ".layout-center",
childOptions: {
defaults: {spacing_open: 0},
center: {
paneSelector: ".layout-center-inner", onresize_end: function () {
m.hideSound(), e.sizeChange(n.m_iWndSizeMode)
}
},
south: {paneSelector: ".layout-south-inner", size: 40}
}
},
east: {
paneSelector: ".layout-east",
initClosed: n.isSingleChannel(),
size: 209,
spacing_open: t.m_bAnonymous ? 0 : 10,
spacing_closed: t.m_bAnonymous ? 0 : 10,
onresize_end: function () {
u.resize()
}
},
south: {paneSelector: ".layout-south", size: 30}
};
a("body").layout(i)
}, initController: function () {
var e = this;
t.m_bAnonymous || o.getPanoramicMapCap(), l.init("header", 0), c.init("channel", "preview", {
onPlay: function (a, t) {
e.startPlay(a, t), m.update(), u.update()
}, onRecord: function (a) {
e.startRecord(a), m.update()
}, onSelected: null, onChangeStream: function (a, t) {
e.channelStreamChange(a, t), m.update(), u.update()
}
}), m.init("tool", "preview", {
onPlayAll: function () {
e.startPlayAll(), c.update(), u.update()
}, onRecordAll: function () {
e.startRecordAll(), c.update()
}, onCapture: function () {
e.capture()
}, onEnableEzoom: function () {
e.enableEzoom()
}, onEnableRegionExposure: function () {
e.enableRegionExposure(), u.update()
}, onEnableRegionFocus: function () {
e.enableRegionFocus(), u.update()
}, onPrevPage: function () {
e.prevPage(), c.update()
}, onNextPage: function () {
e.nextPage(), c.update()
}, onArrangeWindow: function () {
e.m_iCurPage = 0, m.update(!0)
}, onStreamChange: function (a) {
e.streamChange(a), c.update()
}, onSizeChange: function (a) {
e.sizeChange(a)
}, onPluginChange: function (a) {
e.pluginChange(a)
}, onTalkChange: function (a, t, n, i) {
e.enableTalk(a, t, n, i)
}
});
var a = decodeURI(document.URL);
if (a.indexOf("?") > -1) {
var i = r.getURIParam("slice", a);
"" !== i && (n.m_iWndSplitMode = Math.ceil(Math.sqrt(parseInt(i, 10))))
}
d.init("plugin", n.m_iWndSplitMode, {
onGetSelectWndInfo: function (a) {
e.getSelectWndInfo(a), m.update(), u.update()
}, onPluginEventHandler: function (a, t, n) {
e.pluginEventHandler(a, t, n)
}, onZoomInfoCallback: function (a) {
e.zoomInfoCallback(a)
}, onPTZCtrlCallback: function (a, t, n) {
e.ptzCtrlCallback(a, t, n)
}
}), u.init("ptz")
}, unload: function () {
try {
d.stopRealPlayAll(), d.stopTalk()
} catch (e) {
}
}, pluginEventHandler: function (e, a) {
var t = this;
21 == e ? (s.tip(i.getValue("noEnoughSpace")), -1 !== n.m_aWndList[a].iChannelPlayIndex && n.m_aWndList[a].bRecord && setTimeout(function () {
t.startRecord(n.m_aWndList[a].iChannelPlayIndex), c.update(), m.update()
}, 500)) : 3 == e ? (t.enableTalk(0), s.tip(i.getValue("voiceTalkFailed"))) : 7 == e && s.tip(i.getValue("noStreamSecret"))
}, zoomInfoCallback: function (e) {
var l, c, d = n.m_aWndList[n.m_iWndIndex], m = n.m_aChannelList[d.iChannelPlayIndex].iId,
u = r.parseXmlFromStr(e);
if (d.bManualTrackEvidence) l = "
" + y.szFilePath + "
", 5), a("#openDirectory").click(function () { d.openDirectory(y.szDir) })), 0 === d.stop(y.iWndPlayIndex) && (n.m_aWndList[y.iWndPlayIndex].bPlay = !1, n.m_aWndList[y.iWndPlayIndex].bEzoom = !1, n.m_aWndList[y.iWndPlayIndex].bRegionExposure = !1, n.m_aWndList[y.iWndPlayIndex].bRegionFocus = !1, n.m_aWndList[y.iWndPlayIndex].iChannelId = -1, n.m_aWndList[y.iWndPlayIndex].iChannelPlayIndex = -1, n.m_aWndList[y.iWndPlayIndex].bAutoPan = !1, n.m_aWndList[y.iWndPlayIndex].bLight = !1, n.m_aWndList[y.iWndPlayIndex].bWiper = !1, n.m_aWndList[y.iWndPlayIndex].bManualTrack = !1, n.m_aWndList[y.iWndPlayIndex].b3DZoom = !1, n.m_aWndList[y.iWndPlayIndex].bPTZCtrl = !1, n.m_aWndList[y.iWndPlayIndex].bManualTrackEvidence = !1, y.bPlay = !1, n.m_oWndParams.iSoundWndIndex === n.m_aChannelList[e].iWndPlayIndex && (n.m_oWndParams.iSoundWndIndex = -1), y.iWndPlayIndex = -1, m.updateChannelCap(l)); else { if (_.bPlay) { if (_.bRecord && 0 === d.stopSave(l)) { n.m_aChannelList[_.iChannelPlayIndex].bRecord = !1, _.bRecord = !1; var S = _.iChannelPlayIndex; s.tip(i.getValue("recordSucceed") + "" + n.m_aChannelList[S].szFilePath + "
", 5), a("#openDirectory").click(function () { d.openDirectory(n.m_aChannelList[S].szDir) }) } 0 === d.stop(l) && (n.m_aChannelList[_.iChannelPlayIndex].bPlay = !1, _.bPlay = !1, _.bEzoom = !1, _.bRegionExposure = !1, _.bRegionFocus = !1, _.bAutoPan = !1, _.bLight = !1, _.bWiper = !1, _.bManualTrack = !1, _.bManualTrackEvidence = !1, _.b3DZoom = !1, _.bPTZCtrl = !1, n.m_oWndParams.iSoundWndIndex === oService.m_aChannelList[e].iWndPlayIndex && (n.m_oWndParams.iSoundWndIndex = -1)) } 0 === d.play(g, t.m_szPluginNamePwd, l, "", "") ? (y.bPlay = !0, y.iWndPlayIndex = l, _.iChannelId = y.iId, _.bPlay = !0, _.iChannelPlayIndex = e, m.updateChannelCap(l)) : c || s.tip(i.getValue("previewFailed")) } 3 === n.m_iWndSizeMode && m.sizeChange(3), m.isPlayOrRecord() } }, startPlayAll: function () { if (d.isInstalled()) { var e = this, a = n.m_iWndSplitMode * n.m_iWndSplitMode, t = n.m_aChannelList.length; if (n.m_oWndParams.bHasWndPlay) e.stopPlayAll(); else for (var i = !(1 >= t || 1 >= a), o = 0; t > o; o++) a > o && e.startPlay(o, o, i); e.isPlayOrRecord() } }, stopPlayAll: function () { var e = this, a = n.m_aChannelList.length; if (0 === d.stopRealPlayAll()) { for (var t = 0; a > t; t++) n.m_aChannelList[t].bPlay = !1, n.m_aChannelList[t].bRecord = !1, n.m_aChannelList[t].iWndPlayIndex = -1; for (var t = 0; n.m_iMaxWndNum > t; t++) n.m_aWndList[t].bPlay = !1, n.m_aWndList[t].bRecord = !1, n.m_aWndList[t].bEzoom = !1, n.m_aWndList[t].bRegionExposure = !1, n.m_aWndList[t].bRegionFocus = !1, n.m_aWndList[t].iChannelId = -1, n.m_aWndList[t].iChannelPlayIndex = -1, n.m_aWndList[t].bAutoPan = !1, n.m_aWndList[t].bLight = !1, n.m_aWndList[t].bWiper = !1, n.m_aWndList[t].bManualTrack = !1, n.m_aWndList[t].b3DZoom = !1, n.m_aWndList[t].bPTZCtrl = !1, n.m_aWndList[t].bManualTrackEvidence = !1; n.m_oWndParams.iSoundWndIndex = -1, e.updateChannelCap(n.m_iWndIndex) } n.m_oWndParams.bHasWndRecord && s.tip(i.getValue("recordSucceed")) }, startRecord: function (e) { var o = this, l = "", c = "", m = new Date, u = n.m_aChannelList[e]; if (l = 0 > t.m_szHostName.indexOf("[") ? t.m_szHostName : t.m_szHostName.substring(1, t.m_szHostName.length - 1).replace(/:/g, "."), c = "zero" === u.szType ? l + "_" + u.szName.replace(/\s/g, "") + "_" + r.dateFormat(m, "yyyyMMddhhmmssS") : 9 >= u.iId ? l + "_0" + u.iId + "_" + r.dateFormat(m, "yyyyMMddhhmmssS") : l + "_" + u.iId + "_" + r.dateFormat(m, "yyyyMMddhhmmssS"), u.bPlay) if (u.bRecord) u.bRecord = !1, n.m_aWndList[u.iWndPlayIndex].bRecord = !1, 0 === d.stopSave(u.iWndPlayIndex) ? (s.tip(i.getValue("recordSucceed") + "" + u.szFilePath + "
", 5), a("#openDirectory").click(function () { d.openDirectory(n.m_aChannelList[e].szDir) })) : s.tip(i.getValue("recordfailed")); else { var p = d.startSave(u.iWndPlayIndex, c); if (0 == p) { u.bRecord = !0, n.m_aWndList[u.iWndPlayIndex].bRecord = !0, t.m_bAnonymous || WebSDK.WSDK_SetDeviceConfig(t.m_szHostName, "requestKeyFrame", { channel: u.iId, videoStream: u.iStreamType + 1 }, {async: !1}); var m = new Date; u.szFilePath = v + "\\" + r.dateFormat(m, "yyyy-MM-dd") + "\\" + c + ".mp4", u.szDir = v + "\\" + r.dateFormat(m, "yyyy-MM-dd") } else if (-1 === p) { var g = d.getLastError(); 10 === g || 9 === g ? s.tip(i.getValue("createFileFailed")) : s.tip(i.getValue("recordfailed")) } else -2 === p ? s.tip(i.getValue("noEnoughSpace")) : -3 === p && s.tip(i.getValue("createFileFailed")) } o.isPlayOrRecord() }, startRecordAll: function () { var e = this, a = n.m_iWndSplitMode * n.m_iWndSplitMode; if (n.m_oWndParams.bHasWndRecord) for (var t = 0; a > t; t++) n.m_aWndList[t].bRecord && e.startRecord(n.m_aWndList[t].iChannelPlayIndex); else for (var i = n.m_aChannelList.length, t = 0; i > t; t++) e.startRecord(t); e.isPlayOrRecord() }, capture: function () { var e = n.m_iWndIndex, o = n.m_aWndList[e], l = o.iChannelPlayIndex, c = n.m_aChannelList[l]; if (o.bPlay) { var m = new Date, u = "", p = "", g = ""; g = 0 > t.m_szHostName.indexOf("[") ? t.m_szHostName : t.m_szHostName.substring(1, t.m_szHostName.length - 1).replace(/:/g, "."), p = "zero" === c.szType ? g + "_" + c.szName.replace(/\s/g, "") + "_" + r.dateFormat(m, "yyyyMMddhhmmssS") : 9 >= o.iChannelId ? g + "_0" + o.iChannelId + "_" + r.dateFormat(m, "yyyyMMddhhmmssS") : g + "_" + o.iChannelId + "_" + r.dateFormat(m, "yyyyMMddhhmmssS"), u = f + "\\" + r.dateFormat(m, "yyyy-MM-dd") + "\\" + p + (1 == h ? ".bmp" : ".jpg"), p += 1 == h ? ".bmp" : ""; var v = d.capture(e, p); if (0 === v) { var y = f + "\\" + r.dateFormat(m, "yyyy-MM-dd"); s.tip(i.getValue("captureSucceeded") + "" + u + "
", 5), a("#openDirectory").click(function () { d.openDirectory(y) }) } else if (-1 === v) { var _ = d.getLastError(); 10 === _ || 9 === _ ? s.tip(i.getValue("createFileFailed")) : s.tip(i.getValue("captureFailed")) } else -2 === v ? s.tip(i.getValue("noEnoughSpace")) : -3 === v && s.tip(i.getValue("createFileFailed")) } }, enableEzoom: function () { var e = n.m_aWndList[n.m_iWndIndex]; e.bEzoom ? 0 === d.disableEzoom(n.m_iWndIndex) && (e.bEzoom = !1) : (n.disableEzoom(d), 0 === d.enableEzoom(n.m_iWndIndex, 0) && (e.bEzoom = !0)) }, enableRegionExposure: function () { var e = n.m_iWndIndex, a = n.m_aWndList[e]; a.bRegionExposure ? 0 === d.disableEzoom(e) && (a.bRegionExposure = !1) : (n.disableEzoom(d), 0 === d.enableEzoom(e, 1) && (a.bRegionExposure = !0)) }, enableRegionFocus: function () { var e = n.m_aWndList[n.m_iWndIndex], a = n.m_iWndIndex, e = n.m_aWndList[a]; e.bRegionFocus ? 0 === d.disableEzoom(a) && (e.bRegionFocus = !1) : (n.disableEzoom(d), 0 === d.enableEzoom(a, 1) && (e.bRegionFocus = !0)) }, prevPage: function () { var e = this, a = n.m_iWndSplitMode * n.m_iWndSplitMode, t = n.m_aChannelList.length, i = Math.ceil(t / a), o = t % a; if (0 === e.m_iCurPage) var r = 0; else var r = i - e.m_iCurPage + 1; if (r === i && (r = 0), n.m_oWndParams.bHasWndPlay && e.startPlayAll(), o > 0) if (0 === r) for (var s = 0; o > s; s++) e.startPlay(t - s - 1, o - s - 1); else for (var s = o + (r - 1) * a; t > s; s++) o + (r - 1) * a + a > s && e.startPlay(t - s - 1, a - (s - (o + (r - 1) * a)) - 1); else for (var s = r * a; t > s; s++) r * a + a > s && e.startPlay(t - s - 1, a - (s - r * a) - 1); t > r * a && (e.m_iCurPage = i - r) }, nextPage: function () { var e = this, a = n.m_iWndSplitMode * n.m_iWndSplitMode, t = n.m_aChannelList.length, i = Math.ceil(t / a); e.m_iCurPage === i && (e.m_iCurPage = 0), n.m_oWndParams.bHasWndPlay && e.startPlayAll(); for (var o = e.m_iCurPage * a; t > o; o++) e.m_iCurPage * a + a > o && e.startPlay(o, o - e.m_iCurPage * a); t > e.m_iCurPage * a && e.m_iCurPage++ }, sizeChange: function (e) { var i = !1, o = n.m_iWndIndex, r = n.m_aWndList[o], s = r.iChannelPlayIndex; if (s >= 0) { var l = n.m_aChannelList[s]; i = l.bCorridor } n.m_iWndSizeMode = e, a(".plugin").css({background: "#ffffff"}); var c = a("#plugin").width(), d = a("#plugin").height(); if (1 === e) i ? 4 * c / d > 3 ? a("#main_plugin").width(3 * d / 4).height(d) : a("#main_plugin").width(c).height(4 * c / 3) : 3 * c / d > 4 ? a("#main_plugin").width(4 * d / 3).height(d) : a("#main_plugin").width(c).height(3 * c / 4); else if (2 === e) i ? 16 * c / d > 9 ? a("#main_plugin").width(9 * d / 16).height(d) : a("#main_plugin").width(c).height(16 * c / 9) : 9 * c / d > 16 ? a("#main_plugin").width(16 * d / 9).height(d) : a("#main_plugin").width(c).height(9 * c / 16); else if (3 === e) { if (WebSDK.WSDK_GetDeviceConfig(t.m_szHostName, "StreamChannels", null, { async: !1, success: function (e, t) { var i = a(t).find("StreamingChannel").eq(n.m_iStreamType); c = parseInt(a(i).find("videoResolutionWidth").eq(0).text(), 10), d = parseInt(a(i).find("videoResolutionHeight").eq(0).text(), 10) } }), i) { var m = c; c = d, d = m } a("#main_plugin").width(c).height(d) } else 4 === e && a("#main_plugin").width("100%").height("100%") }, streamChange: function (e) { var t = this; a("#btn_stream_type i").eq(0).removeClass().addClass("icon-stream-" + e), n.m_iStreamType = e - 1; for (var i = 0; n.m_aChannelList.length > i; i++) n.m_aChannelList[i].iStreamType = e - 1; n.m_aWndList[n.m_iWndIndex].bPlay && 4 !== n.m_iPluginType && t.pluginChange(n.m_iPluginType) }, channelStreamChange: function (e, a) { var t = this, i = n.m_aChannelList[e]; i.iStreamType = a; var o = i.iWndPlayIndex; o > -1 && n.m_aWndList[o].bPlay && (t.startPlay(e, o), t.startPlay(e, o)) }, isPlayOrRecord: function () { for (var e = 0; 16 > e; e++) { if (n.m_aWndList[e].bPlay) { n.m_oWndParams.bHasWndPlay = !0; break } 15 === e && (n.m_oWndParams.bHasWndPlay = !1) } for (var e = 0; 16 > e; e++) { if (n.m_aWndList[e].bRecord) { n.m_oWndParams.bHasWndRecord = !0; break } 15 === e && (n.m_oWndParams.bHasWndRecord = !1) } }, pluginChange: function (e) { var i = this, r = ""; r = 0 === n.m_iStreamType ? "rtsp://" + t.m_szHostName + ":" + o.m_oDevicePort.iRtspPort + "/ISAPI/streaming/channels/101" : 1 === n.m_iStreamType ? "rtsp://" + t.m_szHostName + ":" + o.m_oDevicePort.iRtspPort + "/ISAPI/streaming/channels/102" : "rtsp://" + t.m_szHostName + ":" + o.m_oDevicePort.iRtspPort + "/ISAPI/streaming/channels/10" + (n.m_iStreamType + 1), 3 === e || t.m_bAnonymous || (r += "?auth=" + t.m_szNamePwd), 2 === e && t.m_bAnonymous && (r += "?auth=" + g.encode("anonymous:******")), n.m_oWndParams.bHasWndPlay && i.stopPlayAll(), n.m_oWndParams.bTalking && i.enableTalk(0), 1 === e ? (a("#main_plugin").html(""), a("#main_plugin").html("