Created
March 21, 2014 17:21
-
-
Save dmazin/9691209 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Screenleap() { | |
var aR = 5322; | |
var E = 5327; | |
var a8 = 3000; | |
var af = 1000; | |
var L = navigator.userAgent.toLowerCase(); | |
this.isMac = L.indexOf("mac") > -1; | |
this.isWin = L.indexOf("windows ") > -1; | |
this.isChrome = L.indexOf("chrome") > -1; | |
this.isFirefox = L.indexOf("firefox") > -1; | |
this.isSafari = L.toLowerCase().indexOf("safari") != -1 && !this.isChrome; | |
this.isMSIE = L.indexOf("msie") > -1 || L.indexOf("trident") > -1; | |
this.isClickOnce = this.isMSIE && L.indexOf(".net") != -1; | |
var ah = null; | |
var f = this.isSafari ? L.substring(L.indexOf("version") + 8, L.indexOf(" safari")) : null; | |
var o = this.isSafari ? f.split(".") : null; | |
var P = this.isSafari && (o.length >= 3 && o[0] >= 6 && o[2] >= 3 || o.length >= 2 && o[0] >= 6 && o[1] >= 1 || o.length >= 1 && o[0] >= 7); | |
var aM = this.isMac ? parseFloat(L.substring(L.indexOf("mac os x") + 9, L.indexOf(")")).replace(/_/g, ".").replace(";", "").replace(")", "")) : null; | |
var d = L.indexOf("trident") > -1; | |
var s = []; | |
var ag = null; | |
var aO = null; | |
var c = !this.isClickOnce; | |
var v = "hpcipbhehomfgjbgnajdhiahhdeeffbg"; | |
var ap = ""; | |
var K = null; | |
var a = false; | |
var at = null; | |
var av = null; | |
var a4 = null; | |
var M = null; | |
var h = null; | |
var aE = null; | |
var x = null; | |
var J = null; | |
var aK = null; | |
var V = null; | |
var ai = ""; | |
var aB = ""; | |
var aa; | |
var b = ""; | |
var l = ""; | |
var ak = null; | |
var a6 = null; | |
var am = null; | |
var k = null; | |
var T = null; | |
this.onScreenShareStart = function () { | |
alert("Your screen is now shared.") | |
}; | |
this.onScreenShareEnd = function () { | |
alert("Screen share ended.") | |
}; | |
this.onViewerConnect = function (ba, a9) {}; | |
this.onViewerDisconnect = function (ba, a9) {}; | |
this.onPause = function () {}; | |
this.onResume = function () {}; | |
this.error = function (bb, a9, ba) { | |
if (typeof ba == "undefined") { | |
alert("Error during " + bb + ". " + a9) | |
} else { | |
if (ba.status) { | |
alert("Error during " + bb + ", status code: " + ba.status) | |
} else { | |
if (ba.message) { | |
alert("Error during " + bb + ": " + ba.message) | |
} else { | |
alert("Error during " + bb + ". " + a9) | |
} | |
} | |
} | |
}; | |
this.setOptions = function (a9) { | |
if (typeof a9 != "undefined") { | |
if (typeof a9.webServerBaseUrl != "undefined") { | |
ag = a9.webServerBaseUrl | |
} | |
if (typeof a9.usePlugin != "undefined") { | |
ad("usePlugin = " + a9.usePlugin); | |
c = a9.usePlugin | |
} | |
if (typeof a9.startingWindowTitle != "undefined") { | |
aO = a9.startingWindowTitle | |
} | |
if (typeof a9.serverEnv != "undefined") { | |
ap = a9.serverEnv | |
} | |
if (typeof a9.chromeAppId != "undefined") { | |
v = a9.chromeAppId | |
} | |
if (typeof a9.bypassLocalCommunication != "undefined") { | |
a = a9.bypassLocalCommunication | |
} | |
if (typeof a9.downloadNativeTimeout != "undefined") { | |
aE = a9.downloadNativeTimeout | |
} | |
} | |
}; | |
this.isBrowserSupportedForExtension = function () { | |
return screenleap.isChrome || screenleap.isFirefox || P | |
}; | |
this.isBrowserSupportedForNative = function () { | |
return !(this.isWin && this.isMSIE && !d) | |
}; | |
this.isOSSupportedForNative = function () { | |
return this.isWin || (this.isMac && aM > 10.5) | |
}; | |
this.checkIsExtensionInstalled = function (a9, bb) { | |
if (screenleap.isChrome) { | |
var ba = new Image(); | |
ba.onload = function () { | |
if (typeof a9 == "function") { | |
a9() | |
} | |
}; | |
ba.onerror = function () { | |
if (typeof bb == "function") { | |
bb() | |
} | |
}; | |
try { | |
ba.src = "chrome-extension://" + v + "/screenleap_icon_16_16.png" | |
} catch (bc) { | |
screenleap.error("checkIsExtensionInstalled", "Error checking extension installation.", bc); | |
if (typeof bb == "function") { | |
bb() | |
} | |
} | |
} else { | |
screenleap.checkIsExtensionEnabled(a9, bb) | |
} | |
}; | |
this.checkIsExtensionEnabled = function (a9, bb, bd, ba) { | |
if (!bd) { | |
bd = 5 | |
} | |
if (!ba) { | |
ba = 1 | |
} | |
var bc = F(); | |
if (bc && bc.getAttribute("installed")) { | |
if (typeof a9 == "function") { | |
a9() | |
} | |
} else { | |
if (ba < bd) { | |
setTimeout(function () { | |
screenleap.checkIsExtensionEnabled(a9, bb, bd, ba + 1) | |
}, 1000) | |
} else { | |
if (typeof bb == "function") { | |
bb() | |
} | |
} | |
} | |
}; | |
this.installExtension = function (a9, ba, bb) { | |
if (this.isBrowserSupportedForExtension()) { | |
if (screenleap.isChrome) { | |
if (!bb) { | |
bb = window.location.href | |
} | |
r(aj() + "/install-extension?redirectUrl=" + bb); | |
aN(a9) | |
} else { | |
if (screenleap.isFirefox) { | |
try { | |
InstallTrigger.install({ | |
Screenleap: { | |
URL: "/ext/screenleap" + ab() + ".xpi" | |
} | |
}); | |
aN(a9, ba) | |
} catch (bc) { | |
if (typeof ba == "function") { | |
ba("Unexpected supported browser type.") | |
} else { | |
a2("installExtension", "Unexpected supported browser type.") | |
} | |
} | |
} else { | |
if (screenleap.isSafari) { | |
r(aj() + "/ext/screenleap" + ab() + ".safariextz"); | |
aN(a9) | |
} else { | |
if (typeof ba == "function") { | |
ba("Unexpected supported browser type.") | |
} else { | |
a2("installExtension", "Unexpected supported browser type.") | |
} | |
} | |
} | |
} | |
} else { | |
if (typeof ba == "function") { | |
ba("The extension is only available in Chrome, Firefox and some versions of Safari.") | |
} else { | |
a2("installExtension", "The extension is only available in Chrome, Firefox and some versions of Safari.") | |
} | |
} | |
}; | |
this.startSharing = function (ba, be, bc, bb) { | |
if (ba && ba == "DEFAULT") { | |
if (screenleap.isMac) { | |
ba = "NATIVE" | |
} else { | |
ba = "APPLET" | |
} | |
} | |
if (!ba || !e(ba)) { | |
a2("startSharing", "Invalid presenterAppType: " + ba); | |
return | |
} | |
if (be && !be.screenShareCode) { | |
a2("startSharing", "Missing mandatory screen share data."); | |
return | |
} | |
if (be && be.screenShareCode && !aP(be.screenShareCode)) { | |
a2("startSharing", "Screen share code is not valid: " + be.screenShareCode); | |
return | |
} else { | |
if (ba == "NATIVE") { | |
if (!a6 && (!be.presenterParams || !be.screenShareCode)) { | |
a2("startSharing", "Missing required information."); | |
return | |
} else { | |
if (!W()) { | |
return | |
} | |
} | |
} else { | |
if (ba == "EXTENSION") { | |
if (!be.screenShareCode) { | |
a2("startSharing", "Missing required information."); | |
return | |
} else { | |
if (!screenleap.isBrowserSupportedForExtension()) { | |
a2("startSharing", "This browser is not supported for the sharing extension."); | |
return | |
} | |
} | |
} else { | |
if (ba == "APPLET") { | |
if (!be.appletHtml) { | |
a2("startSharing", "Missing required information."); | |
return | |
} | |
} | |
} | |
} | |
} | |
D(); | |
K = ba; | |
if (be) { | |
a7(be) | |
} | |
var bd = bc ? bc.redirectUrl : null; | |
if (bc && typeof bc.nativeDownloadStarting == "function") { | |
ak = bc.nativeDownloadStarting | |
} | |
if (bc && typeof bc.nativeDownloaded == "function") { | |
a6 = bc.nativeDownloaded | |
} | |
if (bc && typeof bc.screenShareStarting == "function") { | |
am = bc.screenShareStarting | |
} | |
if (bc && typeof bc.pluginDisabled == "function") { | |
k = bc.pluginDisabled | |
} | |
if (bc && typeof bc.pluginEnabled == "function") { | |
T = bc.pluginEnabled | |
} | |
var a9 = bc ? bc.waitingForSafariExtensionToInstall : false; | |
if (bb) { | |
screenleap.setOptions(bb) | |
} | |
if (!ak && screenleap.onAppDownloadStart && typeof screenleap.onAppDownloadStart == "function") { | |
ak = screenleap.onAppDownloadStart | |
} | |
if (K == "EXTENSION") { | |
screenleap.checkIsExtensionEnabled(function () { | |
aL("share", be); | |
q() | |
}, function () { | |
if (a9) {} else { | |
if (ap == "dev" && !screenleap.isSafari) { | |
alert("Please install the extension before starting an extension share in dev mode") | |
} else { | |
screenleap.installExtension(function () { | |
aL("share", be) | |
}, function () { | |
a2("startSharing", "Unable to install screen sharing extension.") | |
}, bd) | |
} | |
} | |
}) | |
} else { | |
if (K == "NATIVE") { | |
aH(be) | |
} else { | |
if (K == "APPLET") { | |
F().innerHTML = be.appletHtml | |
} | |
} | |
} | |
}; | |
this.getPresenterAppType = function () { | |
return K | |
}; | |
this.getScreenShareCode = function () { | |
return x | |
}; | |
this.getViewerUrl = function () { | |
return J | |
}; | |
var a7 = function (a9) { | |
x = a9.screenShareCode; | |
ad("Extract data for share " + x); | |
J = a9.viewerUrl; | |
aK = a9.origin; | |
V = a9.browserMessageUrl; | |
ap = a9.serverEnv | |
}; | |
this.stopSharing = function () { | |
if (!K) { | |
screenleap.error("stopSharing", "Invalid share state.") | |
} else { | |
if (K == "NATIVE" || K == "APPLET") { | |
aU(1, false) | |
} else { | |
if (K == "EXTENSION") { | |
aL("stop"); | |
screenleap.endScreenShare({ | |
message: "API_CALL" | |
}) | |
} | |
} | |
} | |
}; | |
this.pauseSharing = function () { | |
if (K == "EXTENSION") { | |
a2("pauseSharing", "The pause call has not ben implemented for the browser extension.") | |
} else { | |
if (ae()) { | |
t("/pause/" + x) | |
} else { | |
aF("pa", null, function (a9) { | |
a2("pause", "Error processing pause request", a9) | |
}) | |
} | |
} | |
}; | |
this.resumeSharing = function () { | |
if (K == "EXTENSION") { | |
a2("resumeSharing", "The resume call has not been implemented for the browser extension.") | |
} else { | |
if (ae()) { | |
t("/resume/" + x) | |
} else { | |
aF("re", null, function (a9) { | |
a2("resume", "Error processing resume request", a9) | |
}) | |
} | |
} | |
}; | |
this.endScreenShare = function (a9) { | |
if (x) { | |
if (K == "NATIVE" && c) { | |
F().innerHTML = "" | |
} else { | |
if (K == "APPLET") { | |
F().innerHTML = "" | |
} | |
} if (ap == "stage") { | |
ay("End of screen share on staging") | |
} | |
D(); | |
if (a9) { | |
screenleap.onScreenShareEnd(a9.message) | |
} else { | |
screenleap.onScreenShareEnd() | |
} | |
s = [] | |
} | |
}; | |
this.downloadNativeApp = function (a9, bb, ba) { | |
D(); | |
if (typeof a9 != "function") { | |
a2("downloadNativeApp", "You need to pass in onAppDownloadEnd callback function"); | |
return | |
} | |
if (!W()) { | |
return | |
} | |
a6 = a9; | |
if (bb && typeof bb.downloadStarting == "function") { | |
ak = bb.downloadStarting | |
} | |
if (ba && typeof ba.downloadNativeTimeout != "undefined") { | |
aE = ba.downloadNativeTimeout | |
} | |
z() | |
}; | |
var z = function (a9) { | |
ad("Download native app"); | |
if (ak) { | |
ak() | |
} | |
if (aE && !screenleap.isClickOnce) { | |
setTimeout(function () { | |
aW(a9) | |
}, aE) | |
} else { | |
aW(a9) | |
} | |
}; | |
var aW = function (a9) { | |
aq(aj() + p(a9)); | |
if (c && a9) { | |
au(function () { | |
G(a9) | |
}); | |
return | |
} | |
if (screenleap.onAppDownloadEnd && typeof screenleap.onAppDownloadEnd == "function" && screenleap.isClickOnce) { | |
if (a9) { | |
if (!a9.alreadyDownloaded) { | |
if (screenleap.onAppDownloadEnd) { | |
screenleap.onAppDownloadEnd() | |
} | |
} | |
aT() | |
} else { | |
if (screenleap.onAppDownloadEnd) { | |
screenleap.onAppDownloadEnd() | |
} | |
} | |
} else { | |
if (a9 && screenleap.isClickOnce) { | |
aT() | |
} else { | |
A(a6) | |
} | |
} | |
}; | |
this.startNativeApp = function (ba, a9) { | |
a7(ba); | |
if (a9 && typeof a9.screenShareStarting == "function") { | |
am = a9.screenShareStarting | |
} | |
K = "NATIVE"; | |
j(ba) | |
}; | |
var F = function () { | |
var a9 = document.getElementById("screenleapDiv"); | |
if (!a9) { | |
ad("Make screenleapDiv"); | |
a9 = document.createElement("div"); | |
a9.id = "screenleapDiv"; | |
a9.setAttribute("style", "position:absolute;right:0px;bottom:0px;visibility:hidden;width:1px;height:1px;margin:0px;padding:0px;border:0px;"); | |
document.body.appendChild(a9) | |
} | |
return a9 | |
}; | |
var n = function () { | |
return document.getElementById("screenleapDiv") | |
}; | |
var aI = function (a9, ba) { | |
if (!K) { | |
if (typeof ba == "function") { | |
ba(xhr) | |
} | |
} else { | |
if (K == "EXTENSION") { | |
a2("status check", "This check is not valid for extension shares.") | |
} else { | |
if (K == "NATIVE" || K == "APPLET") { | |
w({ | |
url: i() + "/status" + (x ? "/" + x : ""), | |
type: "GET", | |
success: function (bb, bc) { | |
aZ(); | |
if (typeof a9 == "function") { | |
a9(bb, bc) | |
} | |
}, | |
error: function (bc) { | |
var bb = false; | |
if (x && bc) { | |
if (bc.status == 410) { | |
bb = true; | |
screenleap.endScreenShare({ | |
message: "LOCKED" | |
}) | |
} else { | |
if (bc.status == 400) { | |
bb = true; | |
a2(aB ? aB : "checkIsShareActive", "Screen share " + x + " is not running.") | |
} | |
} | |
} | |
if (!bb && a4 && b) { | |
if (typeof a9 == "function") { | |
ad("Local status check failed, but app server connection is active"); | |
if (bc) { | |
a9(bc.responseText, bc) | |
} else { | |
a9() | |
} | |
} else { | |
ad("Local status check failed, so asking app server"); | |
aV(a9, ba) | |
} | |
} else { | |
if (typeof ba == "function") { | |
ba(bc) | |
} else { | |
a2("checkIsShareActive", "Error checking app for status", bc) | |
} | |
} | |
} | |
}) | |
} | |
} | |
} | |
}; | |
var aF = function (bb, a9, ba) { | |
ad("Send call via app server: " + bb); | |
w({ | |
url: V + "/" + bb, | |
type: "GET", | |
success: function (bc) { | |
if (typeof a9 == "function") { | |
a9(bc) | |
} | |
}, | |
error: function (bc) { | |
if (typeof ba == "function") { | |
ba(bc) | |
} | |
} | |
}) | |
}; | |
var aU = function (a9, ba) { | |
ad("Send stop message to native"); | |
if (a) { | |
aF(ba ? "sa" : "sp", null, function (bb) { | |
a2("stop", "Error processing stop request", bb) | |
}) | |
} else { | |
w({ | |
url: i() + "/stop/" + x, | |
type: "POST", | |
success: function (bb) { | |
ad("Send successful stop message: " + bb) | |
}, | |
error: function () { | |
ad("Stopping share via app server because failed to do so via local web server"); | |
aF(ba ? "sa" : "sp", null, function (bb) { | |
if (!bb || (bb.status != 400 && bb.status != 403 && bb.status != 410)) { | |
a2("stop", "Error processing stop request as backup to local stop", bb) | |
} | |
}) | |
} | |
}) | |
} | |
}; | |
var N = function (a9) { | |
if (!a4) { | |
ad("Screen share started"); | |
screenleap.onScreenShareStart(a9); | |
a4 = new Date().getTime() | |
} | |
}; | |
var ax = function () { | |
return a4 && (Z() || ae()) | |
}; | |
var j = function (a9) { | |
ad("Send start message to presenter app"); | |
if (am) { | |
am() | |
} | |
setTimeout(function () { | |
var ba = "/start?presenterParams=" + a9.presenterParams; | |
if (aO) { | |
ba += "&startingWindowTitle=" + aO | |
} | |
a1(ba, X) | |
}, af) | |
}; | |
var r = function (a9) { | |
window.location.href = a9 | |
}; | |
var aq = function (a9) { | |
var bb = "hiddenDownloader", | |
ba = document.getElementById(bb); | |
if (ba === null) { | |
ba = document.createElement("iframe"); | |
ba.id = bb; | |
ba.style.display = "none"; | |
document.body.appendChild(ba) | |
} | |
ba.src = a9 | |
}; | |
var aQ = function (a9) { | |
if (!a) { | |
ad(a9 + ":Bypass local communication") | |
} | |
a = true | |
}; | |
var aZ = function () { | |
if (!at) { | |
ad("Local communication started") | |
} | |
at = new Date().getTime(); | |
aD(at) | |
}; | |
var ae = function () { | |
return aa && at ? new Date().getTime() - at < 2000 : false | |
}; | |
var B = function () { | |
return at | |
}; | |
var al = function () { | |
if (!av) { | |
ad("App server communication started") | |
} | |
av = new Date().getTime(); | |
aD(av) | |
}; | |
var Z = function () { | |
return b && av ? new Date().getTime() - av < 2000 : false | |
}; | |
var u = function () { | |
return av | |
}; | |
var aD = function (a9) { | |
M = a9 ? a9 : new Date().getTime() | |
}; | |
var a5 = function () { | |
return M ? (new Date().getTime() - M) / 1000 : 0 | |
}; | |
var ab = function () { | |
if (ap == "dev" || ap == "stage") { | |
return "_" + ap | |
} else { | |
return "" | |
} | |
}; | |
var D = function () { | |
ad("Reset share session"); | |
a3(); | |
aw(); | |
x = null; | |
J = null; | |
aK = null; | |
V = ""; | |
K = null; | |
a = false; | |
at = null; | |
av = null; | |
a4 = null; | |
M = null; | |
if (h) { | |
clearTimeout(h); | |
h = null | |
} | |
aE = null; | |
ak = null; | |
a6 = null; | |
am = null; | |
k = null; | |
T = null | |
}; | |
var p = function (bb) { | |
var a9 = (new Date()).getTime(); | |
if (screenleap.isMac) { | |
return "/share/mac?downloadTokenValue=" + a9 + (bb && bb.origin ? "&origin=" + bb.origin : "") | |
} else { | |
if (screenleap.isClickOnce && bb) { | |
var ba = ap ? "_" + ap : ""; | |
return "/public/windows/screenshare" + ba + "/screenshare" + ba + ".application?presenterParams=" + encodeURIComponent(bb.presenterParams) | |
} else { | |
return "/share/win?downloadTokenValue=" + a9 + (bb && bb.origin ? "&origin=" + bb.origin : "") + "&clickOnce=" + screenleap.isClickOnce + "&usePlugin=" + c | |
} | |
} | |
}; | |
var ac = function (a9) { | |
ad("Download and start native app"); | |
if (!a9 || !a9.alreadyDownloaded) { | |
if (!a6) { | |
a6 = function () { | |
j(a9) | |
} | |
} | |
z(a9) | |
} else { | |
j(a9) | |
} | |
}; | |
var y = function (a9) { | |
if (c && aJ() && F()) { | |
if (!g()) { | |
aC() | |
} | |
G(a9) | |
} else { | |
ac(a9) | |
} | |
}; | |
var aH = function (a9) { | |
ad("Start native app"); | |
if (screenleap.isMac) { | |
an(function () { | |
aZ(); | |
if (a9.startedFromApp) { | |
N(); | |
X() | |
} else { | |
j(a9) | |
} | |
}, function () { | |
y(a9) | |
}) | |
} else { | |
y(a9) | |
} | |
}; | |
var W = function () { | |
if (!screenleap.isBrowserSupportedForNative()) { | |
screenleap.error("startSharing", "This browser is not supported for the native sharing app.", { | |
message: "BROWSER_NOT_SUPPORTED" | |
}); | |
return false | |
} else { | |
if (!screenleap.isOSSupportedForNative()) { | |
screenleap.error("startSharing", "This OS is not supported for the native sharing app.", { | |
message: "OS_NOT_SUPPORTED" | |
}); | |
return false | |
} | |
} | |
return true | |
}; | |
var an = function (a9, ba) { | |
w({ | |
url: i() + "/status", | |
type: "POST", | |
success: a9, | |
error: ba | |
}) | |
}; | |
var i = function () { | |
if (!ah) { | |
var a9 = screenleap.isMac || window.location.protocol == "https:"; | |
ah = (a9 ? "https:" : "http:") + "//0111001101101100.com:" + (a9 ? "5327" : "5322") | |
} | |
return ah | |
}; | |
var Y = function () { | |
return window.location.host.indexOf("screenleap.com") != -1 | |
}; | |
var aj = function () { | |
return ag ? ag : S() | |
}; | |
var S = function () { | |
return Y() ? "" : window.location.protocol + "//" + (ap == "stage" ? "stage" : "www") + ".screenleap.com" | |
}; | |
var az = function (bc, ba) { | |
ad(ba + ": Process " + bc); | |
try { | |
var bf = JSON.parse(bc); | |
for (var a9 = 0; a9 < bf.length; a9++) { | |
if (x) { | |
var bb = bf[a9]; | |
switch (bb.type) { | |
case "ss": | |
N(bb); | |
break; | |
case "se": | |
if (bb.message && bb.message == "LOST_CONNECTION") { | |
ay("RECEIVED LOST_CONNECTION FROM POLLING RESPONSE") | |
} | |
screenleap.endScreenShare(bb); | |
break; | |
case "cn": | |
screenleap.onViewerConnect(bb.participantId, bb.externalId); | |
break; | |
case "dn": | |
screenleap.onViewerDisconnect(bb.participantId, bb.externalId); | |
break; | |
case "sp": | |
screenleap.onPause(); | |
break; | |
case "sr": | |
screenleap.onResume(); | |
break; | |
case "sa": | |
var be = (V.charAt(4) == "s" ? "https://" : "http://") + bb.hostname + V.substring(V.indexOf("/", V.indexOf("screenleap.com"))); | |
ad("Switching app servers to " + be); | |
V = be; | |
break; | |
default: | |
if (Y() && typeof screenleap.processResponse == "function") { | |
screenleap.processResponse(bb) | |
} | |
break | |
} | |
} | |
} | |
} catch (bd) {} | |
}; | |
var e = function (a9) { | |
return a9 == "EXTENSION" || a9 == "NATIVE" || a9 == "APPLET" | |
}; | |
var aL = function (bc, ba) { | |
if (ba) { | |
ba.action = bc | |
} else { | |
ba = { | |
action: bc | |
} | |
} | |
ba.origin = aK; | |
var bb = F(); | |
if (bb) { | |
var a9 = new CustomEvent("screenleapTrigger", { | |
detail: ba | |
}); | |
bb.dispatchEvent(a9) | |
} | |
}; | |
var aS = function (ba) { | |
var a9 = ba.detail; | |
if (a9) { | |
switch (a9.event) { | |
case "screenShareStarted": | |
if (screenleap.onScreenShareStart) { | |
screenleap.onScreenShareStart() | |
} | |
break; | |
case "screenShareStartFailed": | |
screenleap.error("startSharing", "Unable to start share", { | |
status: a9.status | |
}); | |
break; | |
case "screenShareStopped": | |
screenleap.endScreenShare(a9); | |
break; | |
case "viewerConnected": | |
screenleap.onViewerConnect(a9.participantId, a9.externalId); | |
break; | |
case "viewerDisconnected": | |
screenleap.onViewerDisconnect(a9.participantId, a9.externalId); | |
break; | |
default: | |
} | |
} | |
}; | |
var q = function () { | |
if (K == "EXTENSION") { | |
var a9 = n(); | |
if (a9) { | |
a9.addEventListener("screenleapExtensionEvent", aS) | |
} | |
} | |
}; | |
var aw = function () { | |
if (K == "EXTENSION") { | |
var a9 = n(); | |
if (a9) { | |
a9.removeEventListener("screenleapExtensionEvent", aS) | |
} | |
} | |
}; | |
var a1 = function (ba, a9, bb) { | |
if (!bb) { | |
bb = 0 | |
} | |
t(ba, a9, function (bc) { | |
if (bc && bc.status == 409) { | |
screenleap.endScreenShare({ | |
message: "CONFLICT" | |
}) | |
} else { | |
if (bc && bc.status == 400) { | |
screenleap.endScreenShare({ | |
message: "CONFLICT" | |
}) | |
} else { | |
setTimeout(function () { | |
a1(ba, a9, ++bb) | |
}, af) | |
} | |
} | |
}) | |
}; | |
var t = function (bb, a9, ba) { | |
w({ | |
url: i() + bb, | |
type: "POST", | |
success: function () { | |
aZ(); | |
if (typeof a9 == "function") { | |
a9() | |
} | |
}, | |
error: function (bc) { | |
if (typeof ba == "function") { | |
ba(bc) | |
} | |
} | |
}) | |
}; | |
var aP = function (a9) { | |
if (!a9) { | |
return false | |
} else { | |
a9 = "" + a9; | |
a9 = a9.replace(/ /g, ""); | |
return a9 && a9.length == 9 && /^[0-9]+$/.test(a9) | |
} | |
}; | |
var ao = function () { | |
return "withCredentials" in new XMLHttpRequest() | |
}; | |
var w = function (bb) { | |
var bc; | |
if (bb.params) { | |
bb.url += "?"; | |
for (var a9 in bb.params) { | |
bb.url += a9 + "=" + encodeURIComponent(bb.params[a9]) + "&" | |
} | |
bb.url = bb.url.slice(0, bb.url.length - 1) | |
} | |
if (!bb.type) { | |
bb.type = "GET" | |
} | |
if (bb.type == "GET") { | |
bb.url += (bb.url.indexOf("?") == -1 ? "?ts=" : "&ts=") + new Date().getTime() | |
} | |
if (ao()) { | |
bc = new XMLHttpRequest(); | |
bc.open(bb.type, bb.url, true); | |
bc.timeout = bb.timeout ? bb.timeout : a8; | |
if (bb.data) { | |
bc.setRequestHeader("Content-type", bb.contentType || "application/x-www-form-urlencoded") | |
} | |
if (bb.headers) { | |
for (var ba in bb.headers) { | |
bc.setRequestHeader(ba, bb.headers[ba]) | |
} | |
} | |
bc.onreadystatechange = function () { | |
if (bc.readyState == 4) { | |
if (bc.status == 200) { | |
if (bb.success) { | |
bb.success(bc.responseText, bc) | |
} | |
} else { | |
if (bb.error) { | |
bb.error(bc) | |
} | |
} | |
bc = null | |
} | |
}; | |
bc.send(bb.data) | |
} else { | |
if (typeof XDomainRequest != "undefined") { | |
bb.url += (bb.url.indexOf("?") == -1 ? "?" : "&") + "returnOkWithStatus=true"; | |
bc = new XDomainRequest(); | |
bc.open(bb.type || "GET", bb.url); | |
bc.onload = function () { | |
if (bc.responseText) { | |
var bd; | |
try { | |
bd = JSON.parse(bc.responseText) | |
} catch (be) { | |
ad("Failed to parse response " + bc.responseText) | |
} | |
if (bd && bd.status && bd.status != 200) { | |
if (bb.error) { | |
bb.error({ | |
status: bd.status, | |
reason: bd.reason | |
}) | |
} | |
bc = null; | |
return | |
} | |
} | |
if (bb.success) { | |
bb.success(bc.responseText) | |
} | |
bc = null | |
}; | |
bc.onerror = function () { | |
if (bb.error) { | |
bb.error() | |
} | |
bc = null | |
}; | |
bc.ontimeout = function () { | |
if (bb.error) { | |
bb.error() | |
} | |
bc = null | |
}; | |
bc.onprogress = function () {}; | |
bc.timeout = bb.timeout ? bb.timeout : a8; | |
setTimeout(function () { | |
bc.send(bb.data) | |
}, 0) | |
} | |
} | |
}; | |
var a0 = function () { | |
return screenleap.isWin ? "application/x-screenleap" + (ap ? "-" + ap : "") + "-1" : "application/x-screenleap-1-plugin" | |
}; | |
var aJ = function () { | |
navigator.plugins.refresh(false); | |
var bc = false; | |
var a9 = navigator.plugins; | |
var bb = a0(); | |
for (var ba = 0; ba < a9.length; ba++) { | |
if (screenleap.isWin) { | |
if (a9[ba][0]) { | |
var bd = a9[ba][0]; | |
if (bd.type == bb) { | |
bc = true; | |
break | |
} | |
} | |
} else { | |
if (a9[ba].name && a9[ba].description == "Screenleap Plugin 1.0.0") { | |
bc = true; | |
break | |
} | |
} | |
} | |
ad(bc ? "Plugin is installed" : "Plugin is not installed"); | |
return bc | |
}; | |
var aC = function () { | |
ad("Make plugin obj"); | |
F().innerHTML = ""; | |
navigator.plugins.refresh(false); | |
aY() | |
}; | |
var aY = function () { | |
F().innerHTML = '<object id="screenleapPluginObj" type="' + (a0()) + '" style="width:1px;height:1px"></object>' | |
}; | |
var g = function () { | |
return document.getElementById("screenleapPluginObj") | |
}; | |
var R = function (ba, bb, a9) { | |
if (ai) { | |
if (ai == ba) { | |
if (aB != bb) { | |
a2(ba, "This action is already running. Try reloading the page for a fresh state.") | |
} | |
} else { | |
a2(ba, "Unable to run this action at the same time as " + ai) | |
} | |
} else { | |
ai = ba; | |
aB = bb; | |
aa = a9 ? a9 : false | |
} | |
}; | |
var C = function (a9) { | |
if (!a9 || ai == a9 || aB == a9) { | |
ai = ""; | |
aB = "" | |
} | |
}; | |
var a3 = function () { | |
C(); | |
aa = false; | |
b = ""; | |
l = "" | |
}; | |
var Q = function (a9) { | |
if (aa && a) { | |
C(a9); | |
ad("Bypassing local communication - turn off poll " + ai) | |
} | |
return aB == a9 | |
}; | |
var aN = function (a9, ba) { | |
var bb = new Date().getTime(); | |
R("[waiting for extension installation]", bb); | |
aX(a9, ba, bb) | |
}; | |
var aX = function (a9, ba, bb) { | |
if (Q(bb)) { | |
setTimeout(function () { | |
screenleap.checkIsExtensionInstalled(function () { | |
C(bb); | |
if (typeof a9 == "function") { | |
a9() | |
} | |
}, function () { | |
setTimeout(function () { | |
aX(a9, ba, bb) | |
}, 500) | |
}) | |
}, 1000) | |
} else { | |
if (typeof ba == "function") { | |
ba("Aborted waiting for extension installation.") | |
} | |
} | |
}; | |
var A = function (a9) { | |
if (!a) { | |
a1("/status", function () { | |
aZ(); | |
if (h) { | |
clearTimeout(h); | |
h = null | |
} | |
a9() | |
}) | |
} else { | |
ad("No local communication alternative for listening for app start.") | |
} | |
}; | |
var aT = function () { | |
if ("EXTENSION" == K) { | |
ad("ERROR: _waitForShareShareStart should not be called for extensions"); | |
return | |
} | |
var a9 = new Date().getTime(); | |
ad("Start polling for share start"); | |
if (!a) { | |
R("[waiting for share start]", a9, true); | |
O(a9) | |
} | |
setTimeout(function () { | |
I(a9) | |
}, 500) | |
}; | |
var O = function (a9) { | |
if (Q(a9)) { | |
aI(function (ba) { | |
C(a9); | |
if (ba) { | |
az(ba, "_pollForShareStartByLocalCommunication") | |
} | |
if (x) { | |
N(); | |
X() | |
} | |
}, function (ba) { | |
setTimeout(function () { | |
if (ba && (ba.status == 400)) { | |
C(a9) | |
} else { | |
O(a9) | |
} | |
}, 1000) | |
}) | |
} | |
}; | |
var X = function () { | |
N(); | |
ad("Start polling for share end"); | |
if (!a) { | |
R("[waiting for share end]", x, true); | |
H(x) | |
} | |
I(new Date().getTime()) | |
}; | |
var H = function (a9) { | |
if (Q(a9)) { | |
aI(function (bb) { | |
var ba = false; | |
aZ(); | |
if (bb) { | |
ad("Received message: " + bb); | |
ba = az(bb, "_pollForShareEndByLocalCommunication") | |
} | |
if (!ba && x) { | |
setTimeout(function () { | |
H(a9) | |
}, 1000) | |
} else { | |
ad("Share ended; stop polling"); | |
C(a9) | |
} | |
}, function (bb) { | |
if (bb && (bb.status == 404 || bb.status == 400)) { | |
C(a9); | |
screenleap.endScreenShare() | |
} else { | |
var ba = new Date().getTime(); | |
if (M && a5() > 30) { | |
ad("Lost local connection over 30s ago; switch to app server polling."); | |
C(a9); | |
aQ("_pollForShareEndByLocalCommunication"); | |
I(ba) | |
} else { | |
if (!a) { | |
ad("Lost local connection"); | |
setTimeout(function () { | |
H(a9) | |
}, 1000) | |
} else { | |
ad("Ignoring failed local poll because bypass is active.") | |
} | |
} | |
} | |
}) | |
} else { | |
ad("Stop polling local webserver for share end; poll cancelled") | |
} | |
}; | |
var au = function (a9) { | |
if (!ba) { | |
var ba = new Date().getTime(); | |
R("[waiting for plugin installation]", ba); | |
if (!aJ() && !g()) { | |
aC() | |
} | |
aA(a9, ba) | |
} | |
}; | |
var aA = function (a9, ba) { | |
if (Q(ba)) { | |
if (!aJ()) { | |
setTimeout(function () { | |
aA(a9, ba) | |
}, 2000) | |
} else { | |
C(); | |
a9() | |
} | |
} | |
}; | |
var G = function (ba) { | |
if (!l) { | |
ad("Start app by plugin"); | |
aC(); | |
var a9 = new Date().getTime(); | |
l = a9; | |
U(ba, a9, true) | |
} | |
}; | |
var U = function (bd, bc, ba) { | |
if (l && l == bc) { | |
aY(); | |
var bb = g(); | |
if (typeof bb.start == "undefined") { | |
if (ba && k) { | |
k() | |
} | |
setTimeout(function () { | |
U(bd, bc) | |
}, 2000) | |
} else { | |
if (!ba && T) { | |
T() | |
} | |
ad("start by plugin"); | |
var a9 = bb.start(screenleap.isWin ? "-pp " + bd.presenterParams : bd.presenterParams); | |
if (a9 == "success") { | |
if (am) { | |
am() | |
} | |
l = ""; | |
aT() | |
} else { | |
if (a9 == "init-failure") { | |
setTimeout(function () { | |
U(bd, bc, ba) | |
}, 1000) | |
} else { | |
l = ""; | |
a2("[start by plugin]", "Attempt to start Screenleap via the plugin was unsuccessful. Turning off usePlugin."); | |
screenleap.setOptions({ | |
usePlugin: false | |
}); | |
ac(bd) | |
} | |
} | |
} | |
} | |
}; | |
var aG = function () { | |
return a4 ? new Date().getTime() - a4 : 0 | |
}; | |
var I = function (ba, a9) { | |
if (V && (a || !B())) { | |
if (!b || b == ba) { | |
if (!b) { | |
ad("Start polling app server"); | |
b = ba | |
} | |
aV(function (bb) { | |
aD(); | |
az(bb, "_pollAppServerForMessages"); | |
if (!a && !B()) { | |
if (aG() > 500) { | |
aQ("_pollForShareEndByLocalCommunication") | |
} | |
} | |
setTimeout(function () { | |
I(ba) | |
}, 500) | |
}, function (bb) { | |
if (bb && bb.status == "400") { | |
setTimeout(function () { | |
I(ba) | |
}, 500) | |
} else { | |
if (bb && bb.status == "404") { | |
ad("Waiting for presenter..."); | |
setTimeout(function () { | |
I(ba) | |
}, 500) | |
} else { | |
if (bb && bb.status == "410") { | |
b = ""; | |
ad("Stop polling app server; share ended"); | |
screenleap.endScreenShare({ | |
message: "LOCKED" | |
}) | |
} else { | |
if (a9) { | |
if (a5() > 480) { | |
ad("Connection lost. Ending."); | |
ay("ENDING SHARE DUE TO LOST CONNECTION"); | |
screenleap.endScreenShare({ | |
message: "LOST_CONNECTION" | |
}) | |
} else { | |
setTimeout(function () { | |
I(ba, true) | |
}, 500) | |
} | |
} else { | |
if (a5() > 300) { | |
setTimeout(function () { | |
I(ba, true) | |
}, 500) | |
} else { | |
setTimeout(function () { | |
I(ba) | |
}, 500) | |
} | |
} | |
} | |
} | |
} | |
}, a9) | |
} | |
} else { | |
b = ""; | |
ad("Stop polling app server") | |
} | |
}; | |
var aV = function (a9, bb, ba) { | |
w({ | |
url: V + "?ts=" + new Date().getTime() + (!M || !a4 || ba ? "&isStart=true" : ""), | |
type: "GET", | |
timeout: 60000, | |
success: function (bc) { | |
if (typeof a9 == "function") { | |
a9(bc) | |
} | |
}, | |
error: function (bc) { | |
if (typeof bb == "function") { | |
bb(bc) | |
} | |
} | |
}) | |
}; | |
var ar = function () { | |
var ba = ""; | |
var bb = s; | |
s = []; | |
for (var a9 = 0; a9 < bb.length; a9++) { | |
ba += bb[a9] + "\n" | |
} | |
return ba | |
}; | |
var ay = function (a9) { | |
var ba = m(); | |
ba.error = a9; | |
w({ | |
url: S() + "/screen-share/log-js-email", | |
params: ba, | |
data: ar(), | |
type: "POST" | |
}) | |
}; | |
var m = function () { | |
return { | |
userAgent: L, | |
usePlugin: c, | |
presenterAppType: K, | |
bypassLocalCommunication: a, | |
localCommunicationStarted: B(), | |
appServerPollingStarted: u(), | |
localShareStartTime: a4, | |
lastAppMessageTimestamp: M, | |
screenShareCode: x, | |
serverEnv: ap, | |
pollingAction: ai, | |
appServerPollId: b, | |
pluginStartPollId: l, | |
isClickOnce: screenleap.isClickOnce, | |
isMac: screenleap.isMac, | |
isWin: screenleap.isWin | |
} | |
}; | |
var ad = function (a9) { | |
a9 = (new Date()).getTime() + ": " + a9; | |
if (ap == "stage" || ap == "dev") { | |
if (typeof console != "undefined" && typeof console.log == "function") { | |
console.log(a9) | |
} | |
} | |
s[s.length] = a9 | |
}; | |
var a2 = function (bb, ba, a9) { | |
ay(bb + ": " + ba + (a9 && a9.message ? " - " + a9.message : "") + (a9 && a9.status ? "; status code " + a9.status : "")); | |
screenleap.error(bb, ba, a9) | |
} | |
} | |
var screenleap = screenleap || new Screenleap(); | |
var screenleapShareCodeFieldAllowHandle = true; | |
function screenleapShareCodeFieldKeyUp(d, c) { | |
if (typeof isAndroid != "undefined" && isAndroid) { | |
return true | |
} | |
d = d ? d : window.event; | |
var a = window.event ? d.keyCode : d.which; | |
if (!d.ctrlKey && !d.altKey && !d.shiftKey && (a >= 33 && a <= 40)) { | |
return true | |
} | |
if (c.value.length > 0) { | |
var b = /^[0-9 ]+$/.test(c.value); | |
if (d.keyCode == 8) { | |
while (c.value.length > 0 && c.value.charAt(c.value.length - 1) == " ") { | |
c.value = c.value.substring(0, c.value.length - 1) | |
} | |
return true | |
} else { | |
if (d.keyCode == 13 && ((screenleapShareCodeFieldAllowHandle && !b) || c.value.length == 13)) { | |
return true | |
} | |
} | |
c.value = formatScreenleapShareCode(c.value) | |
} | |
return false | |
} | |
function formatScreenleapShareCode(e, f) { | |
var b = []; | |
var d = 0; | |
if (!f) { | |
f = getScreenleapShareCodeSeparator(e) | |
} | |
if (!screenleapShareCodeFieldAllowHandle) { | |
e = e.replace(/\D/g, "") | |
} | |
var a = /^[0-9 ]+$/.test(e); | |
if (a) { | |
for (var c = 0; c < e.length; c++) { | |
if (e.charAt(c) != " ") { | |
b.push(e.charAt(c)); | |
d++; | |
if (d > 0 && d < 9 && d % 3 == 0) { | |
b.push(f) | |
} else { | |
if (d == 9) { | |
break | |
} | |
} | |
} | |
} | |
var g = b.join(""); | |
if (e != g) { | |
return g | |
} | |
} | |
return e | |
} | |
function getScreenleapShareCodeSeparator(c) { | |
var d = ""; | |
var b = false; | |
for (var a = 0; a < c.length; a++) { | |
if (c.charAt(a) == " ") { | |
b = true; | |
d += " " | |
} else { | |
if (b) { | |
return d | |
} | |
} | |
} | |
return d == "" ? " " : d | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment