2018-07-24 07:53:26 -05:00
|
|
|
/* -*- js-indent-level: 8 -*- */
|
2020-03-19 10:54:28 -05:00
|
|
|
/* global Uint8Array */
|
2018-04-12 14:57:00 -05:00
|
|
|
(function (global) {
|
|
|
|
|
2020-02-14 14:51:47 -06:00
|
|
|
var ua = navigator.userAgent.toLowerCase(),
|
|
|
|
uv = navigator.vendor.toLowerCase(),
|
|
|
|
doc = document.documentElement,
|
|
|
|
|
|
|
|
ie = 'ActiveXObject' in window,
|
|
|
|
|
|
|
|
webkit = ua.indexOf('webkit') !== -1,
|
|
|
|
phantomjs = ua.indexOf('phantom') !== -1,
|
|
|
|
android23 = ua.search('android [23]') !== -1,
|
|
|
|
chrome = ua.indexOf('chrome') !== -1,
|
|
|
|
gecko = ua.indexOf('gecko') !== -1 && !webkit && !window.opera && !ie,
|
|
|
|
safari = !chrome && (ua.indexOf('safari') !== -1 || uv.indexOf('apple') == 0),
|
|
|
|
|
|
|
|
win = navigator.platform.indexOf('Win') === 0,
|
|
|
|
|
|
|
|
mobile = typeof orientation !== 'undefined' || ua.indexOf('mobile') !== -1,
|
|
|
|
cypressTest = ua.indexOf('cypress') !== -1,
|
|
|
|
msPointer = !window.PointerEvent && window.MSPointerEvent,
|
|
|
|
pointer = (window.PointerEvent && navigator.pointerEnabled && navigator.maxTouchPoints) || msPointer,
|
|
|
|
|
|
|
|
ie3d = ie && ('transition' in doc.style),
|
|
|
|
webkit3d = ('WebKitCSSMatrix' in window) && ('m11' in new window.WebKitCSSMatrix()) && !android23,
|
|
|
|
gecko3d = 'MozPerspective' in doc.style,
|
|
|
|
opera12 = 'OTransition' in doc.style;
|
|
|
|
|
|
|
|
var touch = !window.L_NO_TOUCH && (pointer || 'ontouchstart' in window ||
|
|
|
|
(window.DocumentTouch && document instanceof window.DocumentTouch));
|
|
|
|
|
|
|
|
var isInternetExplorer = (navigator.userAgent.toLowerCase().indexOf('msie') != -1 ||
|
|
|
|
navigator.userAgent.toLowerCase().indexOf('trident') != -1);
|
|
|
|
|
|
|
|
global.L = {};
|
|
|
|
global.L.Browser = {
|
|
|
|
|
|
|
|
// @property ie: Boolean
|
|
|
|
// `true` for all Internet Explorer versions (not Edge).
|
|
|
|
ie: ie,
|
|
|
|
|
|
|
|
// @property ielt9: Boolean
|
|
|
|
// `true` for Internet Explorer versions less than 9.
|
|
|
|
ielt9: ie && !document.addEventListener,
|
|
|
|
|
|
|
|
// @property edge: Boolean
|
|
|
|
// `true` for the Edge web browser.
|
|
|
|
edge: 'msLaunchUri' in navigator && !('documentMode' in document),
|
|
|
|
|
|
|
|
// @property webkit: Boolean
|
|
|
|
// `true` for webkit-based browsers like Chrome and Safari (including mobile versions).
|
|
|
|
webkit: webkit,
|
|
|
|
|
|
|
|
// @property gecko: Boolean
|
|
|
|
// `true` for gecko-based browsers like Firefox.
|
|
|
|
gecko: gecko,
|
|
|
|
|
|
|
|
// @property android: Boolean
|
|
|
|
// `true` for any browser running on an Android platform.
|
|
|
|
android: ua.indexOf('android') !== -1,
|
|
|
|
|
|
|
|
// @property android23: Boolean
|
|
|
|
// `true` for browsers running on Android 2 or Android 3.
|
|
|
|
android23: android23,
|
|
|
|
|
|
|
|
// @property chrome: Boolean
|
|
|
|
// `true` for the Chrome browser.
|
|
|
|
chrome: chrome,
|
|
|
|
|
|
|
|
// @property safari: Boolean
|
|
|
|
// `true` for the Safari browser.
|
|
|
|
safari: safari,
|
|
|
|
|
|
|
|
// @property win: Boolean
|
|
|
|
// `true` when the browser is running in a Windows platform
|
|
|
|
win: win,
|
|
|
|
|
|
|
|
// @property ie3d: Boolean
|
|
|
|
// `true` for all Internet Explorer versions supporting CSS transforms.
|
|
|
|
ie3d: ie3d,
|
|
|
|
|
|
|
|
// @property isInternetExplorer: Boolean
|
|
|
|
// `true` for Internet Explorer
|
|
|
|
isInternetExplorer: isInternetExplorer,
|
|
|
|
|
|
|
|
// @property webkit3d: Boolean
|
|
|
|
// `true` for webkit-based browsers supporting CSS transforms.
|
|
|
|
webkit3d: webkit3d,
|
|
|
|
|
|
|
|
// @property gecko3d: Boolean
|
|
|
|
// `true` for gecko-based browsers supporting CSS transforms.
|
|
|
|
gecko3d: gecko3d,
|
|
|
|
|
|
|
|
// @property opera12: Boolean
|
|
|
|
// `true` for the Opera browser supporting CSS transforms (version 12 or later).
|
|
|
|
opera12: opera12,
|
|
|
|
|
|
|
|
// @property any3d: Boolean
|
|
|
|
// `true` for all browsers supporting CSS transforms.
|
|
|
|
any3d: !window.L_DISABLE_3D && (ie3d || webkit3d || gecko3d) && !opera12 && !phantomjs,
|
|
|
|
|
|
|
|
|
|
|
|
// @property mobile: Boolean
|
|
|
|
// `true` for all browsers running in a mobile device.
|
|
|
|
mobile: mobile,
|
|
|
|
|
|
|
|
// @property mobileWebkit: Boolean
|
|
|
|
// `true` for all webkit-based browsers in a mobile device.
|
|
|
|
mobileWebkit: mobile && webkit,
|
|
|
|
|
|
|
|
// @property mobileWebkit3d: Boolean
|
|
|
|
// `true` for all webkit-based browsers in a mobile device supporting CSS transforms.
|
|
|
|
mobileWebkit3d: mobile && webkit3d,
|
|
|
|
|
|
|
|
// @property mobileOpera: Boolean
|
|
|
|
// `true` for the Opera browser in a mobile device.
|
|
|
|
mobileOpera: mobile && window.opera,
|
|
|
|
|
|
|
|
// @property mobileGecko: Boolean
|
|
|
|
// `true` for gecko-based browsers running in a mobile device.
|
|
|
|
mobileGecko: mobile && gecko,
|
|
|
|
|
|
|
|
// @property cypressTest: Boolean
|
|
|
|
// `true` when the browser run by cypress
|
|
|
|
cypressTest: cypressTest,
|
|
|
|
|
|
|
|
// @property touch: Boolean
|
|
|
|
// `true` for all browsers supporting [touch events](https://developer.mozilla.org/docs/Web/API/Touch_events).
|
|
|
|
touch: !!touch,
|
|
|
|
|
|
|
|
// @property msPointer: Boolean
|
|
|
|
// `true` for browsers implementing the Microsoft touch events model (notably IE10).
|
|
|
|
msPointer: !!msPointer,
|
|
|
|
|
|
|
|
// @property pointer: Boolean
|
|
|
|
// `true` for all browsers supporting [pointer events](https://msdn.microsoft.com/en-us/library/dn433244%28v=vs.85%29.aspx).
|
|
|
|
pointer: !!pointer,
|
|
|
|
|
|
|
|
// @property retina: Boolean
|
|
|
|
// `true` for browsers on a high-resolution "retina" screen.
|
|
|
|
retina: (window.devicePixelRatio || (window.screen.deviceXDPI / window.screen.logicalXDPI)) > 1
|
|
|
|
};
|
|
|
|
|
2020-03-26 03:42:32 -05:00
|
|
|
global.mode = {
|
|
|
|
// Here "mobile" means "mobile phone" (at least for now). Has to match small screen size
|
|
|
|
// requirement.
|
|
|
|
isMobile: function() {
|
|
|
|
if (L.Browser.mobile && L.Browser.cypressTest) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-08 07:15:22 -05:00
|
|
|
return L.Browser.mobile && (screen.width < 768 || screen.height < 768);
|
2020-03-26 03:42:32 -05:00
|
|
|
},
|
|
|
|
// Mobile device with big screen size.
|
|
|
|
isTablet: function() {
|
|
|
|
return L.Browser.mobile && !window.mode.isMobile();
|
|
|
|
},
|
|
|
|
isDesktop: function() {
|
|
|
|
return !L.Browser.mobile;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-01-07 12:04:14 -06:00
|
|
|
document.addEventListener('contextmenu', function(e) {
|
|
|
|
if (e.preventDefault) {
|
|
|
|
e.preventDefault();
|
|
|
|
} else {
|
|
|
|
e.returnValue = false;
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
2019-03-06 05:32:59 -06:00
|
|
|
global.fakeWebSocketCounter = 0;
|
|
|
|
global.FakeWebSocket = function () {
|
|
|
|
this.binaryType = 'arraybuffer';
|
|
|
|
this.bufferedAmount = 0;
|
|
|
|
this.extensions = '';
|
|
|
|
this.protocol = '';
|
|
|
|
this.readyState = 1;
|
|
|
|
this.id = window.fakeWebSocketCounter++;
|
|
|
|
this.sendCounter = 0;
|
|
|
|
this.onclose = function() {
|
|
|
|
};
|
|
|
|
this.onerror = function() {
|
|
|
|
};
|
|
|
|
this.onmessage = function() {
|
|
|
|
};
|
|
|
|
this.onopen = function() {
|
|
|
|
};
|
2020-03-04 07:54:04 -06:00
|
|
|
this.close = function() {
|
|
|
|
};
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-03-06 05:32:59 -06:00
|
|
|
global.FakeWebSocket.prototype.send = function(data) {
|
|
|
|
this.sendCounter++;
|
|
|
|
window.postMobileMessage(data);
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-03-06 05:32:59 -06:00
|
|
|
|
2020-03-04 07:54:04 -06:00
|
|
|
global.proxySocketCounter = 0;
|
|
|
|
global.ProxySocket = function (uri) {
|
2020-03-20 11:38:14 -05:00
|
|
|
var that = this;
|
2020-03-04 07:54:04 -06:00
|
|
|
this.uri = uri;
|
|
|
|
this.binaryType = 'arraybuffer';
|
|
|
|
this.bufferedAmount = 0;
|
|
|
|
this.extensions = '';
|
|
|
|
this.protocol = '';
|
|
|
|
this.connected = true;
|
|
|
|
this.readyState = 0; // connecting
|
|
|
|
this.sessionId = 'fetchsession';
|
|
|
|
this.id = window.proxySocketCounter++;
|
|
|
|
this.sendCounter = 0;
|
2020-03-20 15:15:08 -05:00
|
|
|
this.readWaiting = 0;
|
2020-04-18 12:40:59 -05:00
|
|
|
this.inSerial = 0;
|
|
|
|
this.outSerial = 0;
|
2020-03-04 07:54:04 -06:00
|
|
|
this.onclose = function() {
|
|
|
|
};
|
|
|
|
this.onerror = function() {
|
|
|
|
};
|
|
|
|
this.onmessage = function() {
|
|
|
|
};
|
2020-03-19 10:54:28 -05:00
|
|
|
this.parseIncomingArray = function(arr) {
|
|
|
|
var decoder = new TextDecoder();
|
2020-03-21 10:07:10 -05:00
|
|
|
console.debug('proxy: parse incoming array of length ' + arr.length);
|
2020-03-19 10:54:28 -05:00
|
|
|
for (var i = 0; i < arr.length; ++i)
|
|
|
|
{
|
|
|
|
var left = arr.length - i;
|
|
|
|
if (left < 4)
|
|
|
|
{
|
|
|
|
console.debug('no data left');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
var type = String.fromCharCode(arr[i+0]);
|
|
|
|
if (type != 'T' && type != 'B')
|
|
|
|
{
|
|
|
|
console.debug('wrong data type: ' + type);
|
|
|
|
break;
|
|
|
|
}
|
2020-04-18 12:40:59 -05:00
|
|
|
i++;
|
|
|
|
|
|
|
|
// Serial
|
|
|
|
if (arr[i] !== 48 && arr[i+1] !== 120) // '0x'
|
2020-03-19 10:54:28 -05:00
|
|
|
{
|
|
|
|
console.debug('missing hex preamble');
|
|
|
|
break;
|
|
|
|
}
|
2020-04-18 12:40:59 -05:00
|
|
|
i += 2;
|
2020-03-19 10:54:28 -05:00
|
|
|
var numStr = '';
|
|
|
|
var start = i;
|
|
|
|
while (arr[i] != 10) // '\n'
|
|
|
|
i++;
|
|
|
|
numStr = decoder.decode(arr.slice(start, i)); // FIXME: IE11
|
2020-04-18 12:40:59 -05:00
|
|
|
var serial = parseInt(numStr, 16);
|
|
|
|
|
|
|
|
i++; // skip \n
|
|
|
|
|
|
|
|
// Size:
|
|
|
|
if (arr[i] !== 48 && arr[i+1] !== 120) // '0x'
|
|
|
|
{
|
|
|
|
console.debug('missing hex preamble');
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i += 2;
|
|
|
|
start = i;
|
|
|
|
while (arr[i] != 10) // '\n'
|
|
|
|
i++;
|
|
|
|
numStr = decoder.decode(arr.slice(start, i)); // FIXME: IE11
|
2020-03-19 10:54:28 -05:00
|
|
|
var size = parseInt(numStr, 16);
|
|
|
|
|
|
|
|
i++; // skip \n
|
|
|
|
|
|
|
|
var data;
|
|
|
|
if (type == 'T') // FIXME: IE11
|
|
|
|
data = decoder.decode(arr.slice(i, i + size));
|
|
|
|
else
|
|
|
|
data = arr.slice(i, i + size);
|
|
|
|
|
2020-04-18 12:40:59 -05:00
|
|
|
if (serial !== that.inSerial + 1) {
|
|
|
|
console.debug('Error: serial mismatch ' + serial + ' vs. ' + (that.inSerial + 1));
|
|
|
|
}
|
|
|
|
that.inSerial = serial;
|
2020-03-19 10:54:28 -05:00
|
|
|
this.onmessage({ data: data });
|
|
|
|
|
|
|
|
i += size; // skip trailing '\n' in loop-increment
|
|
|
|
}
|
|
|
|
};
|
2020-03-20 11:38:14 -05:00
|
|
|
this.sendQueue = '';
|
|
|
|
this.sendTimeout = undefined;
|
|
|
|
this.doSend = function () {
|
|
|
|
console.debug('send msg "' + that.sendQueue + '"');
|
2020-03-04 07:54:04 -06:00
|
|
|
var req = new XMLHttpRequest();
|
2020-03-20 11:38:14 -05:00
|
|
|
req.open('POST', that.getEndPoint('write'));
|
|
|
|
req.setRequestHeader('SessionId', that.sessionId);
|
|
|
|
if (that.sessionId === 'fetchsession')
|
|
|
|
console.debug('session fetch not completed');
|
2020-03-19 10:54:28 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
req.responseType = 'arraybuffer';
|
|
|
|
req.addEventListener('load', function() {
|
|
|
|
if (this.status == 200)
|
2020-03-20 11:38:14 -05:00
|
|
|
that.parseIncomingArray(new Uint8Array(this.response));
|
2020-03-19 10:54:28 -05:00
|
|
|
else
|
2020-03-21 10:07:10 -05:00
|
|
|
console.debug('proxy: error on incoming response');
|
2020-03-19 10:54:28 -05:00
|
|
|
});
|
|
|
|
}
|
2020-03-20 11:38:14 -05:00
|
|
|
req.send(that.sendQueue);
|
|
|
|
that.sendQueue = '';
|
2020-04-14 11:01:41 -05:00
|
|
|
that.sendTimeout = undefined;
|
2020-03-20 11:38:14 -05:00
|
|
|
};
|
|
|
|
this.getSessionId = function() {
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
req.open('POST', that.getEndPoint('write'));
|
|
|
|
req.setRequestHeader('SessionId', that.sessionId);
|
|
|
|
req.responseType = 'text';
|
|
|
|
req.addEventListener('load', function() {
|
|
|
|
console.debug('got session: ' + this.responseText);
|
2020-04-28 09:18:24 -05:00
|
|
|
if (this.responseText.indexOf('\n') >= 0)
|
|
|
|
{
|
|
|
|
console.debug('Error: failed to fetch session id!');
|
|
|
|
that.onerror();
|
|
|
|
that.onclose();
|
|
|
|
that.readyState = 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
that.sessionId = this.responseText;
|
|
|
|
that.readyState = 1;
|
|
|
|
that.onopen();
|
|
|
|
}
|
2020-03-20 11:38:14 -05:00
|
|
|
});
|
|
|
|
req.send('');
|
|
|
|
};
|
|
|
|
this.send = function(msg) {
|
|
|
|
this.sendQueue = this.sendQueue.concat(
|
2020-04-18 12:40:59 -05:00
|
|
|
'B0x' + this.outSerial.toString(16) + '\n' +
|
|
|
|
'0x' + msg.length.toString(16) + '\n' + msg + '\n');
|
|
|
|
this.outSerial++;
|
2020-03-20 11:38:14 -05:00
|
|
|
if (this.sessionId !== 'fetchsession' && this.sendTimeout === undefined)
|
|
|
|
this.sendTimeout = setTimeout(this.doSend, 2 /* ms */);
|
|
|
|
};
|
2020-03-04 07:54:04 -06:00
|
|
|
this.close = function() {
|
2020-03-21 10:07:10 -05:00
|
|
|
console.debug('proxy: close socket');
|
2020-03-04 07:54:04 -06:00
|
|
|
this.readyState = 3;
|
|
|
|
this.onclose();
|
2020-03-21 10:07:10 -05:00
|
|
|
clearInterval(this.waitInterval);
|
|
|
|
this.waitInterval = undefined;
|
2020-03-04 07:54:04 -06:00
|
|
|
};
|
|
|
|
this.getEndPoint = function(type) {
|
|
|
|
var base = this.uri;
|
2020-04-28 12:05:25 -05:00
|
|
|
return base + '/' + type + '/' + this.outSerial;
|
2020-03-04 07:54:04 -06:00
|
|
|
};
|
2020-03-21 10:07:10 -05:00
|
|
|
console.debug('proxy: new socket ' + this.id + ' ' + this.uri);
|
2020-03-04 07:54:04 -06:00
|
|
|
|
2020-03-20 11:38:14 -05:00
|
|
|
// queue fetch of session id.
|
|
|
|
this.getSessionId();
|
2020-03-04 07:54:04 -06:00
|
|
|
|
|
|
|
// horrors ...
|
2020-03-21 10:07:10 -05:00
|
|
|
this.waitConnect = function() {
|
|
|
|
console.debug('proxy: waiting - ' + that.readWaiting + ' on session ' + that.sessionId);
|
2020-04-14 11:01:41 -05:00
|
|
|
if (that.readWaiting >= 4) // max 4 waiting connections concurrently.
|
2020-03-04 07:54:04 -06:00
|
|
|
return;
|
2020-03-20 15:15:08 -05:00
|
|
|
if (that.sessionId == 'fetchsession')
|
2020-03-04 07:54:04 -06:00
|
|
|
return; // waiting for our session id.
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
// fetch session id:
|
|
|
|
req.addEventListener('load', function() {
|
|
|
|
if (this.status == 200)
|
2020-03-20 11:38:14 -05:00
|
|
|
that.parseIncomingArray(new Uint8Array(this.response));
|
2020-03-04 07:54:04 -06:00
|
|
|
else
|
|
|
|
console.debug('Handle error ' + this.status);
|
2020-03-20 15:15:08 -05:00
|
|
|
});
|
|
|
|
req.addEventListener('loadend', function() {
|
|
|
|
that.readWaiting--;
|
2020-03-21 10:07:10 -05:00
|
|
|
console.debug('proxy: wait ended, re-issue');
|
|
|
|
that.waitConnect();
|
2020-03-04 07:54:04 -06:00
|
|
|
});
|
2020-03-21 10:07:10 -05:00
|
|
|
req.open('GET', that.getEndPoint('wait'));
|
2020-03-19 10:54:28 -05:00
|
|
|
req.setRequestHeader('SessionId', that.sessionId);
|
|
|
|
req.responseType = 'arraybuffer';
|
|
|
|
req.send('');
|
2020-03-20 15:15:08 -05:00
|
|
|
that.readWaiting++;
|
2020-03-21 10:07:10 -05:00
|
|
|
};
|
|
|
|
this.waitInterval = setInterval(this.waitConnect, 250);
|
2020-03-04 07:54:04 -06:00
|
|
|
};
|
|
|
|
|
2020-03-20 14:05:48 -05:00
|
|
|
if (global.socketProxy)
|
|
|
|
{
|
|
|
|
// re-write relative URLs in CSS - somewhat grim.
|
|
|
|
window.addEventListener('load', function() {
|
|
|
|
var sheets = document.styleSheets;
|
|
|
|
for (var i = 0; i < sheets.length; ++i) {
|
|
|
|
var relBases = sheets[i].href.split('/');
|
|
|
|
relBases.pop(); // bin last - css name.
|
|
|
|
var replaceBase = 'url("' + relBases.join('/') + '/images/';
|
|
|
|
|
|
|
|
var rules = sheets[i].cssRules || sheets[i].rules;
|
|
|
|
for (var r = 0; r < rules.length; ++r) {
|
|
|
|
if (!rules[r] || !rules[r].style)
|
|
|
|
continue;
|
|
|
|
var img = rules[r].style.backgroundImage;
|
|
|
|
if (img === '' || img === undefined)
|
|
|
|
continue;
|
|
|
|
if (img.startsWith('url("images/'))
|
|
|
|
{
|
|
|
|
rules[r].style.backgroundImage =
|
|
|
|
img.replace('url("images/', replaceBase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
|
2020-03-04 07:54:04 -06:00
|
|
|
global.createWebSocket = function(uri) {
|
|
|
|
if (global.socketProxy) {
|
|
|
|
return new global.ProxySocket(uri);
|
|
|
|
} else {
|
|
|
|
return new WebSocket(uri);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-26 15:21:48 -06:00
|
|
|
// If not debug, don't print anything on the console
|
|
|
|
// except in tile debug mode (Ctrl-Shift-Alt-d)
|
|
|
|
console.log2 = console.log;
|
|
|
|
if (global.loleafletLogging !== 'true') {
|
|
|
|
var methods = ['warn', 'info', 'debug', 'trace', 'log', 'assert', 'time', 'timeEnd'];
|
|
|
|
for (var i = 0; i < methods.length; i++) {
|
|
|
|
console[methods[i]] = function() {};
|
|
|
|
}
|
2019-07-01 19:25:10 -05:00
|
|
|
} else {
|
|
|
|
window.onerror = function (msg, src, row, col, err) {
|
|
|
|
var data = {
|
|
|
|
userAgent: navigator.userAgent.toLowerCase(),
|
|
|
|
vendor: navigator.vendor.toLowerCase(),
|
|
|
|
message: msg,
|
|
|
|
source: src,
|
|
|
|
line: row,
|
|
|
|
column: col
|
2019-12-10 15:05:13 -06:00
|
|
|
};
|
|
|
|
var desc = err ? err.message || {}: {}, stack = err ? err.stack || {}: {};
|
2019-07-01 19:25:10 -05:00
|
|
|
var log = 'jserror ' + JSON.stringify(data, null, 2) + '\n' + desc + '\n' + stack + '\n';
|
2019-10-31 03:03:47 -05:00
|
|
|
if (window.ThisIsAMobileApp) {
|
|
|
|
window.postMobileError(log);
|
|
|
|
} else if (global.socket && (global.socket instanceof WebSocket) && global.socket.readyState === 1) {
|
2019-07-01 19:25:10 -05:00
|
|
|
global.socket.send(log);
|
2020-03-04 07:54:04 -06:00
|
|
|
} else if (global.socket && global.L && global.L.Socket &&
|
|
|
|
(global.socket instanceof global.L.Socket) && global.socket.connected()) {
|
2019-07-01 19:25:10 -05:00
|
|
|
global.socket.sendMessage(log);
|
|
|
|
} else {
|
|
|
|
var req = new XMLHttpRequest();
|
|
|
|
var url = global.location.protocol + '//' + global.location.host + global.location.pathname.match(/.*\//) + 'logging.html';
|
|
|
|
req.open('POST', url, true);
|
|
|
|
req.setRequestHeader('Content-type','application/json; charset=utf-8');
|
|
|
|
req.send(log);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2018-04-12 14:57:00 -05:00
|
|
|
}
|
|
|
|
|
2019-03-20 03:44:39 -05:00
|
|
|
// fix jquery-ui
|
|
|
|
// var jQuery = require('jquery');
|
|
|
|
global.require = function (path) {
|
|
|
|
if (path=='jquery') {
|
|
|
|
return global.jQuery;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-01-26 15:21:48 -06:00
|
|
|
global.getParameterByName = function (name) {
|
|
|
|
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]');
|
|
|
|
var regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
|
|
|
|
var results = regex.exec(location.search);
|
|
|
|
return results === null ? '' : results[1].replace(/\+/g, ' ');
|
|
|
|
};
|
2018-04-12 14:57:00 -05:00
|
|
|
|
2019-03-15 11:23:28 -05:00
|
|
|
global._ = function (string) {
|
|
|
|
// In the mobile app case we can't use the stuff from l10n-for-node, as that assumes HTTP.
|
2019-12-11 04:46:52 -06:00
|
|
|
if (window.ThisIsAMobileApp) {
|
2019-01-26 15:21:48 -06:00
|
|
|
// We use another approach just for iOS for now.
|
2019-12-19 07:49:59 -06:00
|
|
|
if (window.LOCALIZATIONS && window.LOCALIZATIONS.hasOwnProperty(string)) {
|
2019-01-26 15:21:48 -06:00
|
|
|
// window.postMobileDebug('_(' + string + '): YES: ' + window.LOCALIZATIONS[string]);
|
|
|
|
var result = window.LOCALIZATIONS[string];
|
|
|
|
if (window.LANG === 'de-CH') {
|
|
|
|
result = result.replace(/ß/g, 'ss');
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
// window.postMobileDebug('_(' + string + '): NO');
|
|
|
|
return string;
|
2018-11-15 16:38:40 -06:00
|
|
|
}
|
2019-03-15 11:23:28 -05:00
|
|
|
} else {
|
|
|
|
return string.toLocaleString();
|
2018-11-09 14:28:46 -06:00
|
|
|
}
|
2019-03-15 11:23:28 -05:00
|
|
|
};
|
2018-04-12 14:57:00 -05:00
|
|
|
|
2019-01-27 12:04:26 -06:00
|
|
|
var docParams, wopiParams;
|
|
|
|
var filePath = global.getParameterByName('file_path');
|
|
|
|
var wopiSrc = global.getParameterByName('WOPISrc');
|
|
|
|
if (wopiSrc != '') {
|
|
|
|
global.docURL = decodeURIComponent(wopiSrc);
|
2019-03-12 13:56:11 -05:00
|
|
|
wopiSrc = '?WOPISrc=' + wopiSrc + '&compat=/ws';
|
2019-01-27 12:04:26 -06:00
|
|
|
if (global.accessToken !== '') {
|
|
|
|
wopiParams = { 'access_token': global.accessToken, 'access_token_ttl': global.accessTokenTTL };
|
|
|
|
}
|
|
|
|
else if (global.accessHeader !== '') {
|
|
|
|
wopiParams = { 'access_header': global.accessHeader };
|
|
|
|
}
|
2020-04-22 08:48:18 -05:00
|
|
|
if (wopiParams) {
|
|
|
|
docParams = Object.keys(wopiParams).map(function(key) {
|
|
|
|
return encodeURIComponent(key) + '=' + encodeURIComponent(wopiParams[key]);
|
|
|
|
}).join('&');
|
|
|
|
}
|
2019-01-27 12:04:26 -06:00
|
|
|
} else {
|
|
|
|
global.docURL = filePath;
|
|
|
|
}
|
|
|
|
|
2019-03-06 05:32:59 -06:00
|
|
|
if (window.ThisIsAMobileApp) {
|
|
|
|
global.socket = new global.FakeWebSocket();
|
|
|
|
window.TheFakeWebSocket = global.socket;
|
|
|
|
} else {
|
|
|
|
var websocketURI = global.host + global.serviceRoot + '/lool/' + encodeURIComponent(global.docURL + (docParams ? '?' + docParams : '')) + '/ws' + wopiSrc;
|
2019-01-27 12:04:26 -06:00
|
|
|
|
2019-03-06 05:32:59 -06:00
|
|
|
try {
|
2020-03-04 07:54:04 -06:00
|
|
|
global.socket = global.createWebSocket(websocketURI);
|
2019-03-06 05:32:59 -06:00
|
|
|
} catch (err) {
|
|
|
|
console.log(err);
|
|
|
|
}
|
2019-01-27 12:04:26 -06:00
|
|
|
}
|
|
|
|
|
2019-11-12 12:49:19 -06:00
|
|
|
var lang = global.getParameterByName('lang');
|
2019-03-07 12:02:15 -06:00
|
|
|
global.queueMsg = [];
|
2019-12-11 04:46:52 -06:00
|
|
|
if (window.ThisIsAMobileApp)
|
2019-11-12 12:49:19 -06:00
|
|
|
window.LANG = lang;
|
2019-01-27 12:04:26 -06:00
|
|
|
if (global.socket && global.socket.readyState !== 3) {
|
|
|
|
global.socket.onopen = function () {
|
|
|
|
if (global.socket.readyState === 1) {
|
|
|
|
var ProtocolVersionNumber = '0.1';
|
2019-11-12 12:49:19 -06:00
|
|
|
var timestamp = global.getParameterByName('timestamp');
|
|
|
|
var msg = 'load url=' + encodeURIComponent(global.docURL);
|
|
|
|
|
2019-01-27 12:04:26 -06:00
|
|
|
global.socket.send('loolclient ' + ProtocolVersionNumber);
|
2019-11-12 12:49:19 -06:00
|
|
|
|
2019-12-11 04:46:52 -06:00
|
|
|
if (window.ThisIsAMobileApp) {
|
2019-11-12 12:49:19 -06:00
|
|
|
msg += ' lang=' + window.LANG;
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (timestamp) {
|
|
|
|
msg += ' timestamp=' + timestamp;
|
|
|
|
}
|
|
|
|
if (lang) {
|
|
|
|
msg += ' lang=' + lang;
|
|
|
|
}
|
|
|
|
// renderingOptions?
|
|
|
|
}
|
|
|
|
global.socket.send(msg);
|
2019-01-27 12:04:26 -06:00
|
|
|
}
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-01-27 12:04:26 -06:00
|
|
|
|
|
|
|
global.socket.onerror = function (event) {
|
|
|
|
console.log(event);
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-01-27 12:04:26 -06:00
|
|
|
|
|
|
|
global.socket.onclose = function (event) {
|
|
|
|
console.log(event);
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-01-27 12:04:26 -06:00
|
|
|
|
|
|
|
global.socket.onmessage = function (event) {
|
2019-06-19 02:48:54 -05:00
|
|
|
if (typeof global.socket._onMessage === 'function') {
|
2020-03-12 22:29:39 -05:00
|
|
|
global.socket._emptyQueue();
|
2019-03-07 12:02:15 -06:00
|
|
|
global.socket._onMessage(event);
|
|
|
|
} else {
|
|
|
|
global.queueMsg.push(event.data);
|
|
|
|
}
|
2020-01-16 08:44:23 -06:00
|
|
|
};
|
2019-01-27 12:04:26 -06:00
|
|
|
|
|
|
|
global.socket.binaryType = 'arraybuffer';
|
2019-03-06 07:29:17 -06:00
|
|
|
|
|
|
|
if (window.ThisIsAMobileApp) {
|
|
|
|
// This corresponds to the initial GET request when creating a WebSocket
|
|
|
|
// connection and tells the app's code that it is OK to start invoking
|
|
|
|
// TheFakeWebSocket's onmessage handler. The app code that handles this
|
|
|
|
// special message knows the document to be edited anyway, and can send it
|
|
|
|
// on as necessary to the Online code.
|
|
|
|
window.postMobileMessage('HULLO');
|
|
|
|
// A FakeWebSocket is immediately open.
|
|
|
|
this.socket.onopen();
|
|
|
|
}
|
2019-01-27 12:04:26 -06:00
|
|
|
}
|
2018-04-12 14:57:00 -05:00
|
|
|
}(window));
|