1 |
3a515b92
|
cagy
|
/* sockjs-client v1.4.0 | http://sockjs.org | MIT license */
|
2 |
|
|
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.SockJS = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
|
3 |
|
|
(function (global){
|
4 |
|
|
'use strict';
|
5 |
|
|
|
6 |
|
|
var transportList = require('./transport-list');
|
7 |
|
|
|
8 |
|
|
module.exports = require('./main')(transportList);
|
9 |
|
|
|
10 |
|
|
// TODO can't get rid of this until all servers do
|
11 |
|
|
if ('_sockjs_onload' in global) {
|
12 |
|
|
setTimeout(global._sockjs_onload, 1);
|
13 |
|
|
}
|
14 |
|
|
|
15 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
16 |
|
|
|
17 |
|
|
},{"./main":14,"./transport-list":16}],2:[function(require,module,exports){
|
18 |
|
|
'use strict';
|
19 |
|
|
|
20 |
|
|
var inherits = require('inherits')
|
21 |
|
|
, Event = require('./event')
|
22 |
|
|
;
|
23 |
|
|
|
24 |
|
|
function CloseEvent() {
|
25 |
|
|
Event.call(this);
|
26 |
|
|
this.initEvent('close', false, false);
|
27 |
|
|
this.wasClean = false;
|
28 |
|
|
this.code = 0;
|
29 |
|
|
this.reason = '';
|
30 |
|
|
}
|
31 |
|
|
|
32 |
|
|
inherits(CloseEvent, Event);
|
33 |
|
|
|
34 |
|
|
module.exports = CloseEvent;
|
35 |
|
|
|
36 |
|
|
},{"./event":4,"inherits":57}],3:[function(require,module,exports){
|
37 |
|
|
'use strict';
|
38 |
|
|
|
39 |
|
|
var inherits = require('inherits')
|
40 |
|
|
, EventTarget = require('./eventtarget')
|
41 |
|
|
;
|
42 |
|
|
|
43 |
|
|
function EventEmitter() {
|
44 |
|
|
EventTarget.call(this);
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
inherits(EventEmitter, EventTarget);
|
48 |
|
|
|
49 |
|
|
EventEmitter.prototype.removeAllListeners = function(type) {
|
50 |
|
|
if (type) {
|
51 |
|
|
delete this._listeners[type];
|
52 |
|
|
} else {
|
53 |
|
|
this._listeners = {};
|
54 |
|
|
}
|
55 |
|
|
};
|
56 |
|
|
|
57 |
|
|
EventEmitter.prototype.once = function(type, listener) {
|
58 |
|
|
var self = this
|
59 |
|
|
, fired = false;
|
60 |
|
|
|
61 |
|
|
function g() {
|
62 |
|
|
self.removeListener(type, g);
|
63 |
|
|
|
64 |
|
|
if (!fired) {
|
65 |
|
|
fired = true;
|
66 |
|
|
listener.apply(this, arguments);
|
67 |
|
|
}
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
this.on(type, g);
|
71 |
|
|
};
|
72 |
|
|
|
73 |
|
|
EventEmitter.prototype.emit = function() {
|
74 |
|
|
var type = arguments[0];
|
75 |
|
|
var listeners = this._listeners[type];
|
76 |
|
|
if (!listeners) {
|
77 |
|
|
return;
|
78 |
|
|
}
|
79 |
|
|
// equivalent of Array.prototype.slice.call(arguments, 1);
|
80 |
|
|
var l = arguments.length;
|
81 |
|
|
var args = new Array(l - 1);
|
82 |
|
|
for (var ai = 1; ai < l; ai++) {
|
83 |
|
|
args[ai - 1] = arguments[ai];
|
84 |
|
|
}
|
85 |
|
|
for (var i = 0; i < listeners.length; i++) {
|
86 |
|
|
listeners[i].apply(this, args);
|
87 |
|
|
}
|
88 |
|
|
};
|
89 |
|
|
|
90 |
|
|
EventEmitter.prototype.on = EventEmitter.prototype.addListener = EventTarget.prototype.addEventListener;
|
91 |
|
|
EventEmitter.prototype.removeListener = EventTarget.prototype.removeEventListener;
|
92 |
|
|
|
93 |
|
|
module.exports.EventEmitter = EventEmitter;
|
94 |
|
|
|
95 |
|
|
},{"./eventtarget":5,"inherits":57}],4:[function(require,module,exports){
|
96 |
|
|
'use strict';
|
97 |
|
|
|
98 |
|
|
function Event(eventType) {
|
99 |
|
|
this.type = eventType;
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
Event.prototype.initEvent = function(eventType, canBubble, cancelable) {
|
103 |
|
|
this.type = eventType;
|
104 |
|
|
this.bubbles = canBubble;
|
105 |
|
|
this.cancelable = cancelable;
|
106 |
|
|
this.timeStamp = +new Date();
|
107 |
|
|
return this;
|
108 |
|
|
};
|
109 |
|
|
|
110 |
|
|
Event.prototype.stopPropagation = function() {};
|
111 |
|
|
Event.prototype.preventDefault = function() {};
|
112 |
|
|
|
113 |
|
|
Event.CAPTURING_PHASE = 1;
|
114 |
|
|
Event.AT_TARGET = 2;
|
115 |
|
|
Event.BUBBLING_PHASE = 3;
|
116 |
|
|
|
117 |
|
|
module.exports = Event;
|
118 |
|
|
|
119 |
|
|
},{}],5:[function(require,module,exports){
|
120 |
|
|
'use strict';
|
121 |
|
|
|
122 |
|
|
/* Simplified implementation of DOM2 EventTarget.
|
123 |
|
|
* http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-EventTarget
|
124 |
|
|
*/
|
125 |
|
|
|
126 |
|
|
function EventTarget() {
|
127 |
|
|
this._listeners = {};
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
EventTarget.prototype.addEventListener = function(eventType, listener) {
|
131 |
|
|
if (!(eventType in this._listeners)) {
|
132 |
|
|
this._listeners[eventType] = [];
|
133 |
|
|
}
|
134 |
|
|
var arr = this._listeners[eventType];
|
135 |
|
|
// #4
|
136 |
|
|
if (arr.indexOf(listener) === -1) {
|
137 |
|
|
// Make a copy so as not to interfere with a current dispatchEvent.
|
138 |
|
|
arr = arr.concat([listener]);
|
139 |
|
|
}
|
140 |
|
|
this._listeners[eventType] = arr;
|
141 |
|
|
};
|
142 |
|
|
|
143 |
|
|
EventTarget.prototype.removeEventListener = function(eventType, listener) {
|
144 |
|
|
var arr = this._listeners[eventType];
|
145 |
|
|
if (!arr) {
|
146 |
|
|
return;
|
147 |
|
|
}
|
148 |
|
|
var idx = arr.indexOf(listener);
|
149 |
|
|
if (idx !== -1) {
|
150 |
|
|
if (arr.length > 1) {
|
151 |
|
|
// Make a copy so as not to interfere with a current dispatchEvent.
|
152 |
|
|
this._listeners[eventType] = arr.slice(0, idx).concat(arr.slice(idx + 1));
|
153 |
|
|
} else {
|
154 |
|
|
delete this._listeners[eventType];
|
155 |
|
|
}
|
156 |
|
|
return;
|
157 |
|
|
}
|
158 |
|
|
};
|
159 |
|
|
|
160 |
|
|
EventTarget.prototype.dispatchEvent = function() {
|
161 |
|
|
var event = arguments[0];
|
162 |
|
|
var t = event.type;
|
163 |
|
|
// equivalent of Array.prototype.slice.call(arguments, 0);
|
164 |
|
|
var args = arguments.length === 1 ? [event] : Array.apply(null, arguments);
|
165 |
|
|
// TODO: This doesn't match the real behavior; per spec, onfoo get
|
166 |
|
|
// their place in line from the /first/ time they're set from
|
167 |
|
|
// non-null. Although WebKit bumps it to the end every time it's
|
168 |
|
|
// set.
|
169 |
|
|
if (this['on' + t]) {
|
170 |
|
|
this['on' + t].apply(this, args);
|
171 |
|
|
}
|
172 |
|
|
if (t in this._listeners) {
|
173 |
|
|
// Grab a reference to the listeners list. removeEventListener may alter the list.
|
174 |
|
|
var listeners = this._listeners[t];
|
175 |
|
|
for (var i = 0; i < listeners.length; i++) {
|
176 |
|
|
listeners[i].apply(this, args);
|
177 |
|
|
}
|
178 |
|
|
}
|
179 |
|
|
};
|
180 |
|
|
|
181 |
|
|
module.exports = EventTarget;
|
182 |
|
|
|
183 |
|
|
},{}],6:[function(require,module,exports){
|
184 |
|
|
'use strict';
|
185 |
|
|
|
186 |
|
|
var inherits = require('inherits')
|
187 |
|
|
, Event = require('./event')
|
188 |
|
|
;
|
189 |
|
|
|
190 |
|
|
function TransportMessageEvent(data) {
|
191 |
|
|
Event.call(this);
|
192 |
|
|
this.initEvent('message', false, false);
|
193 |
|
|
this.data = data;
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
inherits(TransportMessageEvent, Event);
|
197 |
|
|
|
198 |
|
|
module.exports = TransportMessageEvent;
|
199 |
|
|
|
200 |
|
|
},{"./event":4,"inherits":57}],7:[function(require,module,exports){
|
201 |
|
|
'use strict';
|
202 |
|
|
|
203 |
|
|
var JSON3 = require('json3')
|
204 |
|
|
, iframeUtils = require('./utils/iframe')
|
205 |
|
|
;
|
206 |
|
|
|
207 |
|
|
function FacadeJS(transport) {
|
208 |
|
|
this._transport = transport;
|
209 |
|
|
transport.on('message', this._transportMessage.bind(this));
|
210 |
|
|
transport.on('close', this._transportClose.bind(this));
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
FacadeJS.prototype._transportClose = function(code, reason) {
|
214 |
|
|
iframeUtils.postMessage('c', JSON3.stringify([code, reason]));
|
215 |
|
|
};
|
216 |
|
|
FacadeJS.prototype._transportMessage = function(frame) {
|
217 |
|
|
iframeUtils.postMessage('t', frame);
|
218 |
|
|
};
|
219 |
|
|
FacadeJS.prototype._send = function(data) {
|
220 |
|
|
this._transport.send(data);
|
221 |
|
|
};
|
222 |
|
|
FacadeJS.prototype._close = function() {
|
223 |
|
|
this._transport.close();
|
224 |
|
|
this._transport.removeAllListeners();
|
225 |
|
|
};
|
226 |
|
|
|
227 |
|
|
module.exports = FacadeJS;
|
228 |
|
|
|
229 |
|
|
},{"./utils/iframe":47,"json3":58}],8:[function(require,module,exports){
|
230 |
|
|
(function (process){
|
231 |
|
|
'use strict';
|
232 |
|
|
|
233 |
|
|
var urlUtils = require('./utils/url')
|
234 |
|
|
, eventUtils = require('./utils/event')
|
235 |
|
|
, JSON3 = require('json3')
|
236 |
|
|
, FacadeJS = require('./facade')
|
237 |
|
|
, InfoIframeReceiver = require('./info-iframe-receiver')
|
238 |
|
|
, iframeUtils = require('./utils/iframe')
|
239 |
|
|
, loc = require('./location')
|
240 |
|
|
;
|
241 |
|
|
|
242 |
|
|
var debug = function() {};
|
243 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
244 |
|
|
debug = require('debug')('sockjs-client:iframe-bootstrap');
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
module.exports = function(SockJS, availableTransports) {
|
248 |
|
|
var transportMap = {};
|
249 |
|
|
availableTransports.forEach(function(at) {
|
250 |
|
|
if (at.facadeTransport) {
|
251 |
|
|
transportMap[at.facadeTransport.transportName] = at.facadeTransport;
|
252 |
|
|
}
|
253 |
|
|
});
|
254 |
|
|
|
255 |
|
|
// hard-coded for the info iframe
|
256 |
|
|
// TODO see if we can make this more dynamic
|
257 |
|
|
transportMap[InfoIframeReceiver.transportName] = InfoIframeReceiver;
|
258 |
|
|
var parentOrigin;
|
259 |
|
|
|
260 |
|
|
/* eslint-disable camelcase */
|
261 |
|
|
SockJS.bootstrap_iframe = function() {
|
262 |
|
|
/* eslint-enable camelcase */
|
263 |
|
|
var facade;
|
264 |
|
|
iframeUtils.currentWindowId = loc.hash.slice(1);
|
265 |
|
|
var onMessage = function(e) {
|
266 |
|
|
if (e.source !== parent) {
|
267 |
|
|
return;
|
268 |
|
|
}
|
269 |
|
|
if (typeof parentOrigin === 'undefined') {
|
270 |
|
|
parentOrigin = e.origin;
|
271 |
|
|
}
|
272 |
|
|
if (e.origin !== parentOrigin) {
|
273 |
|
|
return;
|
274 |
|
|
}
|
275 |
|
|
|
276 |
|
|
var iframeMessage;
|
277 |
|
|
try {
|
278 |
|
|
iframeMessage = JSON3.parse(e.data);
|
279 |
|
|
} catch (ignored) {
|
280 |
|
|
debug('bad json', e.data);
|
281 |
|
|
return;
|
282 |
|
|
}
|
283 |
|
|
|
284 |
|
|
if (iframeMessage.windowId !== iframeUtils.currentWindowId) {
|
285 |
|
|
return;
|
286 |
|
|
}
|
287 |
|
|
switch (iframeMessage.type) {
|
288 |
|
|
case 's':
|
289 |
|
|
var p;
|
290 |
|
|
try {
|
291 |
|
|
p = JSON3.parse(iframeMessage.data);
|
292 |
|
|
} catch (ignored) {
|
293 |
|
|
debug('bad json', iframeMessage.data);
|
294 |
|
|
break;
|
295 |
|
|
}
|
296 |
|
|
var version = p[0];
|
297 |
|
|
var transport = p[1];
|
298 |
|
|
var transUrl = p[2];
|
299 |
|
|
var baseUrl = p[3];
|
300 |
|
|
debug(version, transport, transUrl, baseUrl);
|
301 |
|
|
// change this to semver logic
|
302 |
|
|
if (version !== SockJS.version) {
|
303 |
|
|
throw new Error('Incompatible SockJS! Main site uses:' +
|
304 |
|
|
' "' + version + '", the iframe:' +
|
305 |
|
|
' "' + SockJS.version + '".');
|
306 |
|
|
}
|
307 |
|
|
|
308 |
|
|
if (!urlUtils.isOriginEqual(transUrl, loc.href) ||
|
309 |
|
|
!urlUtils.isOriginEqual(baseUrl, loc.href)) {
|
310 |
|
|
throw new Error('Can\'t connect to different domain from within an ' +
|
311 |
|
|
'iframe. (' + loc.href + ', ' + transUrl + ', ' + baseUrl + ')');
|
312 |
|
|
}
|
313 |
|
|
facade = new FacadeJS(new transportMap[transport](transUrl, baseUrl));
|
314 |
|
|
break;
|
315 |
|
|
case 'm':
|
316 |
|
|
facade._send(iframeMessage.data);
|
317 |
|
|
break;
|
318 |
|
|
case 'c':
|
319 |
|
|
if (facade) {
|
320 |
|
|
facade._close();
|
321 |
|
|
}
|
322 |
|
|
facade = null;
|
323 |
|
|
break;
|
324 |
|
|
}
|
325 |
|
|
};
|
326 |
|
|
|
327 |
|
|
eventUtils.attachEvent('message', onMessage);
|
328 |
|
|
|
329 |
|
|
// Start
|
330 |
|
|
iframeUtils.postMessage('s');
|
331 |
|
|
};
|
332 |
|
|
};
|
333 |
|
|
|
334 |
|
|
}).call(this,{ env: {} })
|
335 |
|
|
|
336 |
|
|
},{"./facade":7,"./info-iframe-receiver":10,"./location":13,"./utils/event":46,"./utils/iframe":47,"./utils/url":52,"debug":55,"json3":58}],9:[function(require,module,exports){
|
337 |
|
|
(function (process){
|
338 |
|
|
'use strict';
|
339 |
|
|
|
340 |
|
|
var EventEmitter = require('events').EventEmitter
|
341 |
|
|
, inherits = require('inherits')
|
342 |
|
|
, JSON3 = require('json3')
|
343 |
|
|
, objectUtils = require('./utils/object')
|
344 |
|
|
;
|
345 |
|
|
|
346 |
|
|
var debug = function() {};
|
347 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
348 |
|
|
debug = require('debug')('sockjs-client:info-ajax');
|
349 |
|
|
}
|
350 |
|
|
|
351 |
|
|
function InfoAjax(url, AjaxObject) {
|
352 |
|
|
EventEmitter.call(this);
|
353 |
|
|
|
354 |
|
|
var self = this;
|
355 |
|
|
var t0 = +new Date();
|
356 |
|
|
this.xo = new AjaxObject('GET', url);
|
357 |
|
|
|
358 |
|
|
this.xo.once('finish', function(status, text) {
|
359 |
|
|
var info, rtt;
|
360 |
|
|
if (status === 200) {
|
361 |
|
|
rtt = (+new Date()) - t0;
|
362 |
|
|
if (text) {
|
363 |
|
|
try {
|
364 |
|
|
info = JSON3.parse(text);
|
365 |
|
|
} catch (e) {
|
366 |
|
|
debug('bad json', text);
|
367 |
|
|
}
|
368 |
|
|
}
|
369 |
|
|
|
370 |
|
|
if (!objectUtils.isObject(info)) {
|
371 |
|
|
info = {};
|
372 |
|
|
}
|
373 |
|
|
}
|
374 |
|
|
self.emit('finish', info, rtt);
|
375 |
|
|
self.removeAllListeners();
|
376 |
|
|
});
|
377 |
|
|
}
|
378 |
|
|
|
379 |
|
|
inherits(InfoAjax, EventEmitter);
|
380 |
|
|
|
381 |
|
|
InfoAjax.prototype.close = function() {
|
382 |
|
|
this.removeAllListeners();
|
383 |
|
|
this.xo.close();
|
384 |
|
|
};
|
385 |
|
|
|
386 |
|
|
module.exports = InfoAjax;
|
387 |
|
|
|
388 |
|
|
}).call(this,{ env: {} })
|
389 |
|
|
|
390 |
|
|
},{"./utils/object":49,"debug":55,"events":3,"inherits":57,"json3":58}],10:[function(require,module,exports){
|
391 |
|
|
'use strict';
|
392 |
|
|
|
393 |
|
|
var inherits = require('inherits')
|
394 |
|
|
, EventEmitter = require('events').EventEmitter
|
395 |
|
|
, JSON3 = require('json3')
|
396 |
|
|
, XHRLocalObject = require('./transport/sender/xhr-local')
|
397 |
|
|
, InfoAjax = require('./info-ajax')
|
398 |
|
|
;
|
399 |
|
|
|
400 |
|
|
function InfoReceiverIframe(transUrl) {
|
401 |
|
|
var self = this;
|
402 |
|
|
EventEmitter.call(this);
|
403 |
|
|
|
404 |
|
|
this.ir = new InfoAjax(transUrl, XHRLocalObject);
|
405 |
|
|
this.ir.once('finish', function(info, rtt) {
|
406 |
|
|
self.ir = null;
|
407 |
|
|
self.emit('message', JSON3.stringify([info, rtt]));
|
408 |
|
|
});
|
409 |
|
|
}
|
410 |
|
|
|
411 |
|
|
inherits(InfoReceiverIframe, EventEmitter);
|
412 |
|
|
|
413 |
|
|
InfoReceiverIframe.transportName = 'iframe-info-receiver';
|
414 |
|
|
|
415 |
|
|
InfoReceiverIframe.prototype.close = function() {
|
416 |
|
|
if (this.ir) {
|
417 |
|
|
this.ir.close();
|
418 |
|
|
this.ir = null;
|
419 |
|
|
}
|
420 |
|
|
this.removeAllListeners();
|
421 |
|
|
};
|
422 |
|
|
|
423 |
|
|
module.exports = InfoReceiverIframe;
|
424 |
|
|
|
425 |
|
|
},{"./info-ajax":9,"./transport/sender/xhr-local":37,"events":3,"inherits":57,"json3":58}],11:[function(require,module,exports){
|
426 |
|
|
(function (process,global){
|
427 |
|
|
'use strict';
|
428 |
|
|
|
429 |
|
|
var EventEmitter = require('events').EventEmitter
|
430 |
|
|
, inherits = require('inherits')
|
431 |
|
|
, JSON3 = require('json3')
|
432 |
|
|
, utils = require('./utils/event')
|
433 |
|
|
, IframeTransport = require('./transport/iframe')
|
434 |
|
|
, InfoReceiverIframe = require('./info-iframe-receiver')
|
435 |
|
|
;
|
436 |
|
|
|
437 |
|
|
var debug = function() {};
|
438 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
439 |
|
|
debug = require('debug')('sockjs-client:info-iframe');
|
440 |
|
|
}
|
441 |
|
|
|
442 |
|
|
function InfoIframe(baseUrl, url) {
|
443 |
|
|
var self = this;
|
444 |
|
|
EventEmitter.call(this);
|
445 |
|
|
|
446 |
|
|
var go = function() {
|
447 |
|
|
var ifr = self.ifr = new IframeTransport(InfoReceiverIframe.transportName, url, baseUrl);
|
448 |
|
|
|
449 |
|
|
ifr.once('message', function(msg) {
|
450 |
|
|
if (msg) {
|
451 |
|
|
var d;
|
452 |
|
|
try {
|
453 |
|
|
d = JSON3.parse(msg);
|
454 |
|
|
} catch (e) {
|
455 |
|
|
debug('bad json', msg);
|
456 |
|
|
self.emit('finish');
|
457 |
|
|
self.close();
|
458 |
|
|
return;
|
459 |
|
|
}
|
460 |
|
|
|
461 |
|
|
var info = d[0], rtt = d[1];
|
462 |
|
|
self.emit('finish', info, rtt);
|
463 |
|
|
}
|
464 |
|
|
self.close();
|
465 |
|
|
});
|
466 |
|
|
|
467 |
|
|
ifr.once('close', function() {
|
468 |
|
|
self.emit('finish');
|
469 |
|
|
self.close();
|
470 |
|
|
});
|
471 |
|
|
};
|
472 |
|
|
|
473 |
|
|
// TODO this seems the same as the 'needBody' from transports
|
474 |
|
|
if (!global.document.body) {
|
475 |
|
|
utils.attachEvent('load', go);
|
476 |
|
|
} else {
|
477 |
|
|
go();
|
478 |
|
|
}
|
479 |
|
|
}
|
480 |
|
|
|
481 |
|
|
inherits(InfoIframe, EventEmitter);
|
482 |
|
|
|
483 |
|
|
InfoIframe.enabled = function() {
|
484 |
|
|
return IframeTransport.enabled();
|
485 |
|
|
};
|
486 |
|
|
|
487 |
|
|
InfoIframe.prototype.close = function() {
|
488 |
|
|
if (this.ifr) {
|
489 |
|
|
this.ifr.close();
|
490 |
|
|
}
|
491 |
|
|
this.removeAllListeners();
|
492 |
|
|
this.ifr = null;
|
493 |
|
|
};
|
494 |
|
|
|
495 |
|
|
module.exports = InfoIframe;
|
496 |
|
|
|
497 |
|
|
}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
498 |
|
|
|
499 |
|
|
},{"./info-iframe-receiver":10,"./transport/iframe":22,"./utils/event":46,"debug":55,"events":3,"inherits":57,"json3":58}],12:[function(require,module,exports){
|
500 |
|
|
(function (process){
|
501 |
|
|
'use strict';
|
502 |
|
|
|
503 |
|
|
var EventEmitter = require('events').EventEmitter
|
504 |
|
|
, inherits = require('inherits')
|
505 |
|
|
, urlUtils = require('./utils/url')
|
506 |
|
|
, XDR = require('./transport/sender/xdr')
|
507 |
|
|
, XHRCors = require('./transport/sender/xhr-cors')
|
508 |
|
|
, XHRLocal = require('./transport/sender/xhr-local')
|
509 |
|
|
, XHRFake = require('./transport/sender/xhr-fake')
|
510 |
|
|
, InfoIframe = require('./info-iframe')
|
511 |
|
|
, InfoAjax = require('./info-ajax')
|
512 |
|
|
;
|
513 |
|
|
|
514 |
|
|
var debug = function() {};
|
515 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
516 |
|
|
debug = require('debug')('sockjs-client:info-receiver');
|
517 |
|
|
}
|
518 |
|
|
|
519 |
|
|
function InfoReceiver(baseUrl, urlInfo) {
|
520 |
|
|
debug(baseUrl);
|
521 |
|
|
var self = this;
|
522 |
|
|
EventEmitter.call(this);
|
523 |
|
|
|
524 |
|
|
setTimeout(function() {
|
525 |
|
|
self.doXhr(baseUrl, urlInfo);
|
526 |
|
|
}, 0);
|
527 |
|
|
}
|
528 |
|
|
|
529 |
|
|
inherits(InfoReceiver, EventEmitter);
|
530 |
|
|
|
531 |
|
|
// TODO this is currently ignoring the list of available transports and the whitelist
|
532 |
|
|
|
533 |
|
|
InfoReceiver._getReceiver = function(baseUrl, url, urlInfo) {
|
534 |
|
|
// determine method of CORS support (if needed)
|
535 |
|
|
if (urlInfo.sameOrigin) {
|
536 |
|
|
return new InfoAjax(url, XHRLocal);
|
537 |
|
|
}
|
538 |
|
|
if (XHRCors.enabled) {
|
539 |
|
|
return new InfoAjax(url, XHRCors);
|
540 |
|
|
}
|
541 |
|
|
if (XDR.enabled && urlInfo.sameScheme) {
|
542 |
|
|
return new InfoAjax(url, XDR);
|
543 |
|
|
}
|
544 |
|
|
if (InfoIframe.enabled()) {
|
545 |
|
|
return new InfoIframe(baseUrl, url);
|
546 |
|
|
}
|
547 |
|
|
return new InfoAjax(url, XHRFake);
|
548 |
|
|
};
|
549 |
|
|
|
550 |
|
|
InfoReceiver.prototype.doXhr = function(baseUrl, urlInfo) {
|
551 |
|
|
var self = this
|
552 |
|
|
, url = urlUtils.addPath(baseUrl, '/info')
|
553 |
|
|
;
|
554 |
|
|
debug('doXhr', url);
|
555 |
|
|
|
556 |
|
|
this.xo = InfoReceiver._getReceiver(baseUrl, url, urlInfo);
|
557 |
|
|
|
558 |
|
|
this.timeoutRef = setTimeout(function() {
|
559 |
|
|
debug('timeout');
|
560 |
|
|
self._cleanup(false);
|
561 |
|
|
self.emit('finish');
|
562 |
|
|
}, InfoReceiver.timeout);
|
563 |
|
|
|
564 |
|
|
this.xo.once('finish', function(info, rtt) {
|
565 |
|
|
debug('finish', info, rtt);
|
566 |
|
|
self._cleanup(true);
|
567 |
|
|
self.emit('finish', info, rtt);
|
568 |
|
|
});
|
569 |
|
|
};
|
570 |
|
|
|
571 |
|
|
InfoReceiver.prototype._cleanup = function(wasClean) {
|
572 |
|
|
debug('_cleanup');
|
573 |
|
|
clearTimeout(this.timeoutRef);
|
574 |
|
|
this.timeoutRef = null;
|
575 |
|
|
if (!wasClean && this.xo) {
|
576 |
|
|
this.xo.close();
|
577 |
|
|
}
|
578 |
|
|
this.xo = null;
|
579 |
|
|
};
|
580 |
|
|
|
581 |
|
|
InfoReceiver.prototype.close = function() {
|
582 |
|
|
debug('close');
|
583 |
|
|
this.removeAllListeners();
|
584 |
|
|
this._cleanup(false);
|
585 |
|
|
};
|
586 |
|
|
|
587 |
|
|
InfoReceiver.timeout = 8000;
|
588 |
|
|
|
589 |
|
|
module.exports = InfoReceiver;
|
590 |
|
|
|
591 |
|
|
}).call(this,{ env: {} })
|
592 |
|
|
|
593 |
|
|
},{"./info-ajax":9,"./info-iframe":11,"./transport/sender/xdr":34,"./transport/sender/xhr-cors":35,"./transport/sender/xhr-fake":36,"./transport/sender/xhr-local":37,"./utils/url":52,"debug":55,"events":3,"inherits":57}],13:[function(require,module,exports){
|
594 |
|
|
(function (global){
|
595 |
|
|
'use strict';
|
596 |
|
|
|
597 |
|
|
module.exports = global.location || {
|
598 |
|
|
origin: 'http://localhost:80'
|
599 |
|
|
, protocol: 'http:'
|
600 |
|
|
, host: 'localhost'
|
601 |
|
|
, port: 80
|
602 |
|
|
, href: 'http://localhost/'
|
603 |
|
|
, hash: ''
|
604 |
|
|
};
|
605 |
|
|
|
606 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
607 |
|
|
|
608 |
|
|
},{}],14:[function(require,module,exports){
|
609 |
|
|
(function (process,global){
|
610 |
|
|
'use strict';
|
611 |
|
|
|
612 |
|
|
require('./shims');
|
613 |
|
|
|
614 |
|
|
var URL = require('url-parse')
|
615 |
|
|
, inherits = require('inherits')
|
616 |
|
|
, JSON3 = require('json3')
|
617 |
|
|
, random = require('./utils/random')
|
618 |
|
|
, escape = require('./utils/escape')
|
619 |
|
|
, urlUtils = require('./utils/url')
|
620 |
|
|
, eventUtils = require('./utils/event')
|
621 |
|
|
, transport = require('./utils/transport')
|
622 |
|
|
, objectUtils = require('./utils/object')
|
623 |
|
|
, browser = require('./utils/browser')
|
624 |
|
|
, log = require('./utils/log')
|
625 |
|
|
, Event = require('./event/event')
|
626 |
|
|
, EventTarget = require('./event/eventtarget')
|
627 |
|
|
, loc = require('./location')
|
628 |
|
|
, CloseEvent = require('./event/close')
|
629 |
|
|
, TransportMessageEvent = require('./event/trans-message')
|
630 |
|
|
, InfoReceiver = require('./info-receiver')
|
631 |
|
|
;
|
632 |
|
|
|
633 |
|
|
var debug = function() {};
|
634 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
635 |
|
|
debug = require('debug')('sockjs-client:main');
|
636 |
|
|
}
|
637 |
|
|
|
638 |
|
|
var transports;
|
639 |
|
|
|
640 |
|
|
// follow constructor steps defined at http://dev.w3.org/html5/websockets/#the-websocket-interface
|
641 |
|
|
function SockJS(url, protocols, options) {
|
642 |
|
|
if (!(this instanceof SockJS)) {
|
643 |
|
|
return new SockJS(url, protocols, options);
|
644 |
|
|
}
|
645 |
|
|
if (arguments.length < 1) {
|
646 |
|
|
throw new TypeError("Failed to construct 'SockJS: 1 argument required, but only 0 present");
|
647 |
|
|
}
|
648 |
|
|
EventTarget.call(this);
|
649 |
|
|
|
650 |
|
|
this.readyState = SockJS.CONNECTING;
|
651 |
|
|
this.extensions = '';
|
652 |
|
|
this.protocol = '';
|
653 |
|
|
|
654 |
|
|
// non-standard extension
|
655 |
|
|
options = options || {};
|
656 |
|
|
if (options.protocols_whitelist) {
|
657 |
|
|
log.warn("'protocols_whitelist' is DEPRECATED. Use 'transports' instead.");
|
658 |
|
|
}
|
659 |
|
|
this._transportsWhitelist = options.transports;
|
660 |
|
|
this._transportOptions = options.transportOptions || {};
|
661 |
|
|
this._timeout = options.timeout || 0;
|
662 |
|
|
|
663 |
|
|
var sessionId = options.sessionId || 8;
|
664 |
|
|
if (typeof sessionId === 'function') {
|
665 |
|
|
this._generateSessionId = sessionId;
|
666 |
|
|
} else if (typeof sessionId === 'number') {
|
667 |
|
|
this._generateSessionId = function() {
|
668 |
|
|
return random.string(sessionId);
|
669 |
|
|
};
|
670 |
|
|
} else {
|
671 |
|
|
throw new TypeError('If sessionId is used in the options, it needs to be a number or a function.');
|
672 |
|
|
}
|
673 |
|
|
|
674 |
|
|
this._server = options.server || random.numberString(1000);
|
675 |
|
|
|
676 |
|
|
// Step 1 of WS spec - parse and validate the url. Issue #8
|
677 |
|
|
var parsedUrl = new URL(url);
|
678 |
|
|
if (!parsedUrl.host || !parsedUrl.protocol) {
|
679 |
|
|
throw new SyntaxError("The URL '" + url + "' is invalid");
|
680 |
|
|
} else if (parsedUrl.hash) {
|
681 |
|
|
throw new SyntaxError('The URL must not contain a fragment');
|
682 |
|
|
} else if (parsedUrl.protocol !== 'http:' && parsedUrl.protocol !== 'https:') {
|
683 |
|
|
throw new SyntaxError("The URL's scheme must be either 'http:' or 'https:'. '" + parsedUrl.protocol + "' is not allowed.");
|
684 |
|
|
}
|
685 |
|
|
|
686 |
|
|
var secure = parsedUrl.protocol === 'https:';
|
687 |
|
|
// Step 2 - don't allow secure origin with an insecure protocol
|
688 |
|
|
if (loc.protocol === 'https:' && !secure) {
|
689 |
|
|
throw new Error('SecurityError: An insecure SockJS connection may not be initiated from a page loaded over HTTPS');
|
690 |
|
|
}
|
691 |
|
|
|
692 |
|
|
// Step 3 - check port access - no need here
|
693 |
|
|
// Step 4 - parse protocols argument
|
694 |
|
|
if (!protocols) {
|
695 |
|
|
protocols = [];
|
696 |
|
|
} else if (!Array.isArray(protocols)) {
|
697 |
|
|
protocols = [protocols];
|
698 |
|
|
}
|
699 |
|
|
|
700 |
|
|
// Step 5 - check protocols argument
|
701 |
|
|
var sortedProtocols = protocols.sort();
|
702 |
|
|
sortedProtocols.forEach(function(proto, i) {
|
703 |
|
|
if (!proto) {
|
704 |
|
|
throw new SyntaxError("The protocols entry '" + proto + "' is invalid.");
|
705 |
|
|
}
|
706 |
|
|
if (i < (sortedProtocols.length - 1) && proto === sortedProtocols[i + 1]) {
|
707 |
|
|
throw new SyntaxError("The protocols entry '" + proto + "' is duplicated.");
|
708 |
|
|
}
|
709 |
|
|
});
|
710 |
|
|
|
711 |
|
|
// Step 6 - convert origin
|
712 |
|
|
var o = urlUtils.getOrigin(loc.href);
|
713 |
|
|
this._origin = o ? o.toLowerCase() : null;
|
714 |
|
|
|
715 |
|
|
// remove the trailing slash
|
716 |
|
|
parsedUrl.set('pathname', parsedUrl.pathname.replace(/\/+$/, ''));
|
717 |
|
|
|
718 |
|
|
// store the sanitized url
|
719 |
|
|
this.url = parsedUrl.href;
|
720 |
|
|
debug('using url', this.url);
|
721 |
|
|
|
722 |
|
|
// Step 7 - start connection in background
|
723 |
|
|
// obtain server info
|
724 |
|
|
// http://sockjs.github.io/sockjs-protocol/sockjs-protocol-0.3.3.html#section-26
|
725 |
|
|
this._urlInfo = {
|
726 |
|
|
nullOrigin: !browser.hasDomain()
|
727 |
|
|
, sameOrigin: urlUtils.isOriginEqual(this.url, loc.href)
|
728 |
|
|
, sameScheme: urlUtils.isSchemeEqual(this.url, loc.href)
|
729 |
|
|
};
|
730 |
|
|
|
731 |
|
|
this._ir = new InfoReceiver(this.url, this._urlInfo);
|
732 |
|
|
this._ir.once('finish', this._receiveInfo.bind(this));
|
733 |
|
|
}
|
734 |
|
|
|
735 |
|
|
inherits(SockJS, EventTarget);
|
736 |
|
|
|
737 |
|
|
function userSetCode(code) {
|
738 |
|
|
return code === 1000 || (code >= 3000 && code <= 4999);
|
739 |
|
|
}
|
740 |
|
|
|
741 |
|
|
SockJS.prototype.close = function(code, reason) {
|
742 |
|
|
// Step 1
|
743 |
|
|
if (code && !userSetCode(code)) {
|
744 |
|
|
throw new Error('InvalidAccessError: Invalid code');
|
745 |
|
|
}
|
746 |
|
|
// Step 2.4 states the max is 123 bytes, but we are just checking length
|
747 |
|
|
if (reason && reason.length > 123) {
|
748 |
|
|
throw new SyntaxError('reason argument has an invalid length');
|
749 |
|
|
}
|
750 |
|
|
|
751 |
|
|
// Step 3.1
|
752 |
|
|
if (this.readyState === SockJS.CLOSING || this.readyState === SockJS.CLOSED) {
|
753 |
|
|
return;
|
754 |
|
|
}
|
755 |
|
|
|
756 |
|
|
// TODO look at docs to determine how to set this
|
757 |
|
|
var wasClean = true;
|
758 |
|
|
this._close(code || 1000, reason || 'Normal closure', wasClean);
|
759 |
|
|
};
|
760 |
|
|
|
761 |
|
|
SockJS.prototype.send = function(data) {
|
762 |
|
|
// #13 - convert anything non-string to string
|
763 |
|
|
// TODO this currently turns objects into [object Object]
|
764 |
|
|
if (typeof data !== 'string') {
|
765 |
|
|
data = '' + data;
|
766 |
|
|
}
|
767 |
|
|
if (this.readyState === SockJS.CONNECTING) {
|
768 |
|
|
throw new Error('InvalidStateError: The connection has not been established yet');
|
769 |
|
|
}
|
770 |
|
|
if (this.readyState !== SockJS.OPEN) {
|
771 |
|
|
return;
|
772 |
|
|
}
|
773 |
|
|
this._transport.send(escape.quote(data));
|
774 |
|
|
};
|
775 |
|
|
|
776 |
|
|
SockJS.version = require('./version');
|
777 |
|
|
|
778 |
|
|
SockJS.CONNECTING = 0;
|
779 |
|
|
SockJS.OPEN = 1;
|
780 |
|
|
SockJS.CLOSING = 2;
|
781 |
|
|
SockJS.CLOSED = 3;
|
782 |
|
|
|
783 |
|
|
SockJS.prototype._receiveInfo = function(info, rtt) {
|
784 |
|
|
debug('_receiveInfo', rtt);
|
785 |
|
|
this._ir = null;
|
786 |
|
|
if (!info) {
|
787 |
|
|
this._close(1002, 'Cannot connect to server');
|
788 |
|
|
return;
|
789 |
|
|
}
|
790 |
|
|
|
791 |
|
|
// establish a round-trip timeout (RTO) based on the
|
792 |
|
|
// round-trip time (RTT)
|
793 |
|
|
this._rto = this.countRTO(rtt);
|
794 |
|
|
// allow server to override url used for the actual transport
|
795 |
|
|
this._transUrl = info.base_url ? info.base_url : this.url;
|
796 |
|
|
info = objectUtils.extend(info, this._urlInfo);
|
797 |
|
|
debug('info', info);
|
798 |
|
|
// determine list of desired and supported transports
|
799 |
|
|
var enabledTransports = transports.filterToEnabled(this._transportsWhitelist, info);
|
800 |
|
|
this._transports = enabledTransports.main;
|
801 |
|
|
debug(this._transports.length + ' enabled transports');
|
802 |
|
|
|
803 |
|
|
this._connect();
|
804 |
|
|
};
|
805 |
|
|
|
806 |
|
|
SockJS.prototype._connect = function() {
|
807 |
|
|
for (var Transport = this._transports.shift(); Transport; Transport = this._transports.shift()) {
|
808 |
|
|
debug('attempt', Transport.transportName);
|
809 |
|
|
if (Transport.needBody) {
|
810 |
|
|
if (!global.document.body ||
|
811 |
|
|
(typeof global.document.readyState !== 'undefined' &&
|
812 |
|
|
global.document.readyState !== 'complete' &&
|
813 |
|
|
global.document.readyState !== 'interactive')) {
|
814 |
|
|
debug('waiting for body');
|
815 |
|
|
this._transports.unshift(Transport);
|
816 |
|
|
eventUtils.attachEvent('load', this._connect.bind(this));
|
817 |
|
|
return;
|
818 |
|
|
}
|
819 |
|
|
}
|
820 |
|
|
|
821 |
|
|
// calculate timeout based on RTO and round trips. Default to 5s
|
822 |
|
|
var timeoutMs = Math.max(this._timeout, (this._rto * Transport.roundTrips) || 5000);
|
823 |
|
|
this._transportTimeoutId = setTimeout(this._transportTimeout.bind(this), timeoutMs);
|
824 |
|
|
debug('using timeout', timeoutMs);
|
825 |
|
|
|
826 |
|
|
var transportUrl = urlUtils.addPath(this._transUrl, '/' + this._server + '/' + this._generateSessionId());
|
827 |
|
|
var options = this._transportOptions[Transport.transportName];
|
828 |
|
|
debug('transport url', transportUrl);
|
829 |
|
|
var transportObj = new Transport(transportUrl, this._transUrl, options);
|
830 |
|
|
transportObj.on('message', this._transportMessage.bind(this));
|
831 |
|
|
transportObj.once('close', this._transportClose.bind(this));
|
832 |
|
|
transportObj.transportName = Transport.transportName;
|
833 |
|
|
this._transport = transportObj;
|
834 |
|
|
|
835 |
|
|
return;
|
836 |
|
|
}
|
837 |
|
|
this._close(2000, 'All transports failed', false);
|
838 |
|
|
};
|
839 |
|
|
|
840 |
|
|
SockJS.prototype._transportTimeout = function() {
|
841 |
|
|
debug('_transportTimeout');
|
842 |
|
|
if (this.readyState === SockJS.CONNECTING) {
|
843 |
|
|
if (this._transport) {
|
844 |
|
|
this._transport.close();
|
845 |
|
|
}
|
846 |
|
|
|
847 |
|
|
this._transportClose(2007, 'Transport timed out');
|
848 |
|
|
}
|
849 |
|
|
};
|
850 |
|
|
|
851 |
|
|
SockJS.prototype._transportMessage = function(msg) {
|
852 |
|
|
debug('_transportMessage', msg);
|
853 |
|
|
var self = this
|
854 |
|
|
, type = msg.slice(0, 1)
|
855 |
|
|
, content = msg.slice(1)
|
856 |
|
|
, payload
|
857 |
|
|
;
|
858 |
|
|
|
859 |
|
|
// first check for messages that don't need a payload
|
860 |
|
|
switch (type) {
|
861 |
|
|
case 'o':
|
862 |
|
|
this._open();
|
863 |
|
|
return;
|
864 |
|
|
case 'h':
|
865 |
|
|
this.dispatchEvent(new Event('heartbeat'));
|
866 |
|
|
debug('heartbeat', this.transport);
|
867 |
|
|
return;
|
868 |
|
|
}
|
869 |
|
|
|
870 |
|
|
if (content) {
|
871 |
|
|
try {
|
872 |
|
|
payload = JSON3.parse(content);
|
873 |
|
|
} catch (e) {
|
874 |
|
|
debug('bad json', content);
|
875 |
|
|
}
|
876 |
|
|
}
|
877 |
|
|
|
878 |
|
|
if (typeof payload === 'undefined') {
|
879 |
|
|
debug('empty payload', content);
|
880 |
|
|
return;
|
881 |
|
|
}
|
882 |
|
|
|
883 |
|
|
switch (type) {
|
884 |
|
|
case 'a':
|
885 |
|
|
if (Array.isArray(payload)) {
|
886 |
|
|
payload.forEach(function(p) {
|
887 |
|
|
debug('message', self.transport, p);
|
888 |
|
|
self.dispatchEvent(new TransportMessageEvent(p));
|
889 |
|
|
});
|
890 |
|
|
}
|
891 |
|
|
break;
|
892 |
|
|
case 'm':
|
893 |
|
|
debug('message', this.transport, payload);
|
894 |
|
|
this.dispatchEvent(new TransportMessageEvent(payload));
|
895 |
|
|
break;
|
896 |
|
|
case 'c':
|
897 |
|
|
if (Array.isArray(payload) && payload.length === 2) {
|
898 |
|
|
this._close(payload[0], payload[1], true);
|
899 |
|
|
}
|
900 |
|
|
break;
|
901 |
|
|
}
|
902 |
|
|
};
|
903 |
|
|
|
904 |
|
|
SockJS.prototype._transportClose = function(code, reason) {
|
905 |
|
|
debug('_transportClose', this.transport, code, reason);
|
906 |
|
|
if (this._transport) {
|
907 |
|
|
this._transport.removeAllListeners();
|
908 |
|
|
this._transport = null;
|
909 |
|
|
this.transport = null;
|
910 |
|
|
}
|
911 |
|
|
|
912 |
|
|
if (!userSetCode(code) && code !== 2000 && this.readyState === SockJS.CONNECTING) {
|
913 |
|
|
this._connect();
|
914 |
|
|
return;
|
915 |
|
|
}
|
916 |
|
|
|
917 |
|
|
this._close(code, reason);
|
918 |
|
|
};
|
919 |
|
|
|
920 |
|
|
SockJS.prototype._open = function() {
|
921 |
|
|
debug('_open', this._transport && this._transport.transportName, this.readyState);
|
922 |
|
|
if (this.readyState === SockJS.CONNECTING) {
|
923 |
|
|
if (this._transportTimeoutId) {
|
924 |
|
|
clearTimeout(this._transportTimeoutId);
|
925 |
|
|
this._transportTimeoutId = null;
|
926 |
|
|
}
|
927 |
|
|
this.readyState = SockJS.OPEN;
|
928 |
|
|
this.transport = this._transport.transportName;
|
929 |
|
|
this.dispatchEvent(new Event('open'));
|
930 |
|
|
debug('connected', this.transport);
|
931 |
|
|
} else {
|
932 |
|
|
// The server might have been restarted, and lost track of our
|
933 |
|
|
// connection.
|
934 |
|
|
this._close(1006, 'Server lost session');
|
935 |
|
|
}
|
936 |
|
|
};
|
937 |
|
|
|
938 |
|
|
SockJS.prototype._close = function(code, reason, wasClean) {
|
939 |
|
|
debug('_close', this.transport, code, reason, wasClean, this.readyState);
|
940 |
|
|
var forceFail = false;
|
941 |
|
|
|
942 |
|
|
if (this._ir) {
|
943 |
|
|
forceFail = true;
|
944 |
|
|
this._ir.close();
|
945 |
|
|
this._ir = null;
|
946 |
|
|
}
|
947 |
|
|
if (this._transport) {
|
948 |
|
|
this._transport.close();
|
949 |
|
|
this._transport = null;
|
950 |
|
|
this.transport = null;
|
951 |
|
|
}
|
952 |
|
|
|
953 |
|
|
if (this.readyState === SockJS.CLOSED) {
|
954 |
|
|
throw new Error('InvalidStateError: SockJS has already been closed');
|
955 |
|
|
}
|
956 |
|
|
|
957 |
|
|
this.readyState = SockJS.CLOSING;
|
958 |
|
|
setTimeout(function() {
|
959 |
|
|
this.readyState = SockJS.CLOSED;
|
960 |
|
|
|
961 |
|
|
if (forceFail) {
|
962 |
|
|
this.dispatchEvent(new Event('error'));
|
963 |
|
|
}
|
964 |
|
|
|
965 |
|
|
var e = new CloseEvent('close');
|
966 |
|
|
e.wasClean = wasClean || false;
|
967 |
|
|
e.code = code || 1000;
|
968 |
|
|
e.reason = reason;
|
969 |
|
|
|
970 |
|
|
this.dispatchEvent(e);
|
971 |
|
|
this.onmessage = this.onclose = this.onerror = null;
|
972 |
|
|
debug('disconnected');
|
973 |
|
|
}.bind(this), 0);
|
974 |
|
|
};
|
975 |
|
|
|
976 |
|
|
// See: http://www.erg.abdn.ac.uk/~gerrit/dccp/notes/ccid2/rto_estimator/
|
977 |
|
|
// and RFC 2988.
|
978 |
|
|
SockJS.prototype.countRTO = function(rtt) {
|
979 |
|
|
// In a local environment, when using IE8/9 and the `jsonp-polling`
|
980 |
|
|
// transport the time needed to establish a connection (the time that pass
|
981 |
|
|
// from the opening of the transport to the call of `_dispatchOpen`) is
|
982 |
|
|
// around 200msec (the lower bound used in the article above) and this
|
983 |
|
|
// causes spurious timeouts. For this reason we calculate a value slightly
|
984 |
|
|
// larger than that used in the article.
|
985 |
|
|
if (rtt > 100) {
|
986 |
|
|
return 4 * rtt; // rto > 400msec
|
987 |
|
|
}
|
988 |
|
|
return 300 + rtt; // 300msec < rto <= 400msec
|
989 |
|
|
};
|
990 |
|
|
|
991 |
|
|
module.exports = function(availableTransports) {
|
992 |
|
|
transports = transport(availableTransports);
|
993 |
|
|
require('./iframe-bootstrap')(SockJS, availableTransports);
|
994 |
|
|
return SockJS;
|
995 |
|
|
};
|
996 |
|
|
|
997 |
|
|
}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
998 |
|
|
|
999 |
|
|
},{"./event/close":2,"./event/event":4,"./event/eventtarget":5,"./event/trans-message":6,"./iframe-bootstrap":8,"./info-receiver":12,"./location":13,"./shims":15,"./utils/browser":44,"./utils/escape":45,"./utils/event":46,"./utils/log":48,"./utils/object":49,"./utils/random":50,"./utils/transport":51,"./utils/url":52,"./version":53,"debug":55,"inherits":57,"json3":58,"url-parse":61}],15:[function(require,module,exports){
|
1000 |
|
|
/* eslint-disable */
|
1001 |
|
|
/* jscs: disable */
|
1002 |
|
|
'use strict';
|
1003 |
|
|
|
1004 |
|
|
// pulled specific shims from https://github.com/es-shims/es5-shim
|
1005 |
|
|
|
1006 |
|
|
var ArrayPrototype = Array.prototype;
|
1007 |
|
|
var ObjectPrototype = Object.prototype;
|
1008 |
|
|
var FunctionPrototype = Function.prototype;
|
1009 |
|
|
var StringPrototype = String.prototype;
|
1010 |
|
|
var array_slice = ArrayPrototype.slice;
|
1011 |
|
|
|
1012 |
|
|
var _toString = ObjectPrototype.toString;
|
1013 |
|
|
var isFunction = function (val) {
|
1014 |
|
|
return ObjectPrototype.toString.call(val) === '[object Function]';
|
1015 |
|
|
};
|
1016 |
|
|
var isArray = function isArray(obj) {
|
1017 |
|
|
return _toString.call(obj) === '[object Array]';
|
1018 |
|
|
};
|
1019 |
|
|
var isString = function isString(obj) {
|
1020 |
|
|
return _toString.call(obj) === '[object String]';
|
1021 |
|
|
};
|
1022 |
|
|
|
1023 |
|
|
var supportsDescriptors = Object.defineProperty && (function () {
|
1024 |
|
|
try {
|
1025 |
|
|
Object.defineProperty({}, 'x', {});
|
1026 |
|
|
return true;
|
1027 |
|
|
} catch (e) { /* this is ES3 */
|
1028 |
|
|
return false;
|
1029 |
|
|
}
|
1030 |
|
|
}());
|
1031 |
|
|
|
1032 |
|
|
// Define configurable, writable and non-enumerable props
|
1033 |
|
|
// if they don't exist.
|
1034 |
|
|
var defineProperty;
|
1035 |
|
|
if (supportsDescriptors) {
|
1036 |
|
|
defineProperty = function (object, name, method, forceAssign) {
|
1037 |
|
|
if (!forceAssign && (name in object)) { return; }
|
1038 |
|
|
Object.defineProperty(object, name, {
|
1039 |
|
|
configurable: true,
|
1040 |
|
|
enumerable: false,
|
1041 |
|
|
writable: true,
|
1042 |
|
|
value: method
|
1043 |
|
|
});
|
1044 |
|
|
};
|
1045 |
|
|
} else {
|
1046 |
|
|
defineProperty = function (object, name, method, forceAssign) {
|
1047 |
|
|
if (!forceAssign && (name in object)) { return; }
|
1048 |
|
|
object[name] = method;
|
1049 |
|
|
};
|
1050 |
|
|
}
|
1051 |
|
|
var defineProperties = function (object, map, forceAssign) {
|
1052 |
|
|
for (var name in map) {
|
1053 |
|
|
if (ObjectPrototype.hasOwnProperty.call(map, name)) {
|
1054 |
|
|
defineProperty(object, name, map[name], forceAssign);
|
1055 |
|
|
}
|
1056 |
|
|
}
|
1057 |
|
|
};
|
1058 |
|
|
|
1059 |
|
|
var toObject = function (o) {
|
1060 |
|
|
if (o == null) { // this matches both null and undefined
|
1061 |
|
|
throw new TypeError("can't convert " + o + ' to object');
|
1062 |
|
|
}
|
1063 |
|
|
return Object(o);
|
1064 |
|
|
};
|
1065 |
|
|
|
1066 |
|
|
//
|
1067 |
|
|
// Util
|
1068 |
|
|
// ======
|
1069 |
|
|
//
|
1070 |
|
|
|
1071 |
|
|
// ES5 9.4
|
1072 |
|
|
// http://es5.github.com/#x9.4
|
1073 |
|
|
// http://jsperf.com/to-integer
|
1074 |
|
|
|
1075 |
|
|
function toInteger(num) {
|
1076 |
|
|
var n = +num;
|
1077 |
|
|
if (n !== n) { // isNaN
|
1078 |
|
|
n = 0;
|
1079 |
|
|
} else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
|
1080 |
|
|
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
1081 |
|
|
}
|
1082 |
|
|
return n;
|
1083 |
|
|
}
|
1084 |
|
|
|
1085 |
|
|
function ToUint32(x) {
|
1086 |
|
|
return x >>> 0;
|
1087 |
|
|
}
|
1088 |
|
|
|
1089 |
|
|
//
|
1090 |
|
|
// Function
|
1091 |
|
|
// ========
|
1092 |
|
|
//
|
1093 |
|
|
|
1094 |
|
|
// ES-5 15.3.4.5
|
1095 |
|
|
// http://es5.github.com/#x15.3.4.5
|
1096 |
|
|
|
1097 |
|
|
function Empty() {}
|
1098 |
|
|
|
1099 |
|
|
defineProperties(FunctionPrototype, {
|
1100 |
|
|
bind: function bind(that) { // .length is 1
|
1101 |
|
|
// 1. Let Target be the this value.
|
1102 |
|
|
var target = this;
|
1103 |
|
|
// 2. If IsCallable(Target) is false, throw a TypeError exception.
|
1104 |
|
|
if (!isFunction(target)) {
|
1105 |
|
|
throw new TypeError('Function.prototype.bind called on incompatible ' + target);
|
1106 |
|
|
}
|
1107 |
|
|
// 3. Let A be a new (possibly empty) internal list of all of the
|
1108 |
|
|
// argument values provided after thisArg (arg1, arg2 etc), in order.
|
1109 |
|
|
// XXX slicedArgs will stand in for "A" if used
|
1110 |
|
|
var args = array_slice.call(arguments, 1); // for normal call
|
1111 |
|
|
// 4. Let F be a new native ECMAScript object.
|
1112 |
|
|
// 11. Set the [[Prototype]] internal property of F to the standard
|
1113 |
|
|
// built-in Function prototype object as specified in 15.3.3.1.
|
1114 |
|
|
// 12. Set the [[Call]] internal property of F as described in
|
1115 |
|
|
// 15.3.4.5.1.
|
1116 |
|
|
// 13. Set the [[Construct]] internal property of F as described in
|
1117 |
|
|
// 15.3.4.5.2.
|
1118 |
|
|
// 14. Set the [[HasInstance]] internal property of F as described in
|
1119 |
|
|
// 15.3.4.5.3.
|
1120 |
|
|
var binder = function () {
|
1121 |
|
|
|
1122 |
|
|
if (this instanceof bound) {
|
1123 |
|
|
// 15.3.4.5.2 [[Construct]]
|
1124 |
|
|
// When the [[Construct]] internal method of a function object,
|
1125 |
|
|
// F that was created using the bind function is called with a
|
1126 |
|
|
// list of arguments ExtraArgs, the following steps are taken:
|
1127 |
|
|
// 1. Let target be the value of F's [[TargetFunction]]
|
1128 |
|
|
// internal property.
|
1129 |
|
|
// 2. If target has no [[Construct]] internal method, a
|
1130 |
|
|
// TypeError exception is thrown.
|
1131 |
|
|
// 3. Let boundArgs be the value of F's [[BoundArgs]] internal
|
1132 |
|
|
// property.
|
1133 |
|
|
// 4. Let args be a new list containing the same values as the
|
1134 |
|
|
// list boundArgs in the same order followed by the same
|
1135 |
|
|
// values as the list ExtraArgs in the same order.
|
1136 |
|
|
// 5. Return the result of calling the [[Construct]] internal
|
1137 |
|
|
// method of target providing args as the arguments.
|
1138 |
|
|
|
1139 |
|
|
var result = target.apply(
|
1140 |
|
|
this,
|
1141 |
|
|
args.concat(array_slice.call(arguments))
|
1142 |
|
|
);
|
1143 |
|
|
if (Object(result) === result) {
|
1144 |
|
|
return result;
|
1145 |
|
|
}
|
1146 |
|
|
return this;
|
1147 |
|
|
|
1148 |
|
|
} else {
|
1149 |
|
|
// 15.3.4.5.1 [[Call]]
|
1150 |
|
|
// When the [[Call]] internal method of a function object, F,
|
1151 |
|
|
// which was created using the bind function is called with a
|
1152 |
|
|
// this value and a list of arguments ExtraArgs, the following
|
1153 |
|
|
// steps are taken:
|
1154 |
|
|
// 1. Let boundArgs be the value of F's [[BoundArgs]] internal
|
1155 |
|
|
// property.
|
1156 |
|
|
// 2. Let boundThis be the value of F's [[BoundThis]] internal
|
1157 |
|
|
// property.
|
1158 |
|
|
// 3. Let target be the value of F's [[TargetFunction]] internal
|
1159 |
|
|
// property.
|
1160 |
|
|
// 4. Let args be a new list containing the same values as the
|
1161 |
|
|
// list boundArgs in the same order followed by the same
|
1162 |
|
|
// values as the list ExtraArgs in the same order.
|
1163 |
|
|
// 5. Return the result of calling the [[Call]] internal method
|
1164 |
|
|
// of target providing boundThis as the this value and
|
1165 |
|
|
// providing args as the arguments.
|
1166 |
|
|
|
1167 |
|
|
// equiv: target.call(this, ...boundArgs, ...args)
|
1168 |
|
|
return target.apply(
|
1169 |
|
|
that,
|
1170 |
|
|
args.concat(array_slice.call(arguments))
|
1171 |
|
|
);
|
1172 |
|
|
|
1173 |
|
|
}
|
1174 |
|
|
|
1175 |
|
|
};
|
1176 |
|
|
|
1177 |
|
|
// 15. If the [[Class]] internal property of Target is "Function", then
|
1178 |
|
|
// a. Let L be the length property of Target minus the length of A.
|
1179 |
|
|
// b. Set the length own property of F to either 0 or L, whichever is
|
1180 |
|
|
// larger.
|
1181 |
|
|
// 16. Else set the length own property of F to 0.
|
1182 |
|
|
|
1183 |
|
|
var boundLength = Math.max(0, target.length - args.length);
|
1184 |
|
|
|
1185 |
|
|
// 17. Set the attributes of the length own property of F to the values
|
1186 |
|
|
// specified in 15.3.5.1.
|
1187 |
|
|
var boundArgs = [];
|
1188 |
|
|
for (var i = 0; i < boundLength; i++) {
|
1189 |
|
|
boundArgs.push('$' + i);
|
1190 |
|
|
}
|
1191 |
|
|
|
1192 |
|
|
// XXX Build a dynamic function with desired amount of arguments is the only
|
1193 |
|
|
// way to set the length property of a function.
|
1194 |
|
|
// In environments where Content Security Policies enabled (Chrome extensions,
|
1195 |
|
|
// for ex.) all use of eval or Function costructor throws an exception.
|
1196 |
|
|
// However in all of these environments Function.prototype.bind exists
|
1197 |
|
|
// and so this code will never be executed.
|
1198 |
|
|
var bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this, arguments); }')(binder);
|
1199 |
|
|
|
1200 |
|
|
if (target.prototype) {
|
1201 |
|
|
Empty.prototype = target.prototype;
|
1202 |
|
|
bound.prototype = new Empty();
|
1203 |
|
|
// Clean up dangling references.
|
1204 |
|
|
Empty.prototype = null;
|
1205 |
|
|
}
|
1206 |
|
|
|
1207 |
|
|
// TODO
|
1208 |
|
|
// 18. Set the [[Extensible]] internal property of F to true.
|
1209 |
|
|
|
1210 |
|
|
// TODO
|
1211 |
|
|
// 19. Let thrower be the [[ThrowTypeError]] function Object (13.2.3).
|
1212 |
|
|
// 20. Call the [[DefineOwnProperty]] internal method of F with
|
1213 |
|
|
// arguments "caller", PropertyDescriptor {[[Get]]: thrower, [[Set]]:
|
1214 |
|
|
// thrower, [[Enumerable]]: false, [[Configurable]]: false}, and
|
1215 |
|
|
// false.
|
1216 |
|
|
// 21. Call the [[DefineOwnProperty]] internal method of F with
|
1217 |
|
|
// arguments "arguments", PropertyDescriptor {[[Get]]: thrower,
|
1218 |
|
|
// [[Set]]: thrower, [[Enumerable]]: false, [[Configurable]]: false},
|
1219 |
|
|
// and false.
|
1220 |
|
|
|
1221 |
|
|
// TODO
|
1222 |
|
|
// NOTE Function objects created using Function.prototype.bind do not
|
1223 |
|
|
// have a prototype property or the [[Code]], [[FormalParameters]], and
|
1224 |
|
|
// [[Scope]] internal properties.
|
1225 |
|
|
// XXX can't delete prototype in pure-js.
|
1226 |
|
|
|
1227 |
|
|
// 22. Return F.
|
1228 |
|
|
return bound;
|
1229 |
|
|
}
|
1230 |
|
|
});
|
1231 |
|
|
|
1232 |
|
|
//
|
1233 |
|
|
// Array
|
1234 |
|
|
// =====
|
1235 |
|
|
//
|
1236 |
|
|
|
1237 |
|
|
// ES5 15.4.3.2
|
1238 |
|
|
// http://es5.github.com/#x15.4.3.2
|
1239 |
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/isArray
|
1240 |
|
|
defineProperties(Array, { isArray: isArray });
|
1241 |
|
|
|
1242 |
|
|
|
1243 |
|
|
var boxedString = Object('a');
|
1244 |
|
|
var splitString = boxedString[0] !== 'a' || !(0 in boxedString);
|
1245 |
|
|
|
1246 |
|
|
var properlyBoxesContext = function properlyBoxed(method) {
|
1247 |
|
|
// Check node 0.6.21 bug where third parameter is not boxed
|
1248 |
|
|
var properlyBoxesNonStrict = true;
|
1249 |
|
|
var properlyBoxesStrict = true;
|
1250 |
|
|
if (method) {
|
1251 |
|
|
method.call('foo', function (_, __, context) {
|
1252 |
|
|
if (typeof context !== 'object') { properlyBoxesNonStrict = false; }
|
1253 |
|
|
});
|
1254 |
|
|
|
1255 |
|
|
method.call([1], function () {
|
1256 |
|
|
'use strict';
|
1257 |
|
|
properlyBoxesStrict = typeof this === 'string';
|
1258 |
|
|
}, 'x');
|
1259 |
|
|
}
|
1260 |
|
|
return !!method && properlyBoxesNonStrict && properlyBoxesStrict;
|
1261 |
|
|
};
|
1262 |
|
|
|
1263 |
|
|
defineProperties(ArrayPrototype, {
|
1264 |
|
|
forEach: function forEach(fun /*, thisp*/) {
|
1265 |
|
|
var object = toObject(this),
|
1266 |
|
|
self = splitString && isString(this) ? this.split('') : object,
|
1267 |
|
|
thisp = arguments[1],
|
1268 |
|
|
i = -1,
|
1269 |
|
|
length = self.length >>> 0;
|
1270 |
|
|
|
1271 |
|
|
// If no callback function or if callback is not a callable function
|
1272 |
|
|
if (!isFunction(fun)) {
|
1273 |
|
|
throw new TypeError(); // TODO message
|
1274 |
|
|
}
|
1275 |
|
|
|
1276 |
|
|
while (++i < length) {
|
1277 |
|
|
if (i in self) {
|
1278 |
|
|
// Invoke the callback function with call, passing arguments:
|
1279 |
|
|
// context, property value, property key, thisArg object
|
1280 |
|
|
// context
|
1281 |
|
|
fun.call(thisp, self[i], i, object);
|
1282 |
|
|
}
|
1283 |
|
|
}
|
1284 |
|
|
}
|
1285 |
|
|
}, !properlyBoxesContext(ArrayPrototype.forEach));
|
1286 |
|
|
|
1287 |
|
|
// ES5 15.4.4.14
|
1288 |
|
|
// http://es5.github.com/#x15.4.4.14
|
1289 |
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
|
1290 |
|
|
var hasFirefox2IndexOfBug = Array.prototype.indexOf && [0, 1].indexOf(1, 2) !== -1;
|
1291 |
|
|
defineProperties(ArrayPrototype, {
|
1292 |
|
|
indexOf: function indexOf(sought /*, fromIndex */ ) {
|
1293 |
|
|
var self = splitString && isString(this) ? this.split('') : toObject(this),
|
1294 |
|
|
length = self.length >>> 0;
|
1295 |
|
|
|
1296 |
|
|
if (!length) {
|
1297 |
|
|
return -1;
|
1298 |
|
|
}
|
1299 |
|
|
|
1300 |
|
|
var i = 0;
|
1301 |
|
|
if (arguments.length > 1) {
|
1302 |
|
|
i = toInteger(arguments[1]);
|
1303 |
|
|
}
|
1304 |
|
|
|
1305 |
|
|
// handle negative indices
|
1306 |
|
|
i = i >= 0 ? i : Math.max(0, length + i);
|
1307 |
|
|
for (; i < length; i++) {
|
1308 |
|
|
if (i in self && self[i] === sought) {
|
1309 |
|
|
return i;
|
1310 |
|
|
}
|
1311 |
|
|
}
|
1312 |
|
|
return -1;
|
1313 |
|
|
}
|
1314 |
|
|
}, hasFirefox2IndexOfBug);
|
1315 |
|
|
|
1316 |
|
|
//
|
1317 |
|
|
// String
|
1318 |
|
|
// ======
|
1319 |
|
|
//
|
1320 |
|
|
|
1321 |
|
|
// ES5 15.5.4.14
|
1322 |
|
|
// http://es5.github.com/#x15.5.4.14
|
1323 |
|
|
|
1324 |
|
|
// [bugfix, IE lt 9, firefox 4, Konqueror, Opera, obscure browsers]
|
1325 |
|
|
// Many browsers do not split properly with regular expressions or they
|
1326 |
|
|
// do not perform the split correctly under obscure conditions.
|
1327 |
|
|
// See http://blog.stevenlevithan.com/archives/cross-browser-split
|
1328 |
|
|
// I've tested in many browsers and this seems to cover the deviant ones:
|
1329 |
|
|
// 'ab'.split(/(?:ab)*/) should be ["", ""], not [""]
|
1330 |
|
|
// '.'.split(/(.?)(.?)/) should be ["", ".", "", ""], not ["", ""]
|
1331 |
|
|
// 'tesst'.split(/(s)*/) should be ["t", undefined, "e", "s", "t"], not
|
1332 |
|
|
// [undefined, "t", undefined, "e", ...]
|
1333 |
|
|
// ''.split(/.?/) should be [], not [""]
|
1334 |
|
|
// '.'.split(/()()/) should be ["."], not ["", "", "."]
|
1335 |
|
|
|
1336 |
|
|
var string_split = StringPrototype.split;
|
1337 |
|
|
if (
|
1338 |
|
|
'ab'.split(/(?:ab)*/).length !== 2 ||
|
1339 |
|
|
'.'.split(/(.?)(.?)/).length !== 4 ||
|
1340 |
|
|
'tesst'.split(/(s)*/)[1] === 't' ||
|
1341 |
|
|
'test'.split(/(?:)/, -1).length !== 4 ||
|
1342 |
|
|
''.split(/.?/).length ||
|
1343 |
|
|
'.'.split(/()()/).length > 1
|
1344 |
|
|
) {
|
1345 |
|
|
(function () {
|
1346 |
|
|
var compliantExecNpcg = /()??/.exec('')[1] === void 0; // NPCG: nonparticipating capturing group
|
1347 |
|
|
|
1348 |
|
|
StringPrototype.split = function (separator, limit) {
|
1349 |
|
|
var string = this;
|
1350 |
|
|
if (separator === void 0 && limit === 0) {
|
1351 |
|
|
return [];
|
1352 |
|
|
}
|
1353 |
|
|
|
1354 |
|
|
// If `separator` is not a regex, use native split
|
1355 |
|
|
if (_toString.call(separator) !== '[object RegExp]') {
|
1356 |
|
|
return string_split.call(this, separator, limit);
|
1357 |
|
|
}
|
1358 |
|
|
|
1359 |
|
|
var output = [],
|
1360 |
|
|
flags = (separator.ignoreCase ? 'i' : '') +
|
1361 |
|
|
(separator.multiline ? 'm' : '') +
|
1362 |
|
|
(separator.extended ? 'x' : '') + // Proposed for ES6
|
1363 |
|
|
(separator.sticky ? 'y' : ''), // Firefox 3+
|
1364 |
|
|
lastLastIndex = 0,
|
1365 |
|
|
// Make `global` and avoid `lastIndex` issues by working with a copy
|
1366 |
|
|
separator2, match, lastIndex, lastLength;
|
1367 |
|
|
separator = new RegExp(separator.source, flags + 'g');
|
1368 |
|
|
string += ''; // Type-convert
|
1369 |
|
|
if (!compliantExecNpcg) {
|
1370 |
|
|
// Doesn't need flags gy, but they don't hurt
|
1371 |
|
|
separator2 = new RegExp('^' + separator.source + '$(?!\\s)', flags);
|
1372 |
|
|
}
|
1373 |
|
|
/* Values for `limit`, per the spec:
|
1374 |
|
|
* If undefined: 4294967295 // Math.pow(2, 32) - 1
|
1375 |
|
|
* If 0, Infinity, or NaN: 0
|
1376 |
|
|
* If positive number: limit = Math.floor(limit); if (limit > 4294967295) limit -= 4294967296;
|
1377 |
|
|
* If negative number: 4294967296 - Math.floor(Math.abs(limit))
|
1378 |
|
|
* If other: Type-convert, then use the above rules
|
1379 |
|
|
*/
|
1380 |
|
|
limit = limit === void 0 ?
|
1381 |
|
|
-1 >>> 0 : // Math.pow(2, 32) - 1
|
1382 |
|
|
ToUint32(limit);
|
1383 |
|
|
while (match = separator.exec(string)) {
|
1384 |
|
|
// `separator.lastIndex` is not reliable cross-browser
|
1385 |
|
|
lastIndex = match.index + match[0].length;
|
1386 |
|
|
if (lastIndex > lastLastIndex) {
|
1387 |
|
|
output.push(string.slice(lastLastIndex, match.index));
|
1388 |
|
|
// Fix browsers whose `exec` methods don't consistently return `undefined` for
|
1389 |
|
|
// nonparticipating capturing groups
|
1390 |
|
|
if (!compliantExecNpcg && match.length > 1) {
|
1391 |
|
|
match[0].replace(separator2, function () {
|
1392 |
|
|
for (var i = 1; i < arguments.length - 2; i++) {
|
1393 |
|
|
if (arguments[i] === void 0) {
|
1394 |
|
|
match[i] = void 0;
|
1395 |
|
|
}
|
1396 |
|
|
}
|
1397 |
|
|
});
|
1398 |
|
|
}
|
1399 |
|
|
if (match.length > 1 && match.index < string.length) {
|
1400 |
|
|
ArrayPrototype.push.apply(output, match.slice(1));
|
1401 |
|
|
}
|
1402 |
|
|
lastLength = match[0].length;
|
1403 |
|
|
lastLastIndex = lastIndex;
|
1404 |
|
|
if (output.length >= limit) {
|
1405 |
|
|
break;
|
1406 |
|
|
}
|
1407 |
|
|
}
|
1408 |
|
|
if (separator.lastIndex === match.index) {
|
1409 |
|
|
separator.lastIndex++; // Avoid an infinite loop
|
1410 |
|
|
}
|
1411 |
|
|
}
|
1412 |
|
|
if (lastLastIndex === string.length) {
|
1413 |
|
|
if (lastLength || !separator.test('')) {
|
1414 |
|
|
output.push('');
|
1415 |
|
|
}
|
1416 |
|
|
} else {
|
1417 |
|
|
output.push(string.slice(lastLastIndex));
|
1418 |
|
|
}
|
1419 |
|
|
return output.length > limit ? output.slice(0, limit) : output;
|
1420 |
|
|
};
|
1421 |
|
|
}());
|
1422 |
|
|
|
1423 |
|
|
// [bugfix, chrome]
|
1424 |
|
|
// If separator is undefined, then the result array contains just one String,
|
1425 |
|
|
// which is the this value (converted to a String). If limit is not undefined,
|
1426 |
|
|
// then the output array is truncated so that it contains no more than limit
|
1427 |
|
|
// elements.
|
1428 |
|
|
// "0".split(undefined, 0) -> []
|
1429 |
|
|
} else if ('0'.split(void 0, 0).length) {
|
1430 |
|
|
StringPrototype.split = function split(separator, limit) {
|
1431 |
|
|
if (separator === void 0 && limit === 0) { return []; }
|
1432 |
|
|
return string_split.call(this, separator, limit);
|
1433 |
|
|
};
|
1434 |
|
|
}
|
1435 |
|
|
|
1436 |
|
|
// ECMA-262, 3rd B.2.3
|
1437 |
|
|
// Not an ECMAScript standard, although ECMAScript 3rd Edition has a
|
1438 |
|
|
// non-normative section suggesting uniform semantics and it should be
|
1439 |
|
|
// normalized across all browsers
|
1440 |
|
|
// [bugfix, IE lt 9] IE < 9 substr() with negative value not working in IE
|
1441 |
|
|
var string_substr = StringPrototype.substr;
|
1442 |
|
|
var hasNegativeSubstrBug = ''.substr && '0b'.substr(-1) !== 'b';
|
1443 |
|
|
defineProperties(StringPrototype, {
|
1444 |
|
|
substr: function substr(start, length) {
|
1445 |
|
|
return string_substr.call(
|
1446 |
|
|
this,
|
1447 |
|
|
start < 0 ? ((start = this.length + start) < 0 ? 0 : start) : start,
|
1448 |
|
|
length
|
1449 |
|
|
);
|
1450 |
|
|
}
|
1451 |
|
|
}, hasNegativeSubstrBug);
|
1452 |
|
|
|
1453 |
|
|
},{}],16:[function(require,module,exports){
|
1454 |
|
|
'use strict';
|
1455 |
|
|
|
1456 |
|
|
module.exports = [
|
1457 |
|
|
// streaming transports
|
1458 |
|
|
require('./transport/websocket')
|
1459 |
|
|
, require('./transport/xhr-streaming')
|
1460 |
|
|
, require('./transport/xdr-streaming')
|
1461 |
|
|
, require('./transport/eventsource')
|
1462 |
|
|
, require('./transport/lib/iframe-wrap')(require('./transport/eventsource'))
|
1463 |
|
|
|
1464 |
|
|
// polling transports
|
1465 |
|
|
, require('./transport/htmlfile')
|
1466 |
|
|
, require('./transport/lib/iframe-wrap')(require('./transport/htmlfile'))
|
1467 |
|
|
, require('./transport/xhr-polling')
|
1468 |
|
|
, require('./transport/xdr-polling')
|
1469 |
|
|
, require('./transport/lib/iframe-wrap')(require('./transport/xhr-polling'))
|
1470 |
|
|
, require('./transport/jsonp-polling')
|
1471 |
|
|
];
|
1472 |
|
|
|
1473 |
|
|
},{"./transport/eventsource":20,"./transport/htmlfile":21,"./transport/jsonp-polling":23,"./transport/lib/iframe-wrap":26,"./transport/websocket":38,"./transport/xdr-polling":39,"./transport/xdr-streaming":40,"./transport/xhr-polling":41,"./transport/xhr-streaming":42}],17:[function(require,module,exports){
|
1474 |
|
|
(function (process,global){
|
1475 |
|
|
'use strict';
|
1476 |
|
|
|
1477 |
|
|
var EventEmitter = require('events').EventEmitter
|
1478 |
|
|
, inherits = require('inherits')
|
1479 |
|
|
, utils = require('../../utils/event')
|
1480 |
|
|
, urlUtils = require('../../utils/url')
|
1481 |
|
|
, XHR = global.XMLHttpRequest
|
1482 |
|
|
;
|
1483 |
|
|
|
1484 |
|
|
var debug = function() {};
|
1485 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
1486 |
|
|
debug = require('debug')('sockjs-client:browser:xhr');
|
1487 |
|
|
}
|
1488 |
|
|
|
1489 |
|
|
function AbstractXHRObject(method, url, payload, opts) {
|
1490 |
|
|
debug(method, url);
|
1491 |
|
|
var self = this;
|
1492 |
|
|
EventEmitter.call(this);
|
1493 |
|
|
|
1494 |
|
|
setTimeout(function () {
|
1495 |
|
|
self._start(method, url, payload, opts);
|
1496 |
|
|
}, 0);
|
1497 |
|
|
}
|
1498 |
|
|
|
1499 |
|
|
inherits(AbstractXHRObject, EventEmitter);
|
1500 |
|
|
|
1501 |
|
|
AbstractXHRObject.prototype._start = function(method, url, payload, opts) {
|
1502 |
|
|
var self = this;
|
1503 |
|
|
|
1504 |
|
|
try {
|
1505 |
|
|
this.xhr = new XHR();
|
1506 |
|
|
} catch (x) {
|
1507 |
|
|
// intentionally empty
|
1508 |
|
|
}
|
1509 |
|
|
|
1510 |
|
|
if (!this.xhr) {
|
1511 |
|
|
debug('no xhr');
|
1512 |
|
|
this.emit('finish', 0, 'no xhr support');
|
1513 |
|
|
this._cleanup();
|
1514 |
|
|
return;
|
1515 |
|
|
}
|
1516 |
|
|
|
1517 |
|
|
// several browsers cache POSTs
|
1518 |
|
|
url = urlUtils.addQuery(url, 't=' + (+new Date()));
|
1519 |
|
|
|
1520 |
|
|
// Explorer tends to keep connection open, even after the
|
1521 |
|
|
// tab gets closed: http://bugs.jquery.com/ticket/5280
|
1522 |
|
|
this.unloadRef = utils.unloadAdd(function() {
|
1523 |
|
|
debug('unload cleanup');
|
1524 |
|
|
self._cleanup(true);
|
1525 |
|
|
});
|
1526 |
|
|
try {
|
1527 |
|
|
this.xhr.open(method, url, true);
|
1528 |
|
|
if (this.timeout && 'timeout' in this.xhr) {
|
1529 |
|
|
this.xhr.timeout = this.timeout;
|
1530 |
|
|
this.xhr.ontimeout = function() {
|
1531 |
|
|
debug('xhr timeout');
|
1532 |
|
|
self.emit('finish', 0, '');
|
1533 |
|
|
self._cleanup(false);
|
1534 |
|
|
};
|
1535 |
|
|
}
|
1536 |
|
|
} catch (e) {
|
1537 |
|
|
debug('exception', e);
|
1538 |
|
|
// IE raises an exception on wrong port.
|
1539 |
|
|
this.emit('finish', 0, '');
|
1540 |
|
|
this._cleanup(false);
|
1541 |
|
|
return;
|
1542 |
|
|
}
|
1543 |
|
|
|
1544 |
|
|
if ((!opts || !opts.noCredentials) && AbstractXHRObject.supportsCORS) {
|
1545 |
|
|
debug('withCredentials');
|
1546 |
|
|
// Mozilla docs says https://developer.mozilla.org/en/XMLHttpRequest :
|
1547 |
|
|
// "This never affects same-site requests."
|
1548 |
|
|
|
1549 |
|
|
this.xhr.withCredentials = true;
|
1550 |
|
|
}
|
1551 |
|
|
if (opts && opts.headers) {
|
1552 |
|
|
for (var key in opts.headers) {
|
1553 |
|
|
this.xhr.setRequestHeader(key, opts.headers[key]);
|
1554 |
|
|
}
|
1555 |
|
|
}
|
1556 |
|
|
|
1557 |
|
|
this.xhr.onreadystatechange = function() {
|
1558 |
|
|
if (self.xhr) {
|
1559 |
|
|
var x = self.xhr;
|
1560 |
|
|
var text, status;
|
1561 |
|
|
debug('readyState', x.readyState);
|
1562 |
|
|
switch (x.readyState) {
|
1563 |
|
|
case 3:
|
1564 |
|
|
// IE doesn't like peeking into responseText or status
|
1565 |
|
|
// on Microsoft.XMLHTTP and readystate=3
|
1566 |
|
|
try {
|
1567 |
|
|
status = x.status;
|
1568 |
|
|
text = x.responseText;
|
1569 |
|
|
} catch (e) {
|
1570 |
|
|
// intentionally empty
|
1571 |
|
|
}
|
1572 |
|
|
debug('status', status);
|
1573 |
|
|
// IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
|
1574 |
|
|
if (status === 1223) {
|
1575 |
|
|
status = 204;
|
1576 |
|
|
}
|
1577 |
|
|
|
1578 |
|
|
// IE does return readystate == 3 for 404 answers.
|
1579 |
|
|
if (status === 200 && text && text.length > 0) {
|
1580 |
|
|
debug('chunk');
|
1581 |
|
|
self.emit('chunk', status, text);
|
1582 |
|
|
}
|
1583 |
|
|
break;
|
1584 |
|
|
case 4:
|
1585 |
|
|
status = x.status;
|
1586 |
|
|
debug('status', status);
|
1587 |
|
|
// IE returns 1223 for 204: http://bugs.jquery.com/ticket/1450
|
1588 |
|
|
if (status === 1223) {
|
1589 |
|
|
status = 204;
|
1590 |
|
|
}
|
1591 |
|
|
// IE returns this for a bad port
|
1592 |
|
|
// http://msdn.microsoft.com/en-us/library/windows/desktop/aa383770(v=vs.85).aspx
|
1593 |
|
|
if (status === 12005 || status === 12029) {
|
1594 |
|
|
status = 0;
|
1595 |
|
|
}
|
1596 |
|
|
|
1597 |
|
|
debug('finish', status, x.responseText);
|
1598 |
|
|
self.emit('finish', status, x.responseText);
|
1599 |
|
|
self._cleanup(false);
|
1600 |
|
|
break;
|
1601 |
|
|
}
|
1602 |
|
|
}
|
1603 |
|
|
};
|
1604 |
|
|
|
1605 |
|
|
try {
|
1606 |
|
|
self.xhr.send(payload);
|
1607 |
|
|
} catch (e) {
|
1608 |
|
|
self.emit('finish', 0, '');
|
1609 |
|
|
self._cleanup(false);
|
1610 |
|
|
}
|
1611 |
|
|
};
|
1612 |
|
|
|
1613 |
|
|
AbstractXHRObject.prototype._cleanup = function(abort) {
|
1614 |
|
|
debug('cleanup');
|
1615 |
|
|
if (!this.xhr) {
|
1616 |
|
|
return;
|
1617 |
|
|
}
|
1618 |
|
|
this.removeAllListeners();
|
1619 |
|
|
utils.unloadDel(this.unloadRef);
|
1620 |
|
|
|
1621 |
|
|
// IE needs this field to be a function
|
1622 |
|
|
this.xhr.onreadystatechange = function() {};
|
1623 |
|
|
if (this.xhr.ontimeout) {
|
1624 |
|
|
this.xhr.ontimeout = null;
|
1625 |
|
|
}
|
1626 |
|
|
|
1627 |
|
|
if (abort) {
|
1628 |
|
|
try {
|
1629 |
|
|
this.xhr.abort();
|
1630 |
|
|
} catch (x) {
|
1631 |
|
|
// intentionally empty
|
1632 |
|
|
}
|
1633 |
|
|
}
|
1634 |
|
|
this.unloadRef = this.xhr = null;
|
1635 |
|
|
};
|
1636 |
|
|
|
1637 |
|
|
AbstractXHRObject.prototype.close = function() {
|
1638 |
|
|
debug('close');
|
1639 |
|
|
this._cleanup(true);
|
1640 |
|
|
};
|
1641 |
|
|
|
1642 |
|
|
AbstractXHRObject.enabled = !!XHR;
|
1643 |
|
|
// override XMLHttpRequest for IE6/7
|
1644 |
|
|
// obfuscate to avoid firewalls
|
1645 |
|
|
var axo = ['Active'].concat('Object').join('X');
|
1646 |
|
|
if (!AbstractXHRObject.enabled && (axo in global)) {
|
1647 |
|
|
debug('overriding xmlhttprequest');
|
1648 |
|
|
XHR = function() {
|
1649 |
|
|
try {
|
1650 |
|
|
return new global[axo]('Microsoft.XMLHTTP');
|
1651 |
|
|
} catch (e) {
|
1652 |
|
|
return null;
|
1653 |
|
|
}
|
1654 |
|
|
};
|
1655 |
|
|
AbstractXHRObject.enabled = !!new XHR();
|
1656 |
|
|
}
|
1657 |
|
|
|
1658 |
|
|
var cors = false;
|
1659 |
|
|
try {
|
1660 |
|
|
cors = 'withCredentials' in new XHR();
|
1661 |
|
|
} catch (ignored) {
|
1662 |
|
|
// intentionally empty
|
1663 |
|
|
}
|
1664 |
|
|
|
1665 |
|
|
AbstractXHRObject.supportsCORS = cors;
|
1666 |
|
|
|
1667 |
|
|
module.exports = AbstractXHRObject;
|
1668 |
|
|
|
1669 |
|
|
}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1670 |
|
|
|
1671 |
|
|
},{"../../utils/event":46,"../../utils/url":52,"debug":55,"events":3,"inherits":57}],18:[function(require,module,exports){
|
1672 |
|
|
(function (global){
|
1673 |
|
|
module.exports = global.EventSource;
|
1674 |
|
|
|
1675 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1676 |
|
|
|
1677 |
|
|
},{}],19:[function(require,module,exports){
|
1678 |
|
|
(function (global){
|
1679 |
|
|
'use strict';
|
1680 |
|
|
|
1681 |
|
|
var Driver = global.WebSocket || global.MozWebSocket;
|
1682 |
|
|
if (Driver) {
|
1683 |
|
|
module.exports = function WebSocketBrowserDriver(url) {
|
1684 |
|
|
return new Driver(url);
|
1685 |
|
|
};
|
1686 |
|
|
} else {
|
1687 |
|
|
module.exports = undefined;
|
1688 |
|
|
}
|
1689 |
|
|
|
1690 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1691 |
|
|
|
1692 |
|
|
},{}],20:[function(require,module,exports){
|
1693 |
|
|
'use strict';
|
1694 |
|
|
|
1695 |
|
|
var inherits = require('inherits')
|
1696 |
|
|
, AjaxBasedTransport = require('./lib/ajax-based')
|
1697 |
|
|
, EventSourceReceiver = require('./receiver/eventsource')
|
1698 |
|
|
, XHRCorsObject = require('./sender/xhr-cors')
|
1699 |
|
|
, EventSourceDriver = require('eventsource')
|
1700 |
|
|
;
|
1701 |
|
|
|
1702 |
|
|
function EventSourceTransport(transUrl) {
|
1703 |
|
|
if (!EventSourceTransport.enabled()) {
|
1704 |
|
|
throw new Error('Transport created when disabled');
|
1705 |
|
|
}
|
1706 |
|
|
|
1707 |
|
|
AjaxBasedTransport.call(this, transUrl, '/eventsource', EventSourceReceiver, XHRCorsObject);
|
1708 |
|
|
}
|
1709 |
|
|
|
1710 |
|
|
inherits(EventSourceTransport, AjaxBasedTransport);
|
1711 |
|
|
|
1712 |
|
|
EventSourceTransport.enabled = function() {
|
1713 |
|
|
return !!EventSourceDriver;
|
1714 |
|
|
};
|
1715 |
|
|
|
1716 |
|
|
EventSourceTransport.transportName = 'eventsource';
|
1717 |
|
|
EventSourceTransport.roundTrips = 2;
|
1718 |
|
|
|
1719 |
|
|
module.exports = EventSourceTransport;
|
1720 |
|
|
|
1721 |
|
|
},{"./lib/ajax-based":24,"./receiver/eventsource":29,"./sender/xhr-cors":35,"eventsource":18,"inherits":57}],21:[function(require,module,exports){
|
1722 |
|
|
'use strict';
|
1723 |
|
|
|
1724 |
|
|
var inherits = require('inherits')
|
1725 |
|
|
, HtmlfileReceiver = require('./receiver/htmlfile')
|
1726 |
|
|
, XHRLocalObject = require('./sender/xhr-local')
|
1727 |
|
|
, AjaxBasedTransport = require('./lib/ajax-based')
|
1728 |
|
|
;
|
1729 |
|
|
|
1730 |
|
|
function HtmlFileTransport(transUrl) {
|
1731 |
|
|
if (!HtmlfileReceiver.enabled) {
|
1732 |
|
|
throw new Error('Transport created when disabled');
|
1733 |
|
|
}
|
1734 |
|
|
AjaxBasedTransport.call(this, transUrl, '/htmlfile', HtmlfileReceiver, XHRLocalObject);
|
1735 |
|
|
}
|
1736 |
|
|
|
1737 |
|
|
inherits(HtmlFileTransport, AjaxBasedTransport);
|
1738 |
|
|
|
1739 |
|
|
HtmlFileTransport.enabled = function(info) {
|
1740 |
|
|
return HtmlfileReceiver.enabled && info.sameOrigin;
|
1741 |
|
|
};
|
1742 |
|
|
|
1743 |
|
|
HtmlFileTransport.transportName = 'htmlfile';
|
1744 |
|
|
HtmlFileTransport.roundTrips = 2;
|
1745 |
|
|
|
1746 |
|
|
module.exports = HtmlFileTransport;
|
1747 |
|
|
|
1748 |
|
|
},{"./lib/ajax-based":24,"./receiver/htmlfile":30,"./sender/xhr-local":37,"inherits":57}],22:[function(require,module,exports){
|
1749 |
|
|
(function (process){
|
1750 |
|
|
'use strict';
|
1751 |
|
|
|
1752 |
|
|
// Few cool transports do work only for same-origin. In order to make
|
1753 |
|
|
// them work cross-domain we shall use iframe, served from the
|
1754 |
|
|
// remote domain. New browsers have capabilities to communicate with
|
1755 |
|
|
// cross domain iframe using postMessage(). In IE it was implemented
|
1756 |
|
|
// from IE 8+, but of course, IE got some details wrong:
|
1757 |
|
|
// http://msdn.microsoft.com/en-us/library/cc197015(v=VS.85).aspx
|
1758 |
|
|
// http://stevesouders.com/misc/test-postmessage.php
|
1759 |
|
|
|
1760 |
|
|
var inherits = require('inherits')
|
1761 |
|
|
, JSON3 = require('json3')
|
1762 |
|
|
, EventEmitter = require('events').EventEmitter
|
1763 |
|
|
, version = require('../version')
|
1764 |
|
|
, urlUtils = require('../utils/url')
|
1765 |
|
|
, iframeUtils = require('../utils/iframe')
|
1766 |
|
|
, eventUtils = require('../utils/event')
|
1767 |
|
|
, random = require('../utils/random')
|
1768 |
|
|
;
|
1769 |
|
|
|
1770 |
|
|
var debug = function() {};
|
1771 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
1772 |
|
|
debug = require('debug')('sockjs-client:transport:iframe');
|
1773 |
|
|
}
|
1774 |
|
|
|
1775 |
|
|
function IframeTransport(transport, transUrl, baseUrl) {
|
1776 |
|
|
if (!IframeTransport.enabled()) {
|
1777 |
|
|
throw new Error('Transport created when disabled');
|
1778 |
|
|
}
|
1779 |
|
|
EventEmitter.call(this);
|
1780 |
|
|
|
1781 |
|
|
var self = this;
|
1782 |
|
|
this.origin = urlUtils.getOrigin(baseUrl);
|
1783 |
|
|
this.baseUrl = baseUrl;
|
1784 |
|
|
this.transUrl = transUrl;
|
1785 |
|
|
this.transport = transport;
|
1786 |
|
|
this.windowId = random.string(8);
|
1787 |
|
|
|
1788 |
|
|
var iframeUrl = urlUtils.addPath(baseUrl, '/iframe.html') + '#' + this.windowId;
|
1789 |
|
|
debug(transport, transUrl, iframeUrl);
|
1790 |
|
|
|
1791 |
|
|
this.iframeObj = iframeUtils.createIframe(iframeUrl, function(r) {
|
1792 |
|
|
debug('err callback');
|
1793 |
|
|
self.emit('close', 1006, 'Unable to load an iframe (' + r + ')');
|
1794 |
|
|
self.close();
|
1795 |
|
|
});
|
1796 |
|
|
|
1797 |
|
|
this.onmessageCallback = this._message.bind(this);
|
1798 |
|
|
eventUtils.attachEvent('message', this.onmessageCallback);
|
1799 |
|
|
}
|
1800 |
|
|
|
1801 |
|
|
inherits(IframeTransport, EventEmitter);
|
1802 |
|
|
|
1803 |
|
|
IframeTransport.prototype.close = function() {
|
1804 |
|
|
debug('close');
|
1805 |
|
|
this.removeAllListeners();
|
1806 |
|
|
if (this.iframeObj) {
|
1807 |
|
|
eventUtils.detachEvent('message', this.onmessageCallback);
|
1808 |
|
|
try {
|
1809 |
|
|
// When the iframe is not loaded, IE raises an exception
|
1810 |
|
|
// on 'contentWindow'.
|
1811 |
|
|
this.postMessage('c');
|
1812 |
|
|
} catch (x) {
|
1813 |
|
|
// intentionally empty
|
1814 |
|
|
}
|
1815 |
|
|
this.iframeObj.cleanup();
|
1816 |
|
|
this.iframeObj = null;
|
1817 |
|
|
this.onmessageCallback = this.iframeObj = null;
|
1818 |
|
|
}
|
1819 |
|
|
};
|
1820 |
|
|
|
1821 |
|
|
IframeTransport.prototype._message = function(e) {
|
1822 |
|
|
debug('message', e.data);
|
1823 |
|
|
if (!urlUtils.isOriginEqual(e.origin, this.origin)) {
|
1824 |
|
|
debug('not same origin', e.origin, this.origin);
|
1825 |
|
|
return;
|
1826 |
|
|
}
|
1827 |
|
|
|
1828 |
|
|
var iframeMessage;
|
1829 |
|
|
try {
|
1830 |
|
|
iframeMessage = JSON3.parse(e.data);
|
1831 |
|
|
} catch (ignored) {
|
1832 |
|
|
debug('bad json', e.data);
|
1833 |
|
|
return;
|
1834 |
|
|
}
|
1835 |
|
|
|
1836 |
|
|
if (iframeMessage.windowId !== this.windowId) {
|
1837 |
|
|
debug('mismatched window id', iframeMessage.windowId, this.windowId);
|
1838 |
|
|
return;
|
1839 |
|
|
}
|
1840 |
|
|
|
1841 |
|
|
switch (iframeMessage.type) {
|
1842 |
|
|
case 's':
|
1843 |
|
|
this.iframeObj.loaded();
|
1844 |
|
|
// window global dependency
|
1845 |
|
|
this.postMessage('s', JSON3.stringify([
|
1846 |
|
|
version
|
1847 |
|
|
, this.transport
|
1848 |
|
|
, this.transUrl
|
1849 |
|
|
, this.baseUrl
|
1850 |
|
|
]));
|
1851 |
|
|
break;
|
1852 |
|
|
case 't':
|
1853 |
|
|
this.emit('message', iframeMessage.data);
|
1854 |
|
|
break;
|
1855 |
|
|
case 'c':
|
1856 |
|
|
var cdata;
|
1857 |
|
|
try {
|
1858 |
|
|
cdata = JSON3.parse(iframeMessage.data);
|
1859 |
|
|
} catch (ignored) {
|
1860 |
|
|
debug('bad json', iframeMessage.data);
|
1861 |
|
|
return;
|
1862 |
|
|
}
|
1863 |
|
|
this.emit('close', cdata[0], cdata[1]);
|
1864 |
|
|
this.close();
|
1865 |
|
|
break;
|
1866 |
|
|
}
|
1867 |
|
|
};
|
1868 |
|
|
|
1869 |
|
|
IframeTransport.prototype.postMessage = function(type, data) {
|
1870 |
|
|
debug('postMessage', type, data);
|
1871 |
|
|
this.iframeObj.post(JSON3.stringify({
|
1872 |
|
|
windowId: this.windowId
|
1873 |
|
|
, type: type
|
1874 |
|
|
, data: data || ''
|
1875 |
|
|
}), this.origin);
|
1876 |
|
|
};
|
1877 |
|
|
|
1878 |
|
|
IframeTransport.prototype.send = function(message) {
|
1879 |
|
|
debug('send', message);
|
1880 |
|
|
this.postMessage('m', message);
|
1881 |
|
|
};
|
1882 |
|
|
|
1883 |
|
|
IframeTransport.enabled = function() {
|
1884 |
|
|
return iframeUtils.iframeEnabled;
|
1885 |
|
|
};
|
1886 |
|
|
|
1887 |
|
|
IframeTransport.transportName = 'iframe';
|
1888 |
|
|
IframeTransport.roundTrips = 2;
|
1889 |
|
|
|
1890 |
|
|
module.exports = IframeTransport;
|
1891 |
|
|
|
1892 |
|
|
}).call(this,{ env: {} })
|
1893 |
|
|
|
1894 |
|
|
},{"../utils/event":46,"../utils/iframe":47,"../utils/random":50,"../utils/url":52,"../version":53,"debug":55,"events":3,"inherits":57,"json3":58}],23:[function(require,module,exports){
|
1895 |
|
|
(function (global){
|
1896 |
|
|
'use strict';
|
1897 |
|
|
|
1898 |
|
|
// The simplest and most robust transport, using the well-know cross
|
1899 |
|
|
// domain hack - JSONP. This transport is quite inefficient - one
|
1900 |
|
|
// message could use up to one http request. But at least it works almost
|
1901 |
|
|
// everywhere.
|
1902 |
|
|
// Known limitations:
|
1903 |
|
|
// o you will get a spinning cursor
|
1904 |
|
|
// o for Konqueror a dumb timer is needed to detect errors
|
1905 |
|
|
|
1906 |
|
|
var inherits = require('inherits')
|
1907 |
|
|
, SenderReceiver = require('./lib/sender-receiver')
|
1908 |
|
|
, JsonpReceiver = require('./receiver/jsonp')
|
1909 |
|
|
, jsonpSender = require('./sender/jsonp')
|
1910 |
|
|
;
|
1911 |
|
|
|
1912 |
|
|
function JsonPTransport(transUrl) {
|
1913 |
|
|
if (!JsonPTransport.enabled()) {
|
1914 |
|
|
throw new Error('Transport created when disabled');
|
1915 |
|
|
}
|
1916 |
|
|
SenderReceiver.call(this, transUrl, '/jsonp', jsonpSender, JsonpReceiver);
|
1917 |
|
|
}
|
1918 |
|
|
|
1919 |
|
|
inherits(JsonPTransport, SenderReceiver);
|
1920 |
|
|
|
1921 |
|
|
JsonPTransport.enabled = function() {
|
1922 |
|
|
return !!global.document;
|
1923 |
|
|
};
|
1924 |
|
|
|
1925 |
|
|
JsonPTransport.transportName = 'jsonp-polling';
|
1926 |
|
|
JsonPTransport.roundTrips = 1;
|
1927 |
|
|
JsonPTransport.needBody = true;
|
1928 |
|
|
|
1929 |
|
|
module.exports = JsonPTransport;
|
1930 |
|
|
|
1931 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
1932 |
|
|
|
1933 |
|
|
},{"./lib/sender-receiver":28,"./receiver/jsonp":31,"./sender/jsonp":33,"inherits":57}],24:[function(require,module,exports){
|
1934 |
|
|
(function (process){
|
1935 |
|
|
'use strict';
|
1936 |
|
|
|
1937 |
|
|
var inherits = require('inherits')
|
1938 |
|
|
, urlUtils = require('../../utils/url')
|
1939 |
|
|
, SenderReceiver = require('./sender-receiver')
|
1940 |
|
|
;
|
1941 |
|
|
|
1942 |
|
|
var debug = function() {};
|
1943 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
1944 |
|
|
debug = require('debug')('sockjs-client:ajax-based');
|
1945 |
|
|
}
|
1946 |
|
|
|
1947 |
|
|
function createAjaxSender(AjaxObject) {
|
1948 |
|
|
return function(url, payload, callback) {
|
1949 |
|
|
debug('create ajax sender', url, payload);
|
1950 |
|
|
var opt = {};
|
1951 |
|
|
if (typeof payload === 'string') {
|
1952 |
|
|
opt.headers = {'Content-type': 'text/plain'};
|
1953 |
|
|
}
|
1954 |
|
|
var ajaxUrl = urlUtils.addPath(url, '/xhr_send');
|
1955 |
|
|
var xo = new AjaxObject('POST', ajaxUrl, payload, opt);
|
1956 |
|
|
xo.once('finish', function(status) {
|
1957 |
|
|
debug('finish', status);
|
1958 |
|
|
xo = null;
|
1959 |
|
|
|
1960 |
|
|
if (status !== 200 && status !== 204) {
|
1961 |
|
|
return callback(new Error('http status ' + status));
|
1962 |
|
|
}
|
1963 |
|
|
callback();
|
1964 |
|
|
});
|
1965 |
|
|
return function() {
|
1966 |
|
|
debug('abort');
|
1967 |
|
|
xo.close();
|
1968 |
|
|
xo = null;
|
1969 |
|
|
|
1970 |
|
|
var err = new Error('Aborted');
|
1971 |
|
|
err.code = 1000;
|
1972 |
|
|
callback(err);
|
1973 |
|
|
};
|
1974 |
|
|
};
|
1975 |
|
|
}
|
1976 |
|
|
|
1977 |
|
|
function AjaxBasedTransport(transUrl, urlSuffix, Receiver, AjaxObject) {
|
1978 |
|
|
SenderReceiver.call(this, transUrl, urlSuffix, createAjaxSender(AjaxObject), Receiver, AjaxObject);
|
1979 |
|
|
}
|
1980 |
|
|
|
1981 |
|
|
inherits(AjaxBasedTransport, SenderReceiver);
|
1982 |
|
|
|
1983 |
|
|
module.exports = AjaxBasedTransport;
|
1984 |
|
|
|
1985 |
|
|
}).call(this,{ env: {} })
|
1986 |
|
|
|
1987 |
|
|
},{"../../utils/url":52,"./sender-receiver":28,"debug":55,"inherits":57}],25:[function(require,module,exports){
|
1988 |
|
|
(function (process){
|
1989 |
|
|
'use strict';
|
1990 |
|
|
|
1991 |
|
|
var inherits = require('inherits')
|
1992 |
|
|
, EventEmitter = require('events').EventEmitter
|
1993 |
|
|
;
|
1994 |
|
|
|
1995 |
|
|
var debug = function() {};
|
1996 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
1997 |
|
|
debug = require('debug')('sockjs-client:buffered-sender');
|
1998 |
|
|
}
|
1999 |
|
|
|
2000 |
|
|
function BufferedSender(url, sender) {
|
2001 |
|
|
debug(url);
|
2002 |
|
|
EventEmitter.call(this);
|
2003 |
|
|
this.sendBuffer = [];
|
2004 |
|
|
this.sender = sender;
|
2005 |
|
|
this.url = url;
|
2006 |
|
|
}
|
2007 |
|
|
|
2008 |
|
|
inherits(BufferedSender, EventEmitter);
|
2009 |
|
|
|
2010 |
|
|
BufferedSender.prototype.send = function(message) {
|
2011 |
|
|
debug('send', message);
|
2012 |
|
|
this.sendBuffer.push(message);
|
2013 |
|
|
if (!this.sendStop) {
|
2014 |
|
|
this.sendSchedule();
|
2015 |
|
|
}
|
2016 |
|
|
};
|
2017 |
|
|
|
2018 |
|
|
// For polling transports in a situation when in the message callback,
|
2019 |
|
|
// new message is being send. If the sending connection was started
|
2020 |
|
|
// before receiving one, it is possible to saturate the network and
|
2021 |
|
|
// timeout due to the lack of receiving socket. To avoid that we delay
|
2022 |
|
|
// sending messages by some small time, in order to let receiving
|
2023 |
|
|
// connection be started beforehand. This is only a halfmeasure and
|
2024 |
|
|
// does not fix the big problem, but it does make the tests go more
|
2025 |
|
|
// stable on slow networks.
|
2026 |
|
|
BufferedSender.prototype.sendScheduleWait = function() {
|
2027 |
|
|
debug('sendScheduleWait');
|
2028 |
|
|
var self = this;
|
2029 |
|
|
var tref;
|
2030 |
|
|
this.sendStop = function() {
|
2031 |
|
|
debug('sendStop');
|
2032 |
|
|
self.sendStop = null;
|
2033 |
|
|
clearTimeout(tref);
|
2034 |
|
|
};
|
2035 |
|
|
tref = setTimeout(function() {
|
2036 |
|
|
debug('timeout');
|
2037 |
|
|
self.sendStop = null;
|
2038 |
|
|
self.sendSchedule();
|
2039 |
|
|
}, 25);
|
2040 |
|
|
};
|
2041 |
|
|
|
2042 |
|
|
BufferedSender.prototype.sendSchedule = function() {
|
2043 |
|
|
debug('sendSchedule', this.sendBuffer.length);
|
2044 |
|
|
var self = this;
|
2045 |
|
|
if (this.sendBuffer.length > 0) {
|
2046 |
|
|
var payload = '[' + this.sendBuffer.join(',') + ']';
|
2047 |
|
|
this.sendStop = this.sender(this.url, payload, function(err) {
|
2048 |
|
|
self.sendStop = null;
|
2049 |
|
|
if (err) {
|
2050 |
|
|
debug('error', err);
|
2051 |
|
|
self.emit('close', err.code || 1006, 'Sending error: ' + err);
|
2052 |
|
|
self.close();
|
2053 |
|
|
} else {
|
2054 |
|
|
self.sendScheduleWait();
|
2055 |
|
|
}
|
2056 |
|
|
});
|
2057 |
|
|
this.sendBuffer = [];
|
2058 |
|
|
}
|
2059 |
|
|
};
|
2060 |
|
|
|
2061 |
|
|
BufferedSender.prototype._cleanup = function() {
|
2062 |
|
|
debug('_cleanup');
|
2063 |
|
|
this.removeAllListeners();
|
2064 |
|
|
};
|
2065 |
|
|
|
2066 |
|
|
BufferedSender.prototype.close = function() {
|
2067 |
|
|
debug('close');
|
2068 |
|
|
this._cleanup();
|
2069 |
|
|
if (this.sendStop) {
|
2070 |
|
|
this.sendStop();
|
2071 |
|
|
this.sendStop = null;
|
2072 |
|
|
}
|
2073 |
|
|
};
|
2074 |
|
|
|
2075 |
|
|
module.exports = BufferedSender;
|
2076 |
|
|
|
2077 |
|
|
}).call(this,{ env: {} })
|
2078 |
|
|
|
2079 |
|
|
},{"debug":55,"events":3,"inherits":57}],26:[function(require,module,exports){
|
2080 |
|
|
(function (global){
|
2081 |
|
|
'use strict';
|
2082 |
|
|
|
2083 |
|
|
var inherits = require('inherits')
|
2084 |
|
|
, IframeTransport = require('../iframe')
|
2085 |
|
|
, objectUtils = require('../../utils/object')
|
2086 |
|
|
;
|
2087 |
|
|
|
2088 |
|
|
module.exports = function(transport) {
|
2089 |
|
|
|
2090 |
|
|
function IframeWrapTransport(transUrl, baseUrl) {
|
2091 |
|
|
IframeTransport.call(this, transport.transportName, transUrl, baseUrl);
|
2092 |
|
|
}
|
2093 |
|
|
|
2094 |
|
|
inherits(IframeWrapTransport, IframeTransport);
|
2095 |
|
|
|
2096 |
|
|
IframeWrapTransport.enabled = function(url, info) {
|
2097 |
|
|
if (!global.document) {
|
2098 |
|
|
return false;
|
2099 |
|
|
}
|
2100 |
|
|
|
2101 |
|
|
var iframeInfo = objectUtils.extend({}, info);
|
2102 |
|
|
iframeInfo.sameOrigin = true;
|
2103 |
|
|
return transport.enabled(iframeInfo) && IframeTransport.enabled();
|
2104 |
|
|
};
|
2105 |
|
|
|
2106 |
|
|
IframeWrapTransport.transportName = 'iframe-' + transport.transportName;
|
2107 |
|
|
IframeWrapTransport.needBody = true;
|
2108 |
|
|
IframeWrapTransport.roundTrips = IframeTransport.roundTrips + transport.roundTrips - 1; // html, javascript (2) + transport - no CORS (1)
|
2109 |
|
|
|
2110 |
|
|
IframeWrapTransport.facadeTransport = transport;
|
2111 |
|
|
|
2112 |
|
|
return IframeWrapTransport;
|
2113 |
|
|
};
|
2114 |
|
|
|
2115 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
2116 |
|
|
|
2117 |
|
|
},{"../../utils/object":49,"../iframe":22,"inherits":57}],27:[function(require,module,exports){
|
2118 |
|
|
(function (process){
|
2119 |
|
|
'use strict';
|
2120 |
|
|
|
2121 |
|
|
var inherits = require('inherits')
|
2122 |
|
|
, EventEmitter = require('events').EventEmitter
|
2123 |
|
|
;
|
2124 |
|
|
|
2125 |
|
|
var debug = function() {};
|
2126 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
2127 |
|
|
debug = require('debug')('sockjs-client:polling');
|
2128 |
|
|
}
|
2129 |
|
|
|
2130 |
|
|
function Polling(Receiver, receiveUrl, AjaxObject) {
|
2131 |
|
|
debug(receiveUrl);
|
2132 |
|
|
EventEmitter.call(this);
|
2133 |
|
|
this.Receiver = Receiver;
|
2134 |
|
|
this.receiveUrl = receiveUrl;
|
2135 |
|
|
this.AjaxObject = AjaxObject;
|
2136 |
|
|
this._scheduleReceiver();
|
2137 |
|
|
}
|
2138 |
|
|
|
2139 |
|
|
inherits(Polling, EventEmitter);
|
2140 |
|
|
|
2141 |
|
|
Polling.prototype._scheduleReceiver = function() {
|
2142 |
|
|
debug('_scheduleReceiver');
|
2143 |
|
|
var self = this;
|
2144 |
|
|
var poll = this.poll = new this.Receiver(this.receiveUrl, this.AjaxObject);
|
2145 |
|
|
|
2146 |
|
|
poll.on('message', function(msg) {
|
2147 |
|
|
debug('message', msg);
|
2148 |
|
|
self.emit('message', msg);
|
2149 |
|
|
});
|
2150 |
|
|
|
2151 |
|
|
poll.once('close', function(code, reason) {
|
2152 |
|
|
debug('close', code, reason, self.pollIsClosing);
|
2153 |
|
|
self.poll = poll = null;
|
2154 |
|
|
|
2155 |
|
|
if (!self.pollIsClosing) {
|
2156 |
|
|
if (reason === 'network') {
|
2157 |
|
|
self._scheduleReceiver();
|
2158 |
|
|
} else {
|
2159 |
|
|
self.emit('close', code || 1006, reason);
|
2160 |
|
|
self.removeAllListeners();
|
2161 |
|
|
}
|
2162 |
|
|
}
|
2163 |
|
|
});
|
2164 |
|
|
};
|
2165 |
|
|
|
2166 |
|
|
Polling.prototype.abort = function() {
|
2167 |
|
|
debug('abort');
|
2168 |
|
|
this.removeAllListeners();
|
2169 |
|
|
this.pollIsClosing = true;
|
2170 |
|
|
if (this.poll) {
|
2171 |
|
|
this.poll.abort();
|
2172 |
|
|
}
|
2173 |
|
|
};
|
2174 |
|
|
|
2175 |
|
|
module.exports = Polling;
|
2176 |
|
|
|
2177 |
|
|
}).call(this,{ env: {} })
|
2178 |
|
|
|
2179 |
|
|
},{"debug":55,"events":3,"inherits":57}],28:[function(require,module,exports){
|
2180 |
|
|
(function (process){
|
2181 |
|
|
'use strict';
|
2182 |
|
|
|
2183 |
|
|
var inherits = require('inherits')
|
2184 |
|
|
, urlUtils = require('../../utils/url')
|
2185 |
|
|
, BufferedSender = require('./buffered-sender')
|
2186 |
|
|
, Polling = require('./polling')
|
2187 |
|
|
;
|
2188 |
|
|
|
2189 |
|
|
var debug = function() {};
|
2190 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
2191 |
|
|
debug = require('debug')('sockjs-client:sender-receiver');
|
2192 |
|
|
}
|
2193 |
|
|
|
2194 |
|
|
function SenderReceiver(transUrl, urlSuffix, senderFunc, Receiver, AjaxObject) {
|
2195 |
|
|
var pollUrl = urlUtils.addPath(transUrl, urlSuffix);
|
2196 |
|
|
debug(pollUrl);
|
2197 |
|
|
var self = this;
|
2198 |
|
|
BufferedSender.call(this, transUrl, senderFunc);
|
2199 |
|
|
|
2200 |
|
|
this.poll = new Polling(Receiver, pollUrl, AjaxObject);
|
2201 |
|
|
this.poll.on('message', function(msg) {
|
2202 |
|
|
debug('poll message', msg);
|
2203 |
|
|
self.emit('message', msg);
|
2204 |
|
|
});
|
2205 |
|
|
this.poll.once('close', function(code, reason) {
|
2206 |
|
|
debug('poll close', code, reason);
|
2207 |
|
|
self.poll = null;
|
2208 |
|
|
self.emit('close', code, reason);
|
2209 |
|
|
self.close();
|
2210 |
|
|
});
|
2211 |
|
|
}
|
2212 |
|
|
|
2213 |
|
|
inherits(SenderReceiver, BufferedSender);
|
2214 |
|
|
|
2215 |
|
|
SenderReceiver.prototype.close = function() {
|
2216 |
|
|
BufferedSender.prototype.close.call(this);
|
2217 |
|
|
debug('close');
|
2218 |
|
|
this.removeAllListeners();
|
2219 |
|
|
if (this.poll) {
|
2220 |
|
|
this.poll.abort();
|
2221 |
|
|
this.poll = null;
|
2222 |
|
|
}
|
2223 |
|
|
};
|
2224 |
|
|
|
2225 |
|
|
module.exports = SenderReceiver;
|
2226 |
|
|
|
2227 |
|
|
}).call(this,{ env: {} })
|
2228 |
|
|
|
2229 |
|
|
},{"../../utils/url":52,"./buffered-sender":25,"./polling":27,"debug":55,"inherits":57}],29:[function(require,module,exports){
|
2230 |
|
|
(function (process){
|
2231 |
|
|
'use strict';
|
2232 |
|
|
|
2233 |
|
|
var inherits = require('inherits')
|
2234 |
|
|
, EventEmitter = require('events').EventEmitter
|
2235 |
|
|
, EventSourceDriver = require('eventsource')
|
2236 |
|
|
;
|
2237 |
|
|
|
2238 |
|
|
var debug = function() {};
|
2239 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
2240 |
|
|
debug = require('debug')('sockjs-client:receiver:eventsource');
|
2241 |
|
|
}
|
2242 |
|
|
|
2243 |
|
|
function EventSourceReceiver(url) {
|
2244 |
|
|
debug(url);
|
2245 |
|
|
EventEmitter.call(this);
|
2246 |
|
|
|
2247 |
|
|
var self = this;
|
2248 |
|
|
var es = this.es = new EventSourceDriver(url);
|
2249 |
|
|
es.onmessage = function(e) {
|
2250 |
|
|
debug('message', e.data);
|
2251 |
|
|
self.emit('message', decodeURI(e.data));
|
2252 |
|
|
};
|
2253 |
|
|
es.onerror = function(e) {
|
2254 |
|
|
debug('error', es.readyState, e);
|
2255 |
|
|
// ES on reconnection has readyState = 0 or 1.
|
2256 |
|
|
// on network error it's CLOSED = 2
|
2257 |
|
|
var reason = (es.readyState !== 2 ? 'network' : 'permanent');
|
2258 |
|
|
self._cleanup();
|
2259 |
|
|
self._close(reason);
|
2260 |
|
|
};
|
2261 |
|
|
}
|
2262 |
|
|
|
2263 |
|
|
inherits(EventSourceReceiver, EventEmitter);
|
2264 |
|
|
|
2265 |
|
|
EventSourceReceiver.prototype.abort = function() {
|
2266 |
|
|
debug('abort');
|
2267 |
|
|
this._cleanup();
|
2268 |
|
|
this._close('user');
|
2269 |
|
|
};
|
2270 |
|
|
|
2271 |
|
|
EventSourceReceiver.prototype._cleanup = function() {
|
2272 |
|
|
debug('cleanup');
|
2273 |
|
|
var es = this.es;
|
2274 |
|
|
if (es) {
|
2275 |
|
|
es.onmessage = es.onerror = null;
|
2276 |
|
|
es.close();
|
2277 |
|
|
this.es = null;
|
2278 |
|
|
}
|
2279 |
|
|
};
|
2280 |
|
|
|
2281 |
|
|
EventSourceReceiver.prototype._close = function(reason) {
|
2282 |
|
|
debug('close', reason);
|
2283 |
|
|
var self = this;
|
2284 |
|
|
// Safari and chrome < 15 crash if we close window before
|
2285 |
|
|
// waiting for ES cleanup. See:
|
2286 |
|
|
// https://code.google.com/p/chromium/issues/detail?id=89155
|
2287 |
|
|
setTimeout(function() {
|
2288 |
|
|
self.emit('close', null, reason);
|
2289 |
|
|
self.removeAllListeners();
|
2290 |
|
|
}, 200);
|
2291 |
|
|
};
|
2292 |
|
|
|
2293 |
|
|
module.exports = EventSourceReceiver;
|
2294 |
|
|
|
2295 |
|
|
}).call(this,{ env: {} })
|
2296 |
|
|
|
2297 |
|
|
},{"debug":55,"events":3,"eventsource":18,"inherits":57}],30:[function(require,module,exports){
|
2298 |
|
|
(function (process,global){
|
2299 |
|
|
'use strict';
|
2300 |
|
|
|
2301 |
|
|
var inherits = require('inherits')
|
2302 |
|
|
, iframeUtils = require('../../utils/iframe')
|
2303 |
|
|
, urlUtils = require('../../utils/url')
|
2304 |
|
|
, EventEmitter = require('events').EventEmitter
|
2305 |
|
|
, random = require('../../utils/random')
|
2306 |
|
|
;
|
2307 |
|
|
|
2308 |
|
|
var debug = function() {};
|
2309 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
2310 |
|
|
debug = require('debug')('sockjs-client:receiver:htmlfile');
|
2311 |
|
|
}
|
2312 |
|
|
|
2313 |
|
|
function HtmlfileReceiver(url) {
|
2314 |
|
|
debug(url);
|
2315 |
|
|
EventEmitter.call(this);
|
2316 |
|
|
var self = this;
|
2317 |
|
|
iframeUtils.polluteGlobalNamespace();
|
2318 |
|
|
|
2319 |
|
|
this.id = 'a' + random.string(6);
|
2320 |
|
|
url = urlUtils.addQuery(url, 'c=' + decodeURIComponent(iframeUtils.WPrefix + '.' + this.id));
|
2321 |
|
|
|
2322 |
|
|
debug('using htmlfile', HtmlfileReceiver.htmlfileEnabled);
|
2323 |
|
|
var constructFunc = HtmlfileReceiver.htmlfileEnabled ?
|
2324 |
|
|
iframeUtils.createHtmlfile : iframeUtils.createIframe;
|
2325 |
|
|
|
2326 |
|
|
global[iframeUtils.WPrefix][this.id] = {
|
2327 |
|
|
start: function() {
|
2328 |
|
|
debug('start');
|
2329 |
|
|
self.iframeObj.loaded();
|
2330 |
|
|
}
|
2331 |
|
|
, message: function(data) {
|
2332 |
|
|
debug('message', data);
|
2333 |
|
|
self.emit('message', data);
|
2334 |
|
|
}
|
2335 |
|
|
, stop: function() {
|
2336 |
|
|
debug('stop');
|
2337 |
|
|
self._cleanup();
|
2338 |
|
|
self._close('network');
|
2339 |
|
|
}
|
2340 |
|
|
};
|
2341 |
|
|
this.iframeObj = constructFunc(url, function() {
|
2342 |
|
|
debug('callback');
|
2343 |
|
|
self._cleanup();
|
2344 |
|
|
self._close('permanent');
|
2345 |
|
|
});
|
2346 |
|
|
}
|
2347 |
|
|
|
2348 |
|
|
inherits(HtmlfileReceiver, EventEmitter);
|
2349 |
|
|
|
2350 |
|
|
HtmlfileReceiver.prototype.abort = function() {
|
2351 |
|
|
debug('abort');
|
2352 |
|
|
this._cleanup();
|
2353 |
|
|
this._close('user');
|
2354 |
|
|
};
|
2355 |
|
|
|
2356 |
|
|
HtmlfileReceiver.prototype._cleanup = function() {
|
2357 |
|
|
debug('_cleanup');
|
2358 |
|
|
if (this.iframeObj) {
|
2359 |
|
|
this.iframeObj.cleanup();
|
2360 |
|
|
this.iframeObj = null;
|
2361 |
|
|
}
|
2362 |
|
|
delete global[iframeUtils.WPrefix][this.id];
|
2363 |
|
|
};
|
2364 |
|
|
|
2365 |
|
|
HtmlfileReceiver.prototype._close = function(reason) {
|
2366 |
|
|
debug('_close', reason);
|
2367 |
|
|
this.emit('close', null, reason);
|
2368 |
|
|
this.removeAllListeners();
|
2369 |
|
|
};
|
2370 |
|
|
|
2371 |
|
|
HtmlfileReceiver.htmlfileEnabled = false;
|
2372 |
|
|
|
2373 |
|
|
// obfuscate to avoid firewalls
|
2374 |
|
|
var axo = ['Active'].concat('Object').join('X');
|
2375 |
|
|
if (axo in global) {
|
2376 |
|
|
try {
|
2377 |
|
|
HtmlfileReceiver.htmlfileEnabled = !!new global[axo]('htmlfile');
|
2378 |
|
|
} catch (x) {
|
2379 |
|
|
// intentionally empty
|
2380 |
|
|
}
|
2381 |
|
|
}
|
2382 |
|
|
|
2383 |
|
|
HtmlfileReceiver.enabled = HtmlfileReceiver.htmlfileEnabled || iframeUtils.iframeEnabled;
|
2384 |
|
|
|
2385 |
|
|
module.exports = HtmlfileReceiver;
|
2386 |
|
|
|
2387 |
|
|
}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
2388 |
|
|
|
2389 |
|
|
},{"../../utils/iframe":47,"../../utils/random":50,"../../utils/url":52,"debug":55,"events":3,"inherits":57}],31:[function(require,module,exports){
|
2390 |
|
|
(function (process,global){
|
2391 |
|
|
'use strict';
|
2392 |
|
|
|
2393 |
|
|
var utils = require('../../utils/iframe')
|
2394 |
|
|
, random = require('../../utils/random')
|
2395 |
|
|
, browser = require('../../utils/browser')
|
2396 |
|
|
, urlUtils = require('../../utils/url')
|
2397 |
|
|
, inherits = require('inherits')
|
2398 |
|
|
, EventEmitter = require('events').EventEmitter
|
2399 |
|
|
;
|
2400 |
|
|
|
2401 |
|
|
var debug = function() {};
|
2402 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
2403 |
|
|
debug = require('debug')('sockjs-client:receiver:jsonp');
|
2404 |
|
|
}
|
2405 |
|
|
|
2406 |
|
|
function JsonpReceiver(url) {
|
2407 |
|
|
debug(url);
|
2408 |
|
|
var self = this;
|
2409 |
|
|
EventEmitter.call(this);
|
2410 |
|
|
|
2411 |
|
|
utils.polluteGlobalNamespace();
|
2412 |
|
|
|
2413 |
|
|
this.id = 'a' + random.string(6);
|
2414 |
|
|
var urlWithId = urlUtils.addQuery(url, 'c=' + encodeURIComponent(utils.WPrefix + '.' + this.id));
|
2415 |
|
|
|
2416 |
|
|
global[utils.WPrefix][this.id] = this._callback.bind(this);
|
2417 |
|
|
this._createScript(urlWithId);
|
2418 |
|
|
|
2419 |
|
|
// Fallback mostly for Konqueror - stupid timer, 35 seconds shall be plenty.
|
2420 |
|
|
this.timeoutId = setTimeout(function() {
|
2421 |
|
|
debug('timeout');
|
2422 |
|
|
self._abort(new Error('JSONP script loaded abnormally (timeout)'));
|
2423 |
|
|
}, JsonpReceiver.timeout);
|
2424 |
|
|
}
|
2425 |
|
|
|
2426 |
|
|
inherits(JsonpReceiver, EventEmitter);
|
2427 |
|
|
|
2428 |
|
|
JsonpReceiver.prototype.abort = function() {
|
2429 |
|
|
debug('abort');
|
2430 |
|
|
if (global[utils.WPrefix][this.id]) {
|
2431 |
|
|
var err = new Error('JSONP user aborted read');
|
2432 |
|
|
err.code = 1000;
|
2433 |
|
|
this._abort(err);
|
2434 |
|
|
}
|
2435 |
|
|
};
|
2436 |
|
|
|
2437 |
|
|
JsonpReceiver.timeout = 35000;
|
2438 |
|
|
JsonpReceiver.scriptErrorTimeout = 1000;
|
2439 |
|
|
|
2440 |
|
|
JsonpReceiver.prototype._callback = function(data) {
|
2441 |
|
|
debug('_callback', data);
|
2442 |
|
|
this._cleanup();
|
2443 |
|
|
|
2444 |
|
|
if (this.aborting) {
|
2445 |
|
|
return;
|
2446 |
|
|
}
|
2447 |
|
|
|
2448 |
|
|
if (data) {
|
2449 |
|
|
debug('message', data);
|
2450 |
|
|
this.emit('message', data);
|
2451 |
|
|
}
|
2452 |
|
|
this.emit('close', null, 'network');
|
2453 |
|
|
this.removeAllListeners();
|
2454 |
|
|
};
|
2455 |
|
|
|
2456 |
|
|
JsonpReceiver.prototype._abort = function(err) {
|
2457 |
|
|
debug('_abort', err);
|
2458 |
|
|
this._cleanup();
|
2459 |
|
|
this.aborting = true;
|
2460 |
|
|
this.emit('close', err.code, err.message);
|
2461 |
|
|
this.removeAllListeners();
|
2462 |
|
|
};
|
2463 |
|
|
|
2464 |
|
|
JsonpReceiver.prototype._cleanup = function() {
|
2465 |
|
|
debug('_cleanup');
|
2466 |
|
|
clearTimeout(this.timeoutId);
|
2467 |
|
|
if (this.script2) {
|
2468 |
|
|
this.script2.parentNode.removeChild(this.script2);
|
2469 |
|
|
this.script2 = null;
|
2470 |
|
|
}
|
2471 |
|
|
if (this.script) {
|
2472 |
|
|
var script = this.script;
|
2473 |
|
|
// Unfortunately, you can't really abort script loading of
|
2474 |
|
|
// the script.
|
2475 |
|
|
script.parentNode.removeChild(script);
|
2476 |
|
|
script.onreadystatechange = script.onerror =
|
2477 |
|
|
script.onload = script.onclick = null;
|
2478 |
|
|
this.script = null;
|
2479 |
|
|
}
|
2480 |
|
|
delete global[utils.WPrefix][this.id];
|
2481 |
|
|
};
|
2482 |
|
|
|
2483 |
|
|
JsonpReceiver.prototype._scriptError = function() {
|
2484 |
|
|
debug('_scriptError');
|
2485 |
|
|
var self = this;
|
2486 |
|
|
if (this.errorTimer) {
|
2487 |
|
|
return;
|
2488 |
|
|
}
|
2489 |
|
|
|
2490 |
|
|
this.errorTimer = setTimeout(function() {
|
2491 |
|
|
if (!self.loadedOkay) {
|
2492 |
|
|
self._abort(new Error('JSONP script loaded abnormally (onerror)'));
|
2493 |
|
|
}
|
2494 |
|
|
}, JsonpReceiver.scriptErrorTimeout);
|
2495 |
|
|
};
|
2496 |
|
|
|
2497 |
|
|
JsonpReceiver.prototype._createScript = function(url) {
|
2498 |
|
|
debug('_createScript', url);
|
2499 |
|
|
var self = this;
|
2500 |
|
|
var script = this.script = global.document.createElement('script');
|
2501 |
|
|
var script2; // Opera synchronous load trick.
|
2502 |
|
|
|
2503 |
|
|
script.id = 'a' + random.string(8);
|
2504 |
|
|
script.src = url;
|
2505 |
|
|
script.type = 'text/javascript';
|
2506 |
|
|
script.charset = 'UTF-8';
|
2507 |
|
|
script.onerror = this._scriptError.bind(this);
|
2508 |
|
|
script.onload = function() {
|
2509 |
|
|
debug('onload');
|
2510 |
|
|
self._abort(new Error('JSONP script loaded abnormally (onload)'));
|
2511 |
|
|
};
|
2512 |
|
|
|
2513 |
|
|
// IE9 fires 'error' event after onreadystatechange or before, in random order.
|
2514 |
|
|
// Use loadedOkay to determine if actually errored
|
2515 |
|
|
script.onreadystatechange = function() {
|
2516 |
|
|
debug('onreadystatechange', script.readyState);
|
2517 |
|
|
if (/loaded|closed/.test(script.readyState)) {
|
2518 |
|
|
if (script && script.htmlFor && script.onclick) {
|
2519 |
|
|
self.loadedOkay = true;
|
2520 |
|
|
try {
|
2521 |
|
|
// In IE, actually execute the script.
|
2522 |
|
|
script.onclick();
|
2523 |
|
|
} catch (x) {
|
2524 |
|
|
// intentionally empty
|
2525 |
|
|
}
|
2526 |
|
|
}
|
2527 |
|
|
if (script) {
|
2528 |
|
|
self._abort(new Error('JSONP script loaded abnormally (onreadystatechange)'));
|
2529 |
|
|
}
|
2530 |
|
|
}
|
2531 |
|
|
};
|
2532 |
|
|
// IE: event/htmlFor/onclick trick.
|
2533 |
|
|
// One can't rely on proper order for onreadystatechange. In order to
|
2534 |
|
|
// make sure, set a 'htmlFor' and 'event' properties, so that
|
2535 |
|
|
// script code will be installed as 'onclick' handler for the
|
2536 |
|
|
// script object. Later, onreadystatechange, manually execute this
|
2537 |
|
|
// code. FF and Chrome doesn't work with 'event' and 'htmlFor'
|
2538 |
|
|
// set. For reference see:
|
2539 |
|
|
// http://jaubourg.net/2010/07/loading-script-as-onclick-handler-of.html
|
2540 |
|
|
// Also, read on that about script ordering:
|
2541 |
|
|
// http://wiki.whatwg.org/wiki/Dynamic_Script_Execution_Order
|
2542 |
|
|
if (typeof script.async === 'undefined' && global.document.attachEvent) {
|
2543 |
|
|
// According to mozilla docs, in recent browsers script.async defaults
|
2544 |
|
|
// to 'true', so we may use it to detect a good browser:
|
2545 |
|
|
// https://developer.mozilla.org/en/HTML/Element/script
|
2546 |
|
|
if (!browser.isOpera()) {
|
2547 |
|
|
// Naively assume we're in IE
|
2548 |
|
|
try {
|
2549 |
|
|
script.htmlFor = script.id;
|
2550 |
|
|
script.event = 'onclick';
|
2551 |
|
|
} catch (x) {
|
2552 |
|
|
// intentionally empty
|
2553 |
|
|
}
|
2554 |
|
|
script.async = true;
|
2555 |
|
|
} else {
|
2556 |
|
|
// Opera, second sync script hack
|
2557 |
|
|
script2 = this.script2 = global.document.createElement('script');
|
2558 |
|
|
script2.text = "try{var a = document.getElementById('" + script.id + "'); if(a)a.onerror();}catch(x){};";
|
2559 |
|
|
script.async = script2.async = false;
|
2560 |
|
|
}
|
2561 |
|
|
}
|
2562 |
|
|
if (typeof script.async !== 'undefined') {
|
2563 |
|
|
script.async = true;
|
2564 |
|
|
}
|
2565 |
|
|
|
2566 |
|
|
var head = global.document.getElementsByTagName('head')[0];
|
2567 |
|
|
head.insertBefore(script, head.firstChild);
|
2568 |
|
|
if (script2) {
|
2569 |
|
|
head.insertBefore(script2, head.firstChild);
|
2570 |
|
|
}
|
2571 |
|
|
};
|
2572 |
|
|
|
2573 |
|
|
module.exports = JsonpReceiver;
|
2574 |
|
|
|
2575 |
|
|
}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
2576 |
|
|
|
2577 |
|
|
},{"../../utils/browser":44,"../../utils/iframe":47,"../../utils/random":50,"../../utils/url":52,"debug":55,"events":3,"inherits":57}],32:[function(require,module,exports){
|
2578 |
|
|
(function (process){
|
2579 |
|
|
'use strict';
|
2580 |
|
|
|
2581 |
|
|
var inherits = require('inherits')
|
2582 |
|
|
, EventEmitter = require('events').EventEmitter
|
2583 |
|
|
;
|
2584 |
|
|
|
2585 |
|
|
var debug = function() {};
|
2586 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
2587 |
|
|
debug = require('debug')('sockjs-client:receiver:xhr');
|
2588 |
|
|
}
|
2589 |
|
|
|
2590 |
|
|
function XhrReceiver(url, AjaxObject) {
|
2591 |
|
|
debug(url);
|
2592 |
|
|
EventEmitter.call(this);
|
2593 |
|
|
var self = this;
|
2594 |
|
|
|
2595 |
|
|
this.bufferPosition = 0;
|
2596 |
|
|
|
2597 |
|
|
this.xo = new AjaxObject('POST', url, null);
|
2598 |
|
|
this.xo.on('chunk', this._chunkHandler.bind(this));
|
2599 |
|
|
this.xo.once('finish', function(status, text) {
|
2600 |
|
|
debug('finish', status, text);
|
2601 |
|
|
self._chunkHandler(status, text);
|
2602 |
|
|
self.xo = null;
|
2603 |
|
|
var reason = status === 200 ? 'network' : 'permanent';
|
2604 |
|
|
debug('close', reason);
|
2605 |
|
|
self.emit('close', null, reason);
|
2606 |
|
|
self._cleanup();
|
2607 |
|
|
});
|
2608 |
|
|
}
|
2609 |
|
|
|
2610 |
|
|
inherits(XhrReceiver, EventEmitter);
|
2611 |
|
|
|
2612 |
|
|
XhrReceiver.prototype._chunkHandler = function(status, text) {
|
2613 |
|
|
debug('_chunkHandler', status);
|
2614 |
|
|
if (status !== 200 || !text) {
|
2615 |
|
|
return;
|
2616 |
|
|
}
|
2617 |
|
|
|
2618 |
|
|
for (var idx = -1; ; this.bufferPosition += idx + 1) {
|
2619 |
|
|
var buf = text.slice(this.bufferPosition);
|
2620 |
|
|
idx = buf.indexOf('\n');
|
2621 |
|
|
if (idx === -1) {
|
2622 |
|
|
break;
|
2623 |
|
|
}
|
2624 |
|
|
var msg = buf.slice(0, idx);
|
2625 |
|
|
if (msg) {
|
2626 |
|
|
debug('message', msg);
|
2627 |
|
|
this.emit('message', msg);
|
2628 |
|
|
}
|
2629 |
|
|
}
|
2630 |
|
|
};
|
2631 |
|
|
|
2632 |
|
|
XhrReceiver.prototype._cleanup = function() {
|
2633 |
|
|
debug('_cleanup');
|
2634 |
|
|
this.removeAllListeners();
|
2635 |
|
|
};
|
2636 |
|
|
|
2637 |
|
|
XhrReceiver.prototype.abort = function() {
|
2638 |
|
|
debug('abort');
|
2639 |
|
|
if (this.xo) {
|
2640 |
|
|
this.xo.close();
|
2641 |
|
|
debug('close');
|
2642 |
|
|
this.emit('close', null, 'user');
|
2643 |
|
|
this.xo = null;
|
2644 |
|
|
}
|
2645 |
|
|
this._cleanup();
|
2646 |
|
|
};
|
2647 |
|
|
|
2648 |
|
|
module.exports = XhrReceiver;
|
2649 |
|
|
|
2650 |
|
|
}).call(this,{ env: {} })
|
2651 |
|
|
|
2652 |
|
|
},{"debug":55,"events":3,"inherits":57}],33:[function(require,module,exports){
|
2653 |
|
|
(function (process,global){
|
2654 |
|
|
'use strict';
|
2655 |
|
|
|
2656 |
|
|
var random = require('../../utils/random')
|
2657 |
|
|
, urlUtils = require('../../utils/url')
|
2658 |
|
|
;
|
2659 |
|
|
|
2660 |
|
|
var debug = function() {};
|
2661 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
2662 |
|
|
debug = require('debug')('sockjs-client:sender:jsonp');
|
2663 |
|
|
}
|
2664 |
|
|
|
2665 |
|
|
var form, area;
|
2666 |
|
|
|
2667 |
|
|
function createIframe(id) {
|
2668 |
|
|
debug('createIframe', id);
|
2669 |
|
|
try {
|
2670 |
|
|
// ie6 dynamic iframes with target="" support (thanks Chris Lambacher)
|
2671 |
|
|
return global.document.createElement('<iframe name="' + id + '">');
|
2672 |
|
|
} catch (x) {
|
2673 |
|
|
var iframe = global.document.createElement('iframe');
|
2674 |
|
|
iframe.name = id;
|
2675 |
|
|
return iframe;
|
2676 |
|
|
}
|
2677 |
|
|
}
|
2678 |
|
|
|
2679 |
|
|
function createForm() {
|
2680 |
|
|
debug('createForm');
|
2681 |
|
|
form = global.document.createElement('form');
|
2682 |
|
|
form.style.display = 'none';
|
2683 |
|
|
form.style.position = 'absolute';
|
2684 |
|
|
form.method = 'POST';
|
2685 |
|
|
form.enctype = 'application/x-www-form-urlencoded';
|
2686 |
|
|
form.acceptCharset = 'UTF-8';
|
2687 |
|
|
|
2688 |
|
|
area = global.document.createElement('textarea');
|
2689 |
|
|
area.name = 'd';
|
2690 |
|
|
form.appendChild(area);
|
2691 |
|
|
|
2692 |
|
|
global.document.body.appendChild(form);
|
2693 |
|
|
}
|
2694 |
|
|
|
2695 |
|
|
module.exports = function(url, payload, callback) {
|
2696 |
|
|
debug(url, payload);
|
2697 |
|
|
if (!form) {
|
2698 |
|
|
createForm();
|
2699 |
|
|
}
|
2700 |
|
|
var id = 'a' + random.string(8);
|
2701 |
|
|
form.target = id;
|
2702 |
|
|
form.action = urlUtils.addQuery(urlUtils.addPath(url, '/jsonp_send'), 'i=' + id);
|
2703 |
|
|
|
2704 |
|
|
var iframe = createIframe(id);
|
2705 |
|
|
iframe.id = id;
|
2706 |
|
|
iframe.style.display = 'none';
|
2707 |
|
|
form.appendChild(iframe);
|
2708 |
|
|
|
2709 |
|
|
try {
|
2710 |
|
|
area.value = payload;
|
2711 |
|
|
} catch (e) {
|
2712 |
|
|
// seriously broken browsers get here
|
2713 |
|
|
}
|
2714 |
|
|
form.submit();
|
2715 |
|
|
|
2716 |
|
|
var completed = function(err) {
|
2717 |
|
|
debug('completed', id, err);
|
2718 |
|
|
if (!iframe.onerror) {
|
2719 |
|
|
return;
|
2720 |
|
|
}
|
2721 |
|
|
iframe.onreadystatechange = iframe.onerror = iframe.onload = null;
|
2722 |
|
|
// Opera mini doesn't like if we GC iframe
|
2723 |
|
|
// immediately, thus this timeout.
|
2724 |
|
|
setTimeout(function() {
|
2725 |
|
|
debug('cleaning up', id);
|
2726 |
|
|
iframe.parentNode.removeChild(iframe);
|
2727 |
|
|
iframe = null;
|
2728 |
|
|
}, 500);
|
2729 |
|
|
area.value = '';
|
2730 |
|
|
// It is not possible to detect if the iframe succeeded or
|
2731 |
|
|
// failed to submit our form.
|
2732 |
|
|
callback(err);
|
2733 |
|
|
};
|
2734 |
|
|
iframe.onerror = function() {
|
2735 |
|
|
debug('onerror', id);
|
2736 |
|
|
completed();
|
2737 |
|
|
};
|
2738 |
|
|
iframe.onload = function() {
|
2739 |
|
|
debug('onload', id);
|
2740 |
|
|
completed();
|
2741 |
|
|
};
|
2742 |
|
|
iframe.onreadystatechange = function(e) {
|
2743 |
|
|
debug('onreadystatechange', id, iframe.readyState, e);
|
2744 |
|
|
if (iframe.readyState === 'complete') {
|
2745 |
|
|
completed();
|
2746 |
|
|
}
|
2747 |
|
|
};
|
2748 |
|
|
return function() {
|
2749 |
|
|
debug('aborted', id);
|
2750 |
|
|
completed(new Error('Aborted'));
|
2751 |
|
|
};
|
2752 |
|
|
};
|
2753 |
|
|
|
2754 |
|
|
}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
2755 |
|
|
|
2756 |
|
|
},{"../../utils/random":50,"../../utils/url":52,"debug":55}],34:[function(require,module,exports){
|
2757 |
|
|
(function (process,global){
|
2758 |
|
|
'use strict';
|
2759 |
|
|
|
2760 |
|
|
var EventEmitter = require('events').EventEmitter
|
2761 |
|
|
, inherits = require('inherits')
|
2762 |
|
|
, eventUtils = require('../../utils/event')
|
2763 |
|
|
, browser = require('../../utils/browser')
|
2764 |
|
|
, urlUtils = require('../../utils/url')
|
2765 |
|
|
;
|
2766 |
|
|
|
2767 |
|
|
var debug = function() {};
|
2768 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
2769 |
|
|
debug = require('debug')('sockjs-client:sender:xdr');
|
2770 |
|
|
}
|
2771 |
|
|
|
2772 |
|
|
// References:
|
2773 |
|
|
// http://ajaxian.com/archives/100-line-ajax-wrapper
|
2774 |
|
|
// http://msdn.microsoft.com/en-us/library/cc288060(v=VS.85).aspx
|
2775 |
|
|
|
2776 |
|
|
function XDRObject(method, url, payload) {
|
2777 |
|
|
debug(method, url);
|
2778 |
|
|
var self = this;
|
2779 |
|
|
EventEmitter.call(this);
|
2780 |
|
|
|
2781 |
|
|
setTimeout(function() {
|
2782 |
|
|
self._start(method, url, payload);
|
2783 |
|
|
}, 0);
|
2784 |
|
|
}
|
2785 |
|
|
|
2786 |
|
|
inherits(XDRObject, EventEmitter);
|
2787 |
|
|
|
2788 |
|
|
XDRObject.prototype._start = function(method, url, payload) {
|
2789 |
|
|
debug('_start');
|
2790 |
|
|
var self = this;
|
2791 |
|
|
var xdr = new global.XDomainRequest();
|
2792 |
|
|
// IE caches even POSTs
|
2793 |
|
|
url = urlUtils.addQuery(url, 't=' + (+new Date()));
|
2794 |
|
|
|
2795 |
|
|
xdr.onerror = function() {
|
2796 |
|
|
debug('onerror');
|
2797 |
|
|
self._error();
|
2798 |
|
|
};
|
2799 |
|
|
xdr.ontimeout = function() {
|
2800 |
|
|
debug('ontimeout');
|
2801 |
|
|
self._error();
|
2802 |
|
|
};
|
2803 |
|
|
xdr.onprogress = function() {
|
2804 |
|
|
debug('progress', xdr.responseText);
|
2805 |
|
|
self.emit('chunk', 200, xdr.responseText);
|
2806 |
|
|
};
|
2807 |
|
|
xdr.onload = function() {
|
2808 |
|
|
debug('load');
|
2809 |
|
|
self.emit('finish', 200, xdr.responseText);
|
2810 |
|
|
self._cleanup(false);
|
2811 |
|
|
};
|
2812 |
|
|
this.xdr = xdr;
|
2813 |
|
|
this.unloadRef = eventUtils.unloadAdd(function() {
|
2814 |
|
|
self._cleanup(true);
|
2815 |
|
|
});
|
2816 |
|
|
try {
|
2817 |
|
|
// Fails with AccessDenied if port number is bogus
|
2818 |
|
|
this.xdr.open(method, url);
|
2819 |
|
|
if (this.timeout) {
|
2820 |
|
|
this.xdr.timeout = this.timeout;
|
2821 |
|
|
}
|
2822 |
|
|
this.xdr.send(payload);
|
2823 |
|
|
} catch (x) {
|
2824 |
|
|
this._error();
|
2825 |
|
|
}
|
2826 |
|
|
};
|
2827 |
|
|
|
2828 |
|
|
XDRObject.prototype._error = function() {
|
2829 |
|
|
this.emit('finish', 0, '');
|
2830 |
|
|
this._cleanup(false);
|
2831 |
|
|
};
|
2832 |
|
|
|
2833 |
|
|
XDRObject.prototype._cleanup = function(abort) {
|
2834 |
|
|
debug('cleanup', abort);
|
2835 |
|
|
if (!this.xdr) {
|
2836 |
|
|
return;
|
2837 |
|
|
}
|
2838 |
|
|
this.removeAllListeners();
|
2839 |
|
|
eventUtils.unloadDel(this.unloadRef);
|
2840 |
|
|
|
2841 |
|
|
this.xdr.ontimeout = this.xdr.onerror = this.xdr.onprogress = this.xdr.onload = null;
|
2842 |
|
|
if (abort) {
|
2843 |
|
|
try {
|
2844 |
|
|
this.xdr.abort();
|
2845 |
|
|
} catch (x) {
|
2846 |
|
|
// intentionally empty
|
2847 |
|
|
}
|
2848 |
|
|
}
|
2849 |
|
|
this.unloadRef = this.xdr = null;
|
2850 |
|
|
};
|
2851 |
|
|
|
2852 |
|
|
XDRObject.prototype.close = function() {
|
2853 |
|
|
debug('close');
|
2854 |
|
|
this._cleanup(true);
|
2855 |
|
|
};
|
2856 |
|
|
|
2857 |
|
|
// IE 8/9 if the request target uses the same scheme - #79
|
2858 |
|
|
XDRObject.enabled = !!(global.XDomainRequest && browser.hasDomain());
|
2859 |
|
|
|
2860 |
|
|
module.exports = XDRObject;
|
2861 |
|
|
|
2862 |
|
|
}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
2863 |
|
|
|
2864 |
|
|
},{"../../utils/browser":44,"../../utils/event":46,"../../utils/url":52,"debug":55,"events":3,"inherits":57}],35:[function(require,module,exports){
|
2865 |
|
|
'use strict';
|
2866 |
|
|
|
2867 |
|
|
var inherits = require('inherits')
|
2868 |
|
|
, XhrDriver = require('../driver/xhr')
|
2869 |
|
|
;
|
2870 |
|
|
|
2871 |
|
|
function XHRCorsObject(method, url, payload, opts) {
|
2872 |
|
|
XhrDriver.call(this, method, url, payload, opts);
|
2873 |
|
|
}
|
2874 |
|
|
|
2875 |
|
|
inherits(XHRCorsObject, XhrDriver);
|
2876 |
|
|
|
2877 |
|
|
XHRCorsObject.enabled = XhrDriver.enabled && XhrDriver.supportsCORS;
|
2878 |
|
|
|
2879 |
|
|
module.exports = XHRCorsObject;
|
2880 |
|
|
|
2881 |
|
|
},{"../driver/xhr":17,"inherits":57}],36:[function(require,module,exports){
|
2882 |
|
|
'use strict';
|
2883 |
|
|
|
2884 |
|
|
var EventEmitter = require('events').EventEmitter
|
2885 |
|
|
, inherits = require('inherits')
|
2886 |
|
|
;
|
2887 |
|
|
|
2888 |
|
|
function XHRFake(/* method, url, payload, opts */) {
|
2889 |
|
|
var self = this;
|
2890 |
|
|
EventEmitter.call(this);
|
2891 |
|
|
|
2892 |
|
|
this.to = setTimeout(function() {
|
2893 |
|
|
self.emit('finish', 200, '{}');
|
2894 |
|
|
}, XHRFake.timeout);
|
2895 |
|
|
}
|
2896 |
|
|
|
2897 |
|
|
inherits(XHRFake, EventEmitter);
|
2898 |
|
|
|
2899 |
|
|
XHRFake.prototype.close = function() {
|
2900 |
|
|
clearTimeout(this.to);
|
2901 |
|
|
};
|
2902 |
|
|
|
2903 |
|
|
XHRFake.timeout = 2000;
|
2904 |
|
|
|
2905 |
|
|
module.exports = XHRFake;
|
2906 |
|
|
|
2907 |
|
|
},{"events":3,"inherits":57}],37:[function(require,module,exports){
|
2908 |
|
|
'use strict';
|
2909 |
|
|
|
2910 |
|
|
var inherits = require('inherits')
|
2911 |
|
|
, XhrDriver = require('../driver/xhr')
|
2912 |
|
|
;
|
2913 |
|
|
|
2914 |
|
|
function XHRLocalObject(method, url, payload /*, opts */) {
|
2915 |
|
|
XhrDriver.call(this, method, url, payload, {
|
2916 |
|
|
noCredentials: true
|
2917 |
|
|
});
|
2918 |
|
|
}
|
2919 |
|
|
|
2920 |
|
|
inherits(XHRLocalObject, XhrDriver);
|
2921 |
|
|
|
2922 |
|
|
XHRLocalObject.enabled = XhrDriver.enabled;
|
2923 |
|
|
|
2924 |
|
|
module.exports = XHRLocalObject;
|
2925 |
|
|
|
2926 |
|
|
},{"../driver/xhr":17,"inherits":57}],38:[function(require,module,exports){
|
2927 |
|
|
(function (process){
|
2928 |
|
|
'use strict';
|
2929 |
|
|
|
2930 |
|
|
var utils = require('../utils/event')
|
2931 |
|
|
, urlUtils = require('../utils/url')
|
2932 |
|
|
, inherits = require('inherits')
|
2933 |
|
|
, EventEmitter = require('events').EventEmitter
|
2934 |
|
|
, WebsocketDriver = require('./driver/websocket')
|
2935 |
|
|
;
|
2936 |
|
|
|
2937 |
|
|
var debug = function() {};
|
2938 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
2939 |
|
|
debug = require('debug')('sockjs-client:websocket');
|
2940 |
|
|
}
|
2941 |
|
|
|
2942 |
|
|
function WebSocketTransport(transUrl, ignore, options) {
|
2943 |
|
|
if (!WebSocketTransport.enabled()) {
|
2944 |
|
|
throw new Error('Transport created when disabled');
|
2945 |
|
|
}
|
2946 |
|
|
|
2947 |
|
|
EventEmitter.call(this);
|
2948 |
|
|
debug('constructor', transUrl);
|
2949 |
|
|
|
2950 |
|
|
var self = this;
|
2951 |
|
|
var url = urlUtils.addPath(transUrl, '/websocket');
|
2952 |
|
|
if (url.slice(0, 5) === 'https') {
|
2953 |
|
|
url = 'wss' + url.slice(5);
|
2954 |
|
|
} else {
|
2955 |
|
|
url = 'ws' + url.slice(4);
|
2956 |
|
|
}
|
2957 |
|
|
this.url = url;
|
2958 |
|
|
|
2959 |
|
|
this.ws = new WebsocketDriver(this.url, [], options);
|
2960 |
|
|
this.ws.onmessage = function(e) {
|
2961 |
|
|
debug('message event', e.data);
|
2962 |
|
|
self.emit('message', e.data);
|
2963 |
|
|
};
|
2964 |
|
|
// Firefox has an interesting bug. If a websocket connection is
|
2965 |
|
|
// created after onunload, it stays alive even when user
|
2966 |
|
|
// navigates away from the page. In such situation let's lie -
|
2967 |
|
|
// let's not open the ws connection at all. See:
|
2968 |
|
|
// https://github.com/sockjs/sockjs-client/issues/28
|
2969 |
|
|
// https://bugzilla.mozilla.org/show_bug.cgi?id=696085
|
2970 |
|
|
this.unloadRef = utils.unloadAdd(function() {
|
2971 |
|
|
debug('unload');
|
2972 |
|
|
self.ws.close();
|
2973 |
|
|
});
|
2974 |
|
|
this.ws.onclose = function(e) {
|
2975 |
|
|
debug('close event', e.code, e.reason);
|
2976 |
|
|
self.emit('close', e.code, e.reason);
|
2977 |
|
|
self._cleanup();
|
2978 |
|
|
};
|
2979 |
|
|
this.ws.onerror = function(e) {
|
2980 |
|
|
debug('error event', e);
|
2981 |
|
|
self.emit('close', 1006, 'WebSocket connection broken');
|
2982 |
|
|
self._cleanup();
|
2983 |
|
|
};
|
2984 |
|
|
}
|
2985 |
|
|
|
2986 |
|
|
inherits(WebSocketTransport, EventEmitter);
|
2987 |
|
|
|
2988 |
|
|
WebSocketTransport.prototype.send = function(data) {
|
2989 |
|
|
var msg = '[' + data + ']';
|
2990 |
|
|
debug('send', msg);
|
2991 |
|
|
this.ws.send(msg);
|
2992 |
|
|
};
|
2993 |
|
|
|
2994 |
|
|
WebSocketTransport.prototype.close = function() {
|
2995 |
|
|
debug('close');
|
2996 |
|
|
var ws = this.ws;
|
2997 |
|
|
this._cleanup();
|
2998 |
|
|
if (ws) {
|
2999 |
|
|
ws.close();
|
3000 |
|
|
}
|
3001 |
|
|
};
|
3002 |
|
|
|
3003 |
|
|
WebSocketTransport.prototype._cleanup = function() {
|
3004 |
|
|
debug('_cleanup');
|
3005 |
|
|
var ws = this.ws;
|
3006 |
|
|
if (ws) {
|
3007 |
|
|
ws.onmessage = ws.onclose = ws.onerror = null;
|
3008 |
|
|
}
|
3009 |
|
|
utils.unloadDel(this.unloadRef);
|
3010 |
|
|
this.unloadRef = this.ws = null;
|
3011 |
|
|
this.removeAllListeners();
|
3012 |
|
|
};
|
3013 |
|
|
|
3014 |
|
|
WebSocketTransport.enabled = function() {
|
3015 |
|
|
debug('enabled');
|
3016 |
|
|
return !!WebsocketDriver;
|
3017 |
|
|
};
|
3018 |
|
|
WebSocketTransport.transportName = 'websocket';
|
3019 |
|
|
|
3020 |
|
|
// In theory, ws should require 1 round trip. But in chrome, this is
|
3021 |
|
|
// not very stable over SSL. Most likely a ws connection requires a
|
3022 |
|
|
// separate SSL connection, in which case 2 round trips are an
|
3023 |
|
|
// absolute minumum.
|
3024 |
|
|
WebSocketTransport.roundTrips = 2;
|
3025 |
|
|
|
3026 |
|
|
module.exports = WebSocketTransport;
|
3027 |
|
|
|
3028 |
|
|
}).call(this,{ env: {} })
|
3029 |
|
|
|
3030 |
|
|
},{"../utils/event":46,"../utils/url":52,"./driver/websocket":19,"debug":55,"events":3,"inherits":57}],39:[function(require,module,exports){
|
3031 |
|
|
'use strict';
|
3032 |
|
|
|
3033 |
|
|
var inherits = require('inherits')
|
3034 |
|
|
, AjaxBasedTransport = require('./lib/ajax-based')
|
3035 |
|
|
, XdrStreamingTransport = require('./xdr-streaming')
|
3036 |
|
|
, XhrReceiver = require('./receiver/xhr')
|
3037 |
|
|
, XDRObject = require('./sender/xdr')
|
3038 |
|
|
;
|
3039 |
|
|
|
3040 |
|
|
function XdrPollingTransport(transUrl) {
|
3041 |
|
|
if (!XDRObject.enabled) {
|
3042 |
|
|
throw new Error('Transport created when disabled');
|
3043 |
|
|
}
|
3044 |
|
|
AjaxBasedTransport.call(this, transUrl, '/xhr', XhrReceiver, XDRObject);
|
3045 |
|
|
}
|
3046 |
|
|
|
3047 |
|
|
inherits(XdrPollingTransport, AjaxBasedTransport);
|
3048 |
|
|
|
3049 |
|
|
XdrPollingTransport.enabled = XdrStreamingTransport.enabled;
|
3050 |
|
|
XdrPollingTransport.transportName = 'xdr-polling';
|
3051 |
|
|
XdrPollingTransport.roundTrips = 2; // preflight, ajax
|
3052 |
|
|
|
3053 |
|
|
module.exports = XdrPollingTransport;
|
3054 |
|
|
|
3055 |
|
|
},{"./lib/ajax-based":24,"./receiver/xhr":32,"./sender/xdr":34,"./xdr-streaming":40,"inherits":57}],40:[function(require,module,exports){
|
3056 |
|
|
'use strict';
|
3057 |
|
|
|
3058 |
|
|
var inherits = require('inherits')
|
3059 |
|
|
, AjaxBasedTransport = require('./lib/ajax-based')
|
3060 |
|
|
, XhrReceiver = require('./receiver/xhr')
|
3061 |
|
|
, XDRObject = require('./sender/xdr')
|
3062 |
|
|
;
|
3063 |
|
|
|
3064 |
|
|
// According to:
|
3065 |
|
|
// http://stackoverflow.com/questions/1641507/detect-browser-support-for-cross-domain-xmlhttprequests
|
3066 |
|
|
// http://hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
|
3067 |
|
|
|
3068 |
|
|
function XdrStreamingTransport(transUrl) {
|
3069 |
|
|
if (!XDRObject.enabled) {
|
3070 |
|
|
throw new Error('Transport created when disabled');
|
3071 |
|
|
}
|
3072 |
|
|
AjaxBasedTransport.call(this, transUrl, '/xhr_streaming', XhrReceiver, XDRObject);
|
3073 |
|
|
}
|
3074 |
|
|
|
3075 |
|
|
inherits(XdrStreamingTransport, AjaxBasedTransport);
|
3076 |
|
|
|
3077 |
|
|
XdrStreamingTransport.enabled = function(info) {
|
3078 |
|
|
if (info.cookie_needed || info.nullOrigin) {
|
3079 |
|
|
return false;
|
3080 |
|
|
}
|
3081 |
|
|
return XDRObject.enabled && info.sameScheme;
|
3082 |
|
|
};
|
3083 |
|
|
|
3084 |
|
|
XdrStreamingTransport.transportName = 'xdr-streaming';
|
3085 |
|
|
XdrStreamingTransport.roundTrips = 2; // preflight, ajax
|
3086 |
|
|
|
3087 |
|
|
module.exports = XdrStreamingTransport;
|
3088 |
|
|
|
3089 |
|
|
},{"./lib/ajax-based":24,"./receiver/xhr":32,"./sender/xdr":34,"inherits":57}],41:[function(require,module,exports){
|
3090 |
|
|
'use strict';
|
3091 |
|
|
|
3092 |
|
|
var inherits = require('inherits')
|
3093 |
|
|
, AjaxBasedTransport = require('./lib/ajax-based')
|
3094 |
|
|
, XhrReceiver = require('./receiver/xhr')
|
3095 |
|
|
, XHRCorsObject = require('./sender/xhr-cors')
|
3096 |
|
|
, XHRLocalObject = require('./sender/xhr-local')
|
3097 |
|
|
;
|
3098 |
|
|
|
3099 |
|
|
function XhrPollingTransport(transUrl) {
|
3100 |
|
|
if (!XHRLocalObject.enabled && !XHRCorsObject.enabled) {
|
3101 |
|
|
throw new Error('Transport created when disabled');
|
3102 |
|
|
}
|
3103 |
|
|
AjaxBasedTransport.call(this, transUrl, '/xhr', XhrReceiver, XHRCorsObject);
|
3104 |
|
|
}
|
3105 |
|
|
|
3106 |
|
|
inherits(XhrPollingTransport, AjaxBasedTransport);
|
3107 |
|
|
|
3108 |
|
|
XhrPollingTransport.enabled = function(info) {
|
3109 |
|
|
if (info.nullOrigin) {
|
3110 |
|
|
return false;
|
3111 |
|
|
}
|
3112 |
|
|
|
3113 |
|
|
if (XHRLocalObject.enabled && info.sameOrigin) {
|
3114 |
|
|
return true;
|
3115 |
|
|
}
|
3116 |
|
|
return XHRCorsObject.enabled;
|
3117 |
|
|
};
|
3118 |
|
|
|
3119 |
|
|
XhrPollingTransport.transportName = 'xhr-polling';
|
3120 |
|
|
XhrPollingTransport.roundTrips = 2; // preflight, ajax
|
3121 |
|
|
|
3122 |
|
|
module.exports = XhrPollingTransport;
|
3123 |
|
|
|
3124 |
|
|
},{"./lib/ajax-based":24,"./receiver/xhr":32,"./sender/xhr-cors":35,"./sender/xhr-local":37,"inherits":57}],42:[function(require,module,exports){
|
3125 |
|
|
(function (global){
|
3126 |
|
|
'use strict';
|
3127 |
|
|
|
3128 |
|
|
var inherits = require('inherits')
|
3129 |
|
|
, AjaxBasedTransport = require('./lib/ajax-based')
|
3130 |
|
|
, XhrReceiver = require('./receiver/xhr')
|
3131 |
|
|
, XHRCorsObject = require('./sender/xhr-cors')
|
3132 |
|
|
, XHRLocalObject = require('./sender/xhr-local')
|
3133 |
|
|
, browser = require('../utils/browser')
|
3134 |
|
|
;
|
3135 |
|
|
|
3136 |
|
|
function XhrStreamingTransport(transUrl) {
|
3137 |
|
|
if (!XHRLocalObject.enabled && !XHRCorsObject.enabled) {
|
3138 |
|
|
throw new Error('Transport created when disabled');
|
3139 |
|
|
}
|
3140 |
|
|
AjaxBasedTransport.call(this, transUrl, '/xhr_streaming', XhrReceiver, XHRCorsObject);
|
3141 |
|
|
}
|
3142 |
|
|
|
3143 |
|
|
inherits(XhrStreamingTransport, AjaxBasedTransport);
|
3144 |
|
|
|
3145 |
|
|
XhrStreamingTransport.enabled = function(info) {
|
3146 |
|
|
if (info.nullOrigin) {
|
3147 |
|
|
return false;
|
3148 |
|
|
}
|
3149 |
|
|
// Opera doesn't support xhr-streaming #60
|
3150 |
|
|
// But it might be able to #92
|
3151 |
|
|
if (browser.isOpera()) {
|
3152 |
|
|
return false;
|
3153 |
|
|
}
|
3154 |
|
|
|
3155 |
|
|
return XHRCorsObject.enabled;
|
3156 |
|
|
};
|
3157 |
|
|
|
3158 |
|
|
XhrStreamingTransport.transportName = 'xhr-streaming';
|
3159 |
|
|
XhrStreamingTransport.roundTrips = 2; // preflight, ajax
|
3160 |
|
|
|
3161 |
|
|
// Safari gets confused when a streaming ajax request is started
|
3162 |
|
|
// before onload. This causes the load indicator to spin indefinetely.
|
3163 |
|
|
// Only require body when used in a browser
|
3164 |
|
|
XhrStreamingTransport.needBody = !!global.document;
|
3165 |
|
|
|
3166 |
|
|
module.exports = XhrStreamingTransport;
|
3167 |
|
|
|
3168 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3169 |
|
|
|
3170 |
|
|
},{"../utils/browser":44,"./lib/ajax-based":24,"./receiver/xhr":32,"./sender/xhr-cors":35,"./sender/xhr-local":37,"inherits":57}],43:[function(require,module,exports){
|
3171 |
|
|
(function (global){
|
3172 |
|
|
'use strict';
|
3173 |
|
|
|
3174 |
|
|
if (global.crypto && global.crypto.getRandomValues) {
|
3175 |
|
|
module.exports.randomBytes = function(length) {
|
3176 |
|
|
var bytes = new Uint8Array(length);
|
3177 |
|
|
global.crypto.getRandomValues(bytes);
|
3178 |
|
|
return bytes;
|
3179 |
|
|
};
|
3180 |
|
|
} else {
|
3181 |
|
|
module.exports.randomBytes = function(length) {
|
3182 |
|
|
var bytes = new Array(length);
|
3183 |
|
|
for (var i = 0; i < length; i++) {
|
3184 |
|
|
bytes[i] = Math.floor(Math.random() * 256);
|
3185 |
|
|
}
|
3186 |
|
|
return bytes;
|
3187 |
|
|
};
|
3188 |
|
|
}
|
3189 |
|
|
|
3190 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3191 |
|
|
|
3192 |
|
|
},{}],44:[function(require,module,exports){
|
3193 |
|
|
(function (global){
|
3194 |
|
|
'use strict';
|
3195 |
|
|
|
3196 |
|
|
module.exports = {
|
3197 |
|
|
isOpera: function() {
|
3198 |
|
|
return global.navigator &&
|
3199 |
|
|
/opera/i.test(global.navigator.userAgent);
|
3200 |
|
|
}
|
3201 |
|
|
|
3202 |
|
|
, isKonqueror: function() {
|
3203 |
|
|
return global.navigator &&
|
3204 |
|
|
/konqueror/i.test(global.navigator.userAgent);
|
3205 |
|
|
}
|
3206 |
|
|
|
3207 |
|
|
// #187 wrap document.domain in try/catch because of WP8 from file:///
|
3208 |
|
|
, hasDomain: function () {
|
3209 |
|
|
// non-browser client always has a domain
|
3210 |
|
|
if (!global.document) {
|
3211 |
|
|
return true;
|
3212 |
|
|
}
|
3213 |
|
|
|
3214 |
|
|
try {
|
3215 |
|
|
return !!global.document.domain;
|
3216 |
|
|
} catch (e) {
|
3217 |
|
|
return false;
|
3218 |
|
|
}
|
3219 |
|
|
}
|
3220 |
|
|
};
|
3221 |
|
|
|
3222 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3223 |
|
|
|
3224 |
|
|
},{}],45:[function(require,module,exports){
|
3225 |
|
|
'use strict';
|
3226 |
|
|
|
3227 |
|
|
var JSON3 = require('json3');
|
3228 |
|
|
|
3229 |
|
|
// Some extra characters that Chrome gets wrong, and substitutes with
|
3230 |
|
|
// something else on the wire.
|
3231 |
|
|
// eslint-disable-next-line no-control-regex
|
3232 |
|
|
var extraEscapable = /[\x00-\x1f\ud800-\udfff\ufffe\uffff\u0300-\u0333\u033d-\u0346\u034a-\u034c\u0350-\u0352\u0357-\u0358\u035c-\u0362\u0374\u037e\u0387\u0591-\u05af\u05c4\u0610-\u0617\u0653-\u0654\u0657-\u065b\u065d-\u065e\u06df-\u06e2\u06eb-\u06ec\u0730\u0732-\u0733\u0735-\u0736\u073a\u073d\u073f-\u0741\u0743\u0745\u0747\u07eb-\u07f1\u0951\u0958-\u095f\u09dc-\u09dd\u09df\u0a33\u0a36\u0a59-\u0a5b\u0a5e\u0b5c-\u0b5d\u0e38-\u0e39\u0f43\u0f4d\u0f52\u0f57\u0f5c\u0f69\u0f72-\u0f76\u0f78\u0f80-\u0f83\u0f93\u0f9d\u0fa2\u0fa7\u0fac\u0fb9\u1939-\u193a\u1a17\u1b6b\u1cda-\u1cdb\u1dc0-\u1dcf\u1dfc\u1dfe\u1f71\u1f73\u1f75\u1f77\u1f79\u1f7b\u1f7d\u1fbb\u1fbe\u1fc9\u1fcb\u1fd3\u1fdb\u1fe3\u1feb\u1fee-\u1fef\u1ff9\u1ffb\u1ffd\u2000-\u2001\u20d0-\u20d1\u20d4-\u20d7\u20e7-\u20e9\u2126\u212a-\u212b\u2329-\u232a\u2adc\u302b-\u302c\uaab2-\uaab3\uf900-\ufa0d\ufa10\ufa12\ufa15-\ufa1e\ufa20\ufa22\ufa25-\ufa26\ufa2a-\ufa2d\ufa30-\ufa6d\ufa70-\ufad9\ufb1d\ufb1f\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40-\ufb41\ufb43-\ufb44\ufb46-\ufb4e\ufff0-\uffff]/g
|
3233 |
|
|
, extraLookup;
|
3234 |
|
|
|
3235 |
|
|
// This may be quite slow, so let's delay until user actually uses bad
|
3236 |
|
|
// characters.
|
3237 |
|
|
var unrollLookup = function(escapable) {
|
3238 |
|
|
var i;
|
3239 |
|
|
var unrolled = {};
|
3240 |
|
|
var c = [];
|
3241 |
|
|
for (i = 0; i < 65536; i++) {
|
3242 |
|
|
c.push( String.fromCharCode(i) );
|
3243 |
|
|
}
|
3244 |
|
|
escapable.lastIndex = 0;
|
3245 |
|
|
c.join('').replace(escapable, function(a) {
|
3246 |
|
|
unrolled[ a ] = '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
3247 |
|
|
return '';
|
3248 |
|
|
});
|
3249 |
|
|
escapable.lastIndex = 0;
|
3250 |
|
|
return unrolled;
|
3251 |
|
|
};
|
3252 |
|
|
|
3253 |
|
|
// Quote string, also taking care of unicode characters that browsers
|
3254 |
|
|
// often break. Especially, take care of unicode surrogates:
|
3255 |
|
|
// http://en.wikipedia.org/wiki/Mapping_of_Unicode_characters#Surrogates
|
3256 |
|
|
module.exports = {
|
3257 |
|
|
quote: function(string) {
|
3258 |
|
|
var quoted = JSON3.stringify(string);
|
3259 |
|
|
|
3260 |
|
|
// In most cases this should be very fast and good enough.
|
3261 |
|
|
extraEscapable.lastIndex = 0;
|
3262 |
|
|
if (!extraEscapable.test(quoted)) {
|
3263 |
|
|
return quoted;
|
3264 |
|
|
}
|
3265 |
|
|
|
3266 |
|
|
if (!extraLookup) {
|
3267 |
|
|
extraLookup = unrollLookup(extraEscapable);
|
3268 |
|
|
}
|
3269 |
|
|
|
3270 |
|
|
return quoted.replace(extraEscapable, function(a) {
|
3271 |
|
|
return extraLookup[a];
|
3272 |
|
|
});
|
3273 |
|
|
}
|
3274 |
|
|
};
|
3275 |
|
|
|
3276 |
|
|
},{"json3":58}],46:[function(require,module,exports){
|
3277 |
|
|
(function (global){
|
3278 |
|
|
'use strict';
|
3279 |
|
|
|
3280 |
|
|
var random = require('./random');
|
3281 |
|
|
|
3282 |
|
|
var onUnload = {}
|
3283 |
|
|
, afterUnload = false
|
3284 |
|
|
// detect google chrome packaged apps because they don't allow the 'unload' event
|
3285 |
|
|
, isChromePackagedApp = global.chrome && global.chrome.app && global.chrome.app.runtime
|
3286 |
|
|
;
|
3287 |
|
|
|
3288 |
|
|
module.exports = {
|
3289 |
|
|
attachEvent: function(event, listener) {
|
3290 |
|
|
if (typeof global.addEventListener !== 'undefined') {
|
3291 |
|
|
global.addEventListener(event, listener, false);
|
3292 |
|
|
} else if (global.document && global.attachEvent) {
|
3293 |
|
|
// IE quirks.
|
3294 |
|
|
// According to: http://stevesouders.com/misc/test-postmessage.php
|
3295 |
|
|
// the message gets delivered only to 'document', not 'window'.
|
3296 |
|
|
global.document.attachEvent('on' + event, listener);
|
3297 |
|
|
// I get 'window' for ie8.
|
3298 |
|
|
global.attachEvent('on' + event, listener);
|
3299 |
|
|
}
|
3300 |
|
|
}
|
3301 |
|
|
|
3302 |
|
|
, detachEvent: function(event, listener) {
|
3303 |
|
|
if (typeof global.addEventListener !== 'undefined') {
|
3304 |
|
|
global.removeEventListener(event, listener, false);
|
3305 |
|
|
} else if (global.document && global.detachEvent) {
|
3306 |
|
|
global.document.detachEvent('on' + event, listener);
|
3307 |
|
|
global.detachEvent('on' + event, listener);
|
3308 |
|
|
}
|
3309 |
|
|
}
|
3310 |
|
|
|
3311 |
|
|
, unloadAdd: function(listener) {
|
3312 |
|
|
if (isChromePackagedApp) {
|
3313 |
|
|
return null;
|
3314 |
|
|
}
|
3315 |
|
|
|
3316 |
|
|
var ref = random.string(8);
|
3317 |
|
|
onUnload[ref] = listener;
|
3318 |
|
|
if (afterUnload) {
|
3319 |
|
|
setTimeout(this.triggerUnloadCallbacks, 0);
|
3320 |
|
|
}
|
3321 |
|
|
return ref;
|
3322 |
|
|
}
|
3323 |
|
|
|
3324 |
|
|
, unloadDel: function(ref) {
|
3325 |
|
|
if (ref in onUnload) {
|
3326 |
|
|
delete onUnload[ref];
|
3327 |
|
|
}
|
3328 |
|
|
}
|
3329 |
|
|
|
3330 |
|
|
, triggerUnloadCallbacks: function() {
|
3331 |
|
|
for (var ref in onUnload) {
|
3332 |
|
|
onUnload[ref]();
|
3333 |
|
|
delete onUnload[ref];
|
3334 |
|
|
}
|
3335 |
|
|
}
|
3336 |
|
|
};
|
3337 |
|
|
|
3338 |
|
|
var unloadTriggered = function() {
|
3339 |
|
|
if (afterUnload) {
|
3340 |
|
|
return;
|
3341 |
|
|
}
|
3342 |
|
|
afterUnload = true;
|
3343 |
|
|
module.exports.triggerUnloadCallbacks();
|
3344 |
|
|
};
|
3345 |
|
|
|
3346 |
|
|
// 'unload' alone is not reliable in opera within an iframe, but we
|
3347 |
|
|
// can't use `beforeunload` as IE fires it on javascript: links.
|
3348 |
|
|
if (!isChromePackagedApp) {
|
3349 |
|
|
module.exports.attachEvent('unload', unloadTriggered);
|
3350 |
|
|
}
|
3351 |
|
|
|
3352 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3353 |
|
|
|
3354 |
|
|
},{"./random":50}],47:[function(require,module,exports){
|
3355 |
|
|
(function (process,global){
|
3356 |
|
|
'use strict';
|
3357 |
|
|
|
3358 |
|
|
var eventUtils = require('./event')
|
3359 |
|
|
, JSON3 = require('json3')
|
3360 |
|
|
, browser = require('./browser')
|
3361 |
|
|
;
|
3362 |
|
|
|
3363 |
|
|
var debug = function() {};
|
3364 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
3365 |
|
|
debug = require('debug')('sockjs-client:utils:iframe');
|
3366 |
|
|
}
|
3367 |
|
|
|
3368 |
|
|
module.exports = {
|
3369 |
|
|
WPrefix: '_jp'
|
3370 |
|
|
, currentWindowId: null
|
3371 |
|
|
|
3372 |
|
|
, polluteGlobalNamespace: function() {
|
3373 |
|
|
if (!(module.exports.WPrefix in global)) {
|
3374 |
|
|
global[module.exports.WPrefix] = {};
|
3375 |
|
|
}
|
3376 |
|
|
}
|
3377 |
|
|
|
3378 |
|
|
, postMessage: function(type, data) {
|
3379 |
|
|
if (global.parent !== global) {
|
3380 |
|
|
global.parent.postMessage(JSON3.stringify({
|
3381 |
|
|
windowId: module.exports.currentWindowId
|
3382 |
|
|
, type: type
|
3383 |
|
|
, data: data || ''
|
3384 |
|
|
}), '*');
|
3385 |
|
|
} else {
|
3386 |
|
|
debug('Cannot postMessage, no parent window.', type, data);
|
3387 |
|
|
}
|
3388 |
|
|
}
|
3389 |
|
|
|
3390 |
|
|
, createIframe: function(iframeUrl, errorCallback) {
|
3391 |
|
|
var iframe = global.document.createElement('iframe');
|
3392 |
|
|
var tref, unloadRef;
|
3393 |
|
|
var unattach = function() {
|
3394 |
|
|
debug('unattach');
|
3395 |
|
|
clearTimeout(tref);
|
3396 |
|
|
// Explorer had problems with that.
|
3397 |
|
|
try {
|
3398 |
|
|
iframe.onload = null;
|
3399 |
|
|
} catch (x) {
|
3400 |
|
|
// intentionally empty
|
3401 |
|
|
}
|
3402 |
|
|
iframe.onerror = null;
|
3403 |
|
|
};
|
3404 |
|
|
var cleanup = function() {
|
3405 |
|
|
debug('cleanup');
|
3406 |
|
|
if (iframe) {
|
3407 |
|
|
unattach();
|
3408 |
|
|
// This timeout makes chrome fire onbeforeunload event
|
3409 |
|
|
// within iframe. Without the timeout it goes straight to
|
3410 |
|
|
// onunload.
|
3411 |
|
|
setTimeout(function() {
|
3412 |
|
|
if (iframe) {
|
3413 |
|
|
iframe.parentNode.removeChild(iframe);
|
3414 |
|
|
}
|
3415 |
|
|
iframe = null;
|
3416 |
|
|
}, 0);
|
3417 |
|
|
eventUtils.unloadDel(unloadRef);
|
3418 |
|
|
}
|
3419 |
|
|
};
|
3420 |
|
|
var onerror = function(err) {
|
3421 |
|
|
debug('onerror', err);
|
3422 |
|
|
if (iframe) {
|
3423 |
|
|
cleanup();
|
3424 |
|
|
errorCallback(err);
|
3425 |
|
|
}
|
3426 |
|
|
};
|
3427 |
|
|
var post = function(msg, origin) {
|
3428 |
|
|
debug('post', msg, origin);
|
3429 |
|
|
setTimeout(function() {
|
3430 |
|
|
try {
|
3431 |
|
|
// When the iframe is not loaded, IE raises an exception
|
3432 |
|
|
// on 'contentWindow'.
|
3433 |
|
|
if (iframe && iframe.contentWindow) {
|
3434 |
|
|
iframe.contentWindow.postMessage(msg, origin);
|
3435 |
|
|
}
|
3436 |
|
|
} catch (x) {
|
3437 |
|
|
// intentionally empty
|
3438 |
|
|
}
|
3439 |
|
|
}, 0);
|
3440 |
|
|
};
|
3441 |
|
|
|
3442 |
|
|
iframe.src = iframeUrl;
|
3443 |
|
|
iframe.style.display = 'none';
|
3444 |
|
|
iframe.style.position = 'absolute';
|
3445 |
|
|
iframe.onerror = function() {
|
3446 |
|
|
onerror('onerror');
|
3447 |
|
|
};
|
3448 |
|
|
iframe.onload = function() {
|
3449 |
|
|
debug('onload');
|
3450 |
|
|
// `onload` is triggered before scripts on the iframe are
|
3451 |
|
|
// executed. Give it few seconds to actually load stuff.
|
3452 |
|
|
clearTimeout(tref);
|
3453 |
|
|
tref = setTimeout(function() {
|
3454 |
|
|
onerror('onload timeout');
|
3455 |
|
|
}, 2000);
|
3456 |
|
|
};
|
3457 |
|
|
global.document.body.appendChild(iframe);
|
3458 |
|
|
tref = setTimeout(function() {
|
3459 |
|
|
onerror('timeout');
|
3460 |
|
|
}, 15000);
|
3461 |
|
|
unloadRef = eventUtils.unloadAdd(cleanup);
|
3462 |
|
|
return {
|
3463 |
|
|
post: post
|
3464 |
|
|
, cleanup: cleanup
|
3465 |
|
|
, loaded: unattach
|
3466 |
|
|
};
|
3467 |
|
|
}
|
3468 |
|
|
|
3469 |
|
|
/* eslint no-undef: "off", new-cap: "off" */
|
3470 |
|
|
, createHtmlfile: function(iframeUrl, errorCallback) {
|
3471 |
|
|
var axo = ['Active'].concat('Object').join('X');
|
3472 |
|
|
var doc = new global[axo]('htmlfile');
|
3473 |
|
|
var tref, unloadRef;
|
3474 |
|
|
var iframe;
|
3475 |
|
|
var unattach = function() {
|
3476 |
|
|
clearTimeout(tref);
|
3477 |
|
|
iframe.onerror = null;
|
3478 |
|
|
};
|
3479 |
|
|
var cleanup = function() {
|
3480 |
|
|
if (doc) {
|
3481 |
|
|
unattach();
|
3482 |
|
|
eventUtils.unloadDel(unloadRef);
|
3483 |
|
|
iframe.parentNode.removeChild(iframe);
|
3484 |
|
|
iframe = doc = null;
|
3485 |
|
|
CollectGarbage();
|
3486 |
|
|
}
|
3487 |
|
|
};
|
3488 |
|
|
var onerror = function(r) {
|
3489 |
|
|
debug('onerror', r);
|
3490 |
|
|
if (doc) {
|
3491 |
|
|
cleanup();
|
3492 |
|
|
errorCallback(r);
|
3493 |
|
|
}
|
3494 |
|
|
};
|
3495 |
|
|
var post = function(msg, origin) {
|
3496 |
|
|
try {
|
3497 |
|
|
// When the iframe is not loaded, IE raises an exception
|
3498 |
|
|
// on 'contentWindow'.
|
3499 |
|
|
setTimeout(function() {
|
3500 |
|
|
if (iframe && iframe.contentWindow) {
|
3501 |
|
|
iframe.contentWindow.postMessage(msg, origin);
|
3502 |
|
|
}
|
3503 |
|
|
}, 0);
|
3504 |
|
|
} catch (x) {
|
3505 |
|
|
// intentionally empty
|
3506 |
|
|
}
|
3507 |
|
|
};
|
3508 |
|
|
|
3509 |
|
|
doc.open();
|
3510 |
|
|
doc.write('<html><s' + 'cript>' +
|
3511 |
|
|
'document.domain="' + global.document.domain + '";' +
|
3512 |
|
|
'</s' + 'cript></html>');
|
3513 |
|
|
doc.close();
|
3514 |
|
|
doc.parentWindow[module.exports.WPrefix] = global[module.exports.WPrefix];
|
3515 |
|
|
var c = doc.createElement('div');
|
3516 |
|
|
doc.body.appendChild(c);
|
3517 |
|
|
iframe = doc.createElement('iframe');
|
3518 |
|
|
c.appendChild(iframe);
|
3519 |
|
|
iframe.src = iframeUrl;
|
3520 |
|
|
iframe.onerror = function() {
|
3521 |
|
|
onerror('onerror');
|
3522 |
|
|
};
|
3523 |
|
|
tref = setTimeout(function() {
|
3524 |
|
|
onerror('timeout');
|
3525 |
|
|
}, 15000);
|
3526 |
|
|
unloadRef = eventUtils.unloadAdd(cleanup);
|
3527 |
|
|
return {
|
3528 |
|
|
post: post
|
3529 |
|
|
, cleanup: cleanup
|
3530 |
|
|
, loaded: unattach
|
3531 |
|
|
};
|
3532 |
|
|
}
|
3533 |
|
|
};
|
3534 |
|
|
|
3535 |
|
|
module.exports.iframeEnabled = false;
|
3536 |
|
|
if (global.document) {
|
3537 |
|
|
// postMessage misbehaves in konqueror 4.6.5 - the messages are delivered with
|
3538 |
|
|
// huge delay, or not at all.
|
3539 |
|
|
module.exports.iframeEnabled = (typeof global.postMessage === 'function' ||
|
3540 |
|
|
typeof global.postMessage === 'object') && (!browser.isKonqueror());
|
3541 |
|
|
}
|
3542 |
|
|
|
3543 |
|
|
}).call(this,{ env: {} },typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3544 |
|
|
|
3545 |
|
|
},{"./browser":44,"./event":46,"debug":55,"json3":58}],48:[function(require,module,exports){
|
3546 |
|
|
(function (global){
|
3547 |
|
|
'use strict';
|
3548 |
|
|
|
3549 |
|
|
var logObject = {};
|
3550 |
|
|
['log', 'debug', 'warn'].forEach(function (level) {
|
3551 |
|
|
var levelExists;
|
3552 |
|
|
|
3553 |
|
|
try {
|
3554 |
|
|
levelExists = global.console && global.console[level] && global.console[level].apply;
|
3555 |
|
|
} catch(e) {
|
3556 |
|
|
// do nothing
|
3557 |
|
|
}
|
3558 |
|
|
|
3559 |
|
|
logObject[level] = levelExists ? function () {
|
3560 |
|
|
return global.console[level].apply(global.console, arguments);
|
3561 |
|
|
} : (level === 'log' ? function () {} : logObject.log);
|
3562 |
|
|
});
|
3563 |
|
|
|
3564 |
|
|
module.exports = logObject;
|
3565 |
|
|
|
3566 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
3567 |
|
|
|
3568 |
|
|
},{}],49:[function(require,module,exports){
|
3569 |
|
|
'use strict';
|
3570 |
|
|
|
3571 |
|
|
module.exports = {
|
3572 |
|
|
isObject: function(obj) {
|
3573 |
|
|
var type = typeof obj;
|
3574 |
|
|
return type === 'function' || type === 'object' && !!obj;
|
3575 |
|
|
}
|
3576 |
|
|
|
3577 |
|
|
, extend: function(obj) {
|
3578 |
|
|
if (!this.isObject(obj)) {
|
3579 |
|
|
return obj;
|
3580 |
|
|
}
|
3581 |
|
|
var source, prop;
|
3582 |
|
|
for (var i = 1, length = arguments.length; i < length; i++) {
|
3583 |
|
|
source = arguments[i];
|
3584 |
|
|
for (prop in source) {
|
3585 |
|
|
if (Object.prototype.hasOwnProperty.call(source, prop)) {
|
3586 |
|
|
obj[prop] = source[prop];
|
3587 |
|
|
}
|
3588 |
|
|
}
|
3589 |
|
|
}
|
3590 |
|
|
return obj;
|
3591 |
|
|
}
|
3592 |
|
|
};
|
3593 |
|
|
|
3594 |
|
|
},{}],50:[function(require,module,exports){
|
3595 |
|
|
'use strict';
|
3596 |
|
|
|
3597 |
|
|
/* global crypto:true */
|
3598 |
|
|
var crypto = require('crypto');
|
3599 |
|
|
|
3600 |
|
|
// This string has length 32, a power of 2, so the modulus doesn't introduce a
|
3601 |
|
|
// bias.
|
3602 |
|
|
var _randomStringChars = 'abcdefghijklmnopqrstuvwxyz012345';
|
3603 |
|
|
module.exports = {
|
3604 |
|
|
string: function(length) {
|
3605 |
|
|
var max = _randomStringChars.length;
|
3606 |
|
|
var bytes = crypto.randomBytes(length);
|
3607 |
|
|
var ret = [];
|
3608 |
|
|
for (var i = 0; i < length; i++) {
|
3609 |
|
|
ret.push(_randomStringChars.substr(bytes[i] % max, 1));
|
3610 |
|
|
}
|
3611 |
|
|
return ret.join('');
|
3612 |
|
|
}
|
3613 |
|
|
|
3614 |
|
|
, number: function(max) {
|
3615 |
|
|
return Math.floor(Math.random() * max);
|
3616 |
|
|
}
|
3617 |
|
|
|
3618 |
|
|
, numberString: function(max) {
|
3619 |
|
|
var t = ('' + (max - 1)).length;
|
3620 |
|
|
var p = new Array(t + 1).join('0');
|
3621 |
|
|
return (p + this.number(max)).slice(-t);
|
3622 |
|
|
}
|
3623 |
|
|
};
|
3624 |
|
|
|
3625 |
|
|
},{"crypto":43}],51:[function(require,module,exports){
|
3626 |
|
|
(function (process){
|
3627 |
|
|
'use strict';
|
3628 |
|
|
|
3629 |
|
|
var debug = function() {};
|
3630 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
3631 |
|
|
debug = require('debug')('sockjs-client:utils:transport');
|
3632 |
|
|
}
|
3633 |
|
|
|
3634 |
|
|
module.exports = function(availableTransports) {
|
3635 |
|
|
return {
|
3636 |
|
|
filterToEnabled: function(transportsWhitelist, info) {
|
3637 |
|
|
var transports = {
|
3638 |
|
|
main: []
|
3639 |
|
|
, facade: []
|
3640 |
|
|
};
|
3641 |
|
|
if (!transportsWhitelist) {
|
3642 |
|
|
transportsWhitelist = [];
|
3643 |
|
|
} else if (typeof transportsWhitelist === 'string') {
|
3644 |
|
|
transportsWhitelist = [transportsWhitelist];
|
3645 |
|
|
}
|
3646 |
|
|
|
3647 |
|
|
availableTransports.forEach(function(trans) {
|
3648 |
|
|
if (!trans) {
|
3649 |
|
|
return;
|
3650 |
|
|
}
|
3651 |
|
|
|
3652 |
|
|
if (trans.transportName === 'websocket' && info.websocket === false) {
|
3653 |
|
|
debug('disabled from server', 'websocket');
|
3654 |
|
|
return;
|
3655 |
|
|
}
|
3656 |
|
|
|
3657 |
|
|
if (transportsWhitelist.length &&
|
3658 |
|
|
transportsWhitelist.indexOf(trans.transportName) === -1) {
|
3659 |
|
|
debug('not in whitelist', trans.transportName);
|
3660 |
|
|
return;
|
3661 |
|
|
}
|
3662 |
|
|
|
3663 |
|
|
if (trans.enabled(info)) {
|
3664 |
|
|
debug('enabled', trans.transportName);
|
3665 |
|
|
transports.main.push(trans);
|
3666 |
|
|
if (trans.facadeTransport) {
|
3667 |
|
|
transports.facade.push(trans.facadeTransport);
|
3668 |
|
|
}
|
3669 |
|
|
} else {
|
3670 |
|
|
debug('disabled', trans.transportName);
|
3671 |
|
|
}
|
3672 |
|
|
});
|
3673 |
|
|
return transports;
|
3674 |
|
|
}
|
3675 |
|
|
};
|
3676 |
|
|
};
|
3677 |
|
|
|
3678 |
|
|
}).call(this,{ env: {} })
|
3679 |
|
|
|
3680 |
|
|
},{"debug":55}],52:[function(require,module,exports){
|
3681 |
|
|
(function (process){
|
3682 |
|
|
'use strict';
|
3683 |
|
|
|
3684 |
|
|
var URL = require('url-parse');
|
3685 |
|
|
|
3686 |
|
|
var debug = function() {};
|
3687 |
|
|
if (process.env.NODE_ENV !== 'production') {
|
3688 |
|
|
debug = require('debug')('sockjs-client:utils:url');
|
3689 |
|
|
}
|
3690 |
|
|
|
3691 |
|
|
module.exports = {
|
3692 |
|
|
getOrigin: function(url) {
|
3693 |
|
|
if (!url) {
|
3694 |
|
|
return null;
|
3695 |
|
|
}
|
3696 |
|
|
|
3697 |
|
|
var p = new URL(url);
|
3698 |
|
|
if (p.protocol === 'file:') {
|
3699 |
|
|
return null;
|
3700 |
|
|
}
|
3701 |
|
|
|
3702 |
|
|
var port = p.port;
|
3703 |
|
|
if (!port) {
|
3704 |
|
|
port = (p.protocol === 'https:') ? '443' : '80';
|
3705 |
|
|
}
|
3706 |
|
|
|
3707 |
|
|
return p.protocol + '//' + p.hostname + ':' + port;
|
3708 |
|
|
}
|
3709 |
|
|
|
3710 |
|
|
, isOriginEqual: function(a, b) {
|
3711 |
|
|
var res = this.getOrigin(a) === this.getOrigin(b);
|
3712 |
|
|
debug('same', a, b, res);
|
3713 |
|
|
return res;
|
3714 |
|
|
}
|
3715 |
|
|
|
3716 |
|
|
, isSchemeEqual: function(a, b) {
|
3717 |
|
|
return (a.split(':')[0] === b.split(':')[0]);
|
3718 |
|
|
}
|
3719 |
|
|
|
3720 |
|
|
, addPath: function (url, path) {
|
3721 |
|
|
var qs = url.split('?');
|
3722 |
|
|
return qs[0] + path + (qs[1] ? '?' + qs[1] : '');
|
3723 |
|
|
}
|
3724 |
|
|
|
3725 |
|
|
, addQuery: function (url, q) {
|
3726 |
|
|
return url + (url.indexOf('?') === -1 ? ('?' + q) : ('&' + q));
|
3727 |
|
|
}
|
3728 |
|
|
};
|
3729 |
|
|
|
3730 |
|
|
}).call(this,{ env: {} })
|
3731 |
|
|
|
3732 |
|
|
},{"debug":55,"url-parse":61}],53:[function(require,module,exports){
|
3733 |
|
|
module.exports = '1.4.0';
|
3734 |
|
|
|
3735 |
|
|
},{}],54:[function(require,module,exports){
|
3736 |
|
|
/**
|
3737 |
|
|
* Helpers.
|
3738 |
|
|
*/
|
3739 |
|
|
|
3740 |
|
|
var s = 1000;
|
3741 |
|
|
var m = s * 60;
|
3742 |
|
|
var h = m * 60;
|
3743 |
|
|
var d = h * 24;
|
3744 |
|
|
var w = d * 7;
|
3745 |
|
|
var y = d * 365.25;
|
3746 |
|
|
|
3747 |
|
|
/**
|
3748 |
|
|
* Parse or format the given `val`.
|
3749 |
|
|
*
|
3750 |
|
|
* Options:
|
3751 |
|
|
*
|
3752 |
|
|
* - `long` verbose formatting [false]
|
3753 |
|
|
*
|
3754 |
|
|
* @param {String|Number} val
|
3755 |
|
|
* @param {Object} [options]
|
3756 |
|
|
* @throws {Error} throw an error if val is not a non-empty string or a number
|
3757 |
|
|
* @return {String|Number}
|
3758 |
|
|
* @api public
|
3759 |
|
|
*/
|
3760 |
|
|
|
3761 |
|
|
module.exports = function(val, options) {
|
3762 |
|
|
options = options || {};
|
3763 |
|
|
var type = typeof val;
|
3764 |
|
|
if (type === 'string' && val.length > 0) {
|
3765 |
|
|
return parse(val);
|
3766 |
|
|
} else if (type === 'number' && isNaN(val) === false) {
|
3767 |
|
|
return options.long ? fmtLong(val) : fmtShort(val);
|
3768 |
|
|
}
|
3769 |
|
|
throw new Error(
|
3770 |
|
|
'val is not a non-empty string or a valid number. val=' +
|
3771 |
|
|
JSON.stringify(val)
|
3772 |
|
|
);
|
3773 |
|
|
};
|
3774 |
|
|
|
3775 |
|
|
/**
|
3776 |
|
|
* Parse the given `str` and return milliseconds.
|
3777 |
|
|
*
|
3778 |
|
|
* @param {String} str
|
3779 |
|
|
* @return {Number}
|
3780 |
|
|
* @api private
|
3781 |
|
|
*/
|
3782 |
|
|
|
3783 |
|
|
function parse(str) {
|
3784 |
|
|
str = String(str);
|
3785 |
|
|
if (str.length > 100) {
|
3786 |
|
|
return;
|
3787 |
|
|
}
|
3788 |
|
|
var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
3789 |
|
|
str
|
3790 |
|
|
);
|
3791 |
|
|
if (!match) {
|
3792 |
|
|
return;
|
3793 |
|
|
}
|
3794 |
|
|
var n = parseFloat(match[1]);
|
3795 |
|
|
var type = (match[2] || 'ms').toLowerCase();
|
3796 |
|
|
switch (type) {
|
3797 |
|
|
case 'years':
|
3798 |
|
|
case 'year':
|
3799 |
|
|
case 'yrs':
|
3800 |
|
|
case 'yr':
|
3801 |
|
|
case 'y':
|
3802 |
|
|
return n * y;
|
3803 |
|
|
case 'weeks':
|
3804 |
|
|
case 'week':
|
3805 |
|
|
case 'w':
|
3806 |
|
|
return n * w;
|
3807 |
|
|
case 'days':
|
3808 |
|
|
case 'day':
|
3809 |
|
|
case 'd':
|
3810 |
|
|
return n * d;
|
3811 |
|
|
case 'hours':
|
3812 |
|
|
case 'hour':
|
3813 |
|
|
case 'hrs':
|
3814 |
|
|
case 'hr':
|
3815 |
|
|
case 'h':
|
3816 |
|
|
return n * h;
|
3817 |
|
|
case 'minutes':
|
3818 |
|
|
case 'minute':
|
3819 |
|
|
case 'mins':
|
3820 |
|
|
case 'min':
|
3821 |
|
|
case 'm':
|
3822 |
|
|
return n * m;
|
3823 |
|
|
case 'seconds':
|
3824 |
|
|
case 'second':
|
3825 |
|
|
case 'secs':
|
3826 |
|
|
case 'sec':
|
3827 |
|
|
case 's':
|
3828 |
|
|
return n * s;
|
3829 |
|
|
case 'milliseconds':
|
3830 |
|
|
case 'millisecond':
|
3831 |
|
|
case 'msecs':
|
3832 |
|
|
case 'msec':
|
3833 |
|
|
case 'ms':
|
3834 |
|
|
return n;
|
3835 |
|
|
default:
|
3836 |
|
|
return undefined;
|
3837 |
|
|
}
|
3838 |
|
|
}
|
3839 |
|
|
|
3840 |
|
|
/**
|
3841 |
|
|
* Short format for `ms`.
|
3842 |
|
|
*
|
3843 |
|
|
* @param {Number} ms
|
3844 |
|
|
* @return {String}
|
3845 |
|
|
* @api private
|
3846 |
|
|
*/
|
3847 |
|
|
|
3848 |
|
|
function fmtShort(ms) {
|
3849 |
|
|
var msAbs = Math.abs(ms);
|
3850 |
|
|
if (msAbs >= d) {
|
3851 |
|
|
return Math.round(ms / d) + 'd';
|
3852 |
|
|
}
|
3853 |
|
|
if (msAbs >= h) {
|
3854 |
|
|
return Math.round(ms / h) + 'h';
|
3855 |
|
|
}
|
3856 |
|
|
if (msAbs >= m) {
|
3857 |
|
|
return Math.round(ms / m) + 'm';
|
3858 |
|
|
}
|
3859 |
|
|
if (msAbs >= s) {
|
3860 |
|
|
return Math.round(ms / s) + 's';
|
3861 |
|
|
}
|
3862 |
|
|
return ms + 'ms';
|
3863 |
|
|
}
|
3864 |
|
|
|
3865 |
|
|
/**
|
3866 |
|
|
* Long format for `ms`.
|
3867 |
|
|
*
|
3868 |
|
|
* @param {Number} ms
|
3869 |
|
|
* @return {String}
|
3870 |
|
|
* @api private
|
3871 |
|
|
*/
|
3872 |
|
|
|
3873 |
|
|
function fmtLong(ms) {
|
3874 |
|
|
var msAbs = Math.abs(ms);
|
3875 |
|
|
if (msAbs >= d) {
|
3876 |
|
|
return plural(ms, msAbs, d, 'day');
|
3877 |
|
|
}
|
3878 |
|
|
if (msAbs >= h) {
|
3879 |
|
|
return plural(ms, msAbs, h, 'hour');
|
3880 |
|
|
}
|
3881 |
|
|
if (msAbs >= m) {
|
3882 |
|
|
return plural(ms, msAbs, m, 'minute');
|
3883 |
|
|
}
|
3884 |
|
|
if (msAbs >= s) {
|
3885 |
|
|
return plural(ms, msAbs, s, 'second');
|
3886 |
|
|
}
|
3887 |
|
|
return ms + ' ms';
|
3888 |
|
|
}
|
3889 |
|
|
|
3890 |
|
|
/**
|
3891 |
|
|
* Pluralization helper.
|
3892 |
|
|
*/
|
3893 |
|
|
|
3894 |
|
|
function plural(ms, msAbs, n, name) {
|
3895 |
|
|
var isPlural = msAbs >= n * 1.5;
|
3896 |
|
|
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
3897 |
|
|
}
|
3898 |
|
|
|
3899 |
|
|
},{}],55:[function(require,module,exports){
|
3900 |
|
|
(function (process){
|
3901 |
|
|
"use strict";
|
3902 |
|
|
|
3903 |
|
|
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
3904 |
|
|
|
3905 |
|
|
/* eslint-env browser */
|
3906 |
|
|
|
3907 |
|
|
/**
|
3908 |
|
|
* This is the web browser implementation of `debug()`.
|
3909 |
|
|
*/
|
3910 |
|
|
exports.log = log;
|
3911 |
|
|
exports.formatArgs = formatArgs;
|
3912 |
|
|
exports.save = save;
|
3913 |
|
|
exports.load = load;
|
3914 |
|
|
exports.useColors = useColors;
|
3915 |
|
|
exports.storage = localstorage();
|
3916 |
|
|
/**
|
3917 |
|
|
* Colors.
|
3918 |
|
|
*/
|
3919 |
|
|
|
3920 |
|
|
exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
|
3921 |
|
|
/**
|
3922 |
|
|
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
3923 |
|
|
* and the Firebug extension (any Firefox version) are known
|
3924 |
|
|
* to support "%c" CSS customizations.
|
3925 |
|
|
*
|
3926 |
|
|
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
3927 |
|
|
*/
|
3928 |
|
|
// eslint-disable-next-line complexity
|
3929 |
|
|
|
3930 |
|
|
function useColors() {
|
3931 |
|
|
// NB: In an Electron preload script, document will be defined but not fully
|
3932 |
|
|
// initialized. Since we know we're in Chrome, we'll just detect this case
|
3933 |
|
|
// explicitly
|
3934 |
|
|
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
3935 |
|
|
return true;
|
3936 |
|
|
} // Internet Explorer and Edge do not support colors.
|
3937 |
|
|
|
3938 |
|
|
|
3939 |
|
|
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
3940 |
|
|
return false;
|
3941 |
|
|
} // Is webkit? http://stackoverflow.com/a/16459606/376773
|
3942 |
|
|
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
3943 |
|
|
|
3944 |
|
|
|
3945 |
|
|
return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773
|
3946 |
|
|
typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31?
|
3947 |
|
|
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
3948 |
|
|
typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker
|
3949 |
|
|
typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
3950 |
|
|
}
|
3951 |
|
|
/**
|
3952 |
|
|
* Colorize log arguments if enabled.
|
3953 |
|
|
*
|
3954 |
|
|
* @api public
|
3955 |
|
|
*/
|
3956 |
|
|
|
3957 |
|
|
|
3958 |
|
|
function formatArgs(args) {
|
3959 |
|
|
args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
|
3960 |
|
|
|
3961 |
|
|
if (!this.useColors) {
|
3962 |
|
|
return;
|
3963 |
|
|
}
|
3964 |
|
|
|
3965 |
|
|
var c = 'color: ' + this.color;
|
3966 |
|
|
args.splice(1, 0, c, 'color: inherit'); // The final "%c" is somewhat tricky, because there could be other
|
3967 |
|
|
// arguments passed either before or after the %c, so we need to
|
3968 |
|
|
// figure out the correct index to insert the CSS into
|
3969 |
|
|
|
3970 |
|
|
var index = 0;
|
3971 |
|
|
var lastC = 0;
|
3972 |
|
|
args[0].replace(/%[a-zA-Z%]/g, function (match) {
|
3973 |
|
|
if (match === '%%') {
|
3974 |
|
|
return;
|
3975 |
|
|
}
|
3976 |
|
|
|
3977 |
|
|
index++;
|
3978 |
|
|
|
3979 |
|
|
if (match === '%c') {
|
3980 |
|
|
// We only are interested in the *last* %c
|
3981 |
|
|
// (the user may have provided their own)
|
3982 |
|
|
lastC = index;
|
3983 |
|
|
}
|
3984 |
|
|
});
|
3985 |
|
|
args.splice(lastC, 0, c);
|
3986 |
|
|
}
|
3987 |
|
|
/**
|
3988 |
|
|
* Invokes `console.log()` when available.
|
3989 |
|
|
* No-op when `console.log` is not a "function".
|
3990 |
|
|
*
|
3991 |
|
|
* @api public
|
3992 |
|
|
*/
|
3993 |
|
|
|
3994 |
|
|
|
3995 |
|
|
function log() {
|
3996 |
|
|
var _console;
|
3997 |
|
|
|
3998 |
|
|
// This hackery is required for IE8/9, where
|
3999 |
|
|
// the `console.log` function doesn't have 'apply'
|
4000 |
|
|
return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
|
4001 |
|
|
}
|
4002 |
|
|
/**
|
4003 |
|
|
* Save `namespaces`.
|
4004 |
|
|
*
|
4005 |
|
|
* @param {String} namespaces
|
4006 |
|
|
* @api private
|
4007 |
|
|
*/
|
4008 |
|
|
|
4009 |
|
|
|
4010 |
|
|
function save(namespaces) {
|
4011 |
|
|
try {
|
4012 |
|
|
if (namespaces) {
|
4013 |
|
|
exports.storage.setItem('debug', namespaces);
|
4014 |
|
|
} else {
|
4015 |
|
|
exports.storage.removeItem('debug');
|
4016 |
|
|
}
|
4017 |
|
|
} catch (error) {// Swallow
|
4018 |
|
|
// XXX (@Qix-) should we be logging these?
|
4019 |
|
|
}
|
4020 |
|
|
}
|
4021 |
|
|
/**
|
4022 |
|
|
* Load `namespaces`.
|
4023 |
|
|
*
|
4024 |
|
|
* @return {String} returns the previously persisted debug modes
|
4025 |
|
|
* @api private
|
4026 |
|
|
*/
|
4027 |
|
|
|
4028 |
|
|
|
4029 |
|
|
function load() {
|
4030 |
|
|
var r;
|
4031 |
|
|
|
4032 |
|
|
try {
|
4033 |
|
|
r = exports.storage.getItem('debug');
|
4034 |
|
|
} catch (error) {} // Swallow
|
4035 |
|
|
// XXX (@Qix-) should we be logging these?
|
4036 |
|
|
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
4037 |
|
|
|
4038 |
|
|
|
4039 |
|
|
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
4040 |
|
|
r = process.env.DEBUG;
|
4041 |
|
|
}
|
4042 |
|
|
|
4043 |
|
|
return r;
|
4044 |
|
|
}
|
4045 |
|
|
/**
|
4046 |
|
|
* Localstorage attempts to return the localstorage.
|
4047 |
|
|
*
|
4048 |
|
|
* This is necessary because safari throws
|
4049 |
|
|
* when a user disables cookies/localstorage
|
4050 |
|
|
* and you attempt to access it.
|
4051 |
|
|
*
|
4052 |
|
|
* @return {LocalStorage}
|
4053 |
|
|
* @api private
|
4054 |
|
|
*/
|
4055 |
|
|
|
4056 |
|
|
|
4057 |
|
|
function localstorage() {
|
4058 |
|
|
try {
|
4059 |
|
|
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
4060 |
|
|
// The Browser also has localStorage in the global context.
|
4061 |
|
|
return localStorage;
|
4062 |
|
|
} catch (error) {// Swallow
|
4063 |
|
|
// XXX (@Qix-) should we be logging these?
|
4064 |
|
|
}
|
4065 |
|
|
}
|
4066 |
|
|
|
4067 |
|
|
module.exports = require('./common')(exports);
|
4068 |
|
|
var formatters = module.exports.formatters;
|
4069 |
|
|
/**
|
4070 |
|
|
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
4071 |
|
|
*/
|
4072 |
|
|
|
4073 |
|
|
formatters.j = function (v) {
|
4074 |
|
|
try {
|
4075 |
|
|
return JSON.stringify(v);
|
4076 |
|
|
} catch (error) {
|
4077 |
|
|
return '[UnexpectedJSONParseError]: ' + error.message;
|
4078 |
|
|
}
|
4079 |
|
|
};
|
4080 |
|
|
|
4081 |
|
|
|
4082 |
|
|
}).call(this,{ env: {} })
|
4083 |
|
|
|
4084 |
|
|
},{"./common":56}],56:[function(require,module,exports){
|
4085 |
|
|
"use strict";
|
4086 |
|
|
|
4087 |
|
|
/**
|
4088 |
|
|
* This is the common logic for both the Node.js and web browser
|
4089 |
|
|
* implementations of `debug()`.
|
4090 |
|
|
*/
|
4091 |
|
|
function setup(env) {
|
4092 |
|
|
createDebug.debug = createDebug;
|
4093 |
|
|
createDebug.default = createDebug;
|
4094 |
|
|
createDebug.coerce = coerce;
|
4095 |
|
|
createDebug.disable = disable;
|
4096 |
|
|
createDebug.enable = enable;
|
4097 |
|
|
createDebug.enabled = enabled;
|
4098 |
|
|
createDebug.humanize = require('ms');
|
4099 |
|
|
Object.keys(env).forEach(function (key) {
|
4100 |
|
|
createDebug[key] = env[key];
|
4101 |
|
|
});
|
4102 |
|
|
/**
|
4103 |
|
|
* Active `debug` instances.
|
4104 |
|
|
*/
|
4105 |
|
|
|
4106 |
|
|
createDebug.instances = [];
|
4107 |
|
|
/**
|
4108 |
|
|
* The currently active debug mode names, and names to skip.
|
4109 |
|
|
*/
|
4110 |
|
|
|
4111 |
|
|
createDebug.names = [];
|
4112 |
|
|
createDebug.skips = [];
|
4113 |
|
|
/**
|
4114 |
|
|
* Map of special "%n" handling functions, for the debug "format" argument.
|
4115 |
|
|
*
|
4116 |
|
|
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
4117 |
|
|
*/
|
4118 |
|
|
|
4119 |
|
|
createDebug.formatters = {};
|
4120 |
|
|
/**
|
4121 |
|
|
* Selects a color for a debug namespace
|
4122 |
|
|
* @param {String} namespace The namespace string for the for the debug instance to be colored
|
4123 |
|
|
* @return {Number|String} An ANSI color code for the given namespace
|
4124 |
|
|
* @api private
|
4125 |
|
|
*/
|
4126 |
|
|
|
4127 |
|
|
function selectColor(namespace) {
|
4128 |
|
|
var hash = 0;
|
4129 |
|
|
|
4130 |
|
|
for (var i = 0; i < namespace.length; i++) {
|
4131 |
|
|
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
4132 |
|
|
hash |= 0; // Convert to 32bit integer
|
4133 |
|
|
}
|
4134 |
|
|
|
4135 |
|
|
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
4136 |
|
|
}
|
4137 |
|
|
|
4138 |
|
|
createDebug.selectColor = selectColor;
|
4139 |
|
|
/**
|
4140 |
|
|
* Create a debugger with the given `namespace`.
|
4141 |
|
|
*
|
4142 |
|
|
* @param {String} namespace
|
4143 |
|
|
* @return {Function}
|
4144 |
|
|
* @api public
|
4145 |
|
|
*/
|
4146 |
|
|
|
4147 |
|
|
function createDebug(namespace) {
|
4148 |
|
|
var prevTime;
|
4149 |
|
|
|
4150 |
|
|
function debug() {
|
4151 |
|
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
4152 |
|
|
args[_key] = arguments[_key];
|
4153 |
|
|
}
|
4154 |
|
|
|
4155 |
|
|
// Disabled?
|
4156 |
|
|
if (!debug.enabled) {
|
4157 |
|
|
return;
|
4158 |
|
|
}
|
4159 |
|
|
|
4160 |
|
|
var self = debug; // Set `diff` timestamp
|
4161 |
|
|
|
4162 |
|
|
var curr = Number(new Date());
|
4163 |
|
|
var ms = curr - (prevTime || curr);
|
4164 |
|
|
self.diff = ms;
|
4165 |
|
|
self.prev = prevTime;
|
4166 |
|
|
self.curr = curr;
|
4167 |
|
|
prevTime = curr;
|
4168 |
|
|
args[0] = createDebug.coerce(args[0]);
|
4169 |
|
|
|
4170 |
|
|
if (typeof args[0] !== 'string') {
|
4171 |
|
|
// Anything else let's inspect with %O
|
4172 |
|
|
args.unshift('%O');
|
4173 |
|
|
} // Apply any `formatters` transformations
|
4174 |
|
|
|
4175 |
|
|
|
4176 |
|
|
var index = 0;
|
4177 |
|
|
args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
|
4178 |
|
|
// If we encounter an escaped % then don't increase the array index
|
4179 |
|
|
if (match === '%%') {
|
4180 |
|
|
return match;
|
4181 |
|
|
}
|
4182 |
|
|
|
4183 |
|
|
index++;
|
4184 |
|
|
var formatter = createDebug.formatters[format];
|
4185 |
|
|
|
4186 |
|
|
if (typeof formatter === 'function') {
|
4187 |
|
|
var val = args[index];
|
4188 |
|
|
match = formatter.call(self, val); // Now we need to remove `args[index]` since it's inlined in the `format`
|
4189 |
|
|
|
4190 |
|
|
args.splice(index, 1);
|
4191 |
|
|
index--;
|
4192 |
|
|
}
|
4193 |
|
|
|
4194 |
|
|
return match;
|
4195 |
|
|
}); // Apply env-specific formatting (colors, etc.)
|
4196 |
|
|
|
4197 |
|
|
createDebug.formatArgs.call(self, args);
|
4198 |
|
|
var logFn = self.log || createDebug.log;
|
4199 |
|
|
logFn.apply(self, args);
|
4200 |
|
|
}
|
4201 |
|
|
|
4202 |
|
|
debug.namespace = namespace;
|
4203 |
|
|
debug.enabled = createDebug.enabled(namespace);
|
4204 |
|
|
debug.useColors = createDebug.useColors();
|
4205 |
|
|
debug.color = selectColor(namespace);
|
4206 |
|
|
debug.destroy = destroy;
|
4207 |
|
|
debug.extend = extend; // Debug.formatArgs = formatArgs;
|
4208 |
|
|
// debug.rawLog = rawLog;
|
4209 |
|
|
// env-specific initialization logic for debug instances
|
4210 |
|
|
|
4211 |
|
|
if (typeof createDebug.init === 'function') {
|
4212 |
|
|
createDebug.init(debug);
|
4213 |
|
|
}
|
4214 |
|
|
|
4215 |
|
|
createDebug.instances.push(debug);
|
4216 |
|
|
return debug;
|
4217 |
|
|
}
|
4218 |
|
|
|
4219 |
|
|
function destroy() {
|
4220 |
|
|
var index = createDebug.instances.indexOf(this);
|
4221 |
|
|
|
4222 |
|
|
if (index !== -1) {
|
4223 |
|
|
createDebug.instances.splice(index, 1);
|
4224 |
|
|
return true;
|
4225 |
|
|
}
|
4226 |
|
|
|
4227 |
|
|
return false;
|
4228 |
|
|
}
|
4229 |
|
|
|
4230 |
|
|
function extend(namespace, delimiter) {
|
4231 |
|
|
return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
4232 |
|
|
}
|
4233 |
|
|
/**
|
4234 |
|
|
* Enables a debug mode by namespaces. This can include modes
|
4235 |
|
|
* separated by a colon and wildcards.
|
4236 |
|
|
*
|
4237 |
|
|
* @param {String} namespaces
|
4238 |
|
|
* @api public
|
4239 |
|
|
*/
|
4240 |
|
|
|
4241 |
|
|
|
4242 |
|
|
function enable(namespaces) {
|
4243 |
|
|
createDebug.save(namespaces);
|
4244 |
|
|
createDebug.names = [];
|
4245 |
|
|
createDebug.skips = [];
|
4246 |
|
|
var i;
|
4247 |
|
|
var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
4248 |
|
|
var len = split.length;
|
4249 |
|
|
|
4250 |
|
|
for (i = 0; i < len; i++) {
|
4251 |
|
|
if (!split[i]) {
|
4252 |
|
|
// ignore empty strings
|
4253 |
|
|
continue;
|
4254 |
|
|
}
|
4255 |
|
|
|
4256 |
|
|
namespaces = split[i].replace(/\*/g, '.*?');
|
4257 |
|
|
|
4258 |
|
|
if (namespaces[0] === '-') {
|
4259 |
|
|
createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
4260 |
|
|
} else {
|
4261 |
|
|
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
4262 |
|
|
}
|
4263 |
|
|
}
|
4264 |
|
|
|
4265 |
|
|
for (i = 0; i < createDebug.instances.length; i++) {
|
4266 |
|
|
var instance = createDebug.instances[i];
|
4267 |
|
|
instance.enabled = createDebug.enabled(instance.namespace);
|
4268 |
|
|
}
|
4269 |
|
|
}
|
4270 |
|
|
/**
|
4271 |
|
|
* Disable debug output.
|
4272 |
|
|
*
|
4273 |
|
|
* @api public
|
4274 |
|
|
*/
|
4275 |
|
|
|
4276 |
|
|
|
4277 |
|
|
function disable() {
|
4278 |
|
|
createDebug.enable('');
|
4279 |
|
|
}
|
4280 |
|
|
/**
|
4281 |
|
|
* Returns true if the given mode name is enabled, false otherwise.
|
4282 |
|
|
*
|
4283 |
|
|
* @param {String} name
|
4284 |
|
|
* @return {Boolean}
|
4285 |
|
|
* @api public
|
4286 |
|
|
*/
|
4287 |
|
|
|
4288 |
|
|
|
4289 |
|
|
function enabled(name) {
|
4290 |
|
|
if (name[name.length - 1] === '*') {
|
4291 |
|
|
return true;
|
4292 |
|
|
}
|
4293 |
|
|
|
4294 |
|
|
var i;
|
4295 |
|
|
var len;
|
4296 |
|
|
|
4297 |
|
|
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
4298 |
|
|
if (createDebug.skips[i].test(name)) {
|
4299 |
|
|
return false;
|
4300 |
|
|
}
|
4301 |
|
|
}
|
4302 |
|
|
|
4303 |
|
|
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
4304 |
|
|
if (createDebug.names[i].test(name)) {
|
4305 |
|
|
return true;
|
4306 |
|
|
}
|
4307 |
|
|
}
|
4308 |
|
|
|
4309 |
|
|
return false;
|
4310 |
|
|
}
|
4311 |
|
|
/**
|
4312 |
|
|
* Coerce `val`.
|
4313 |
|
|
*
|
4314 |
|
|
* @param {Mixed} val
|
4315 |
|
|
* @return {Mixed}
|
4316 |
|
|
* @api private
|
4317 |
|
|
*/
|
4318 |
|
|
|
4319 |
|
|
|
4320 |
|
|
function coerce(val) {
|
4321 |
|
|
if (val instanceof Error) {
|
4322 |
|
|
return val.stack || val.message;
|
4323 |
|
|
}
|
4324 |
|
|
|
4325 |
|
|
return val;
|
4326 |
|
|
}
|
4327 |
|
|
|
4328 |
|
|
createDebug.enable(createDebug.load());
|
4329 |
|
|
return createDebug;
|
4330 |
|
|
}
|
4331 |
|
|
|
4332 |
|
|
module.exports = setup;
|
4333 |
|
|
|
4334 |
|
|
|
4335 |
|
|
},{"ms":54}],57:[function(require,module,exports){
|
4336 |
|
|
if (typeof Object.create === 'function') {
|
4337 |
|
|
// implementation from standard node.js 'util' module
|
4338 |
|
|
module.exports = function inherits(ctor, superCtor) {
|
4339 |
|
|
ctor.super_ = superCtor
|
4340 |
|
|
ctor.prototype = Object.create(superCtor.prototype, {
|
4341 |
|
|
constructor: {
|
4342 |
|
|
value: ctor,
|
4343 |
|
|
enumerable: false,
|
4344 |
|
|
writable: true,
|
4345 |
|
|
configurable: true
|
4346 |
|
|
}
|
4347 |
|
|
});
|
4348 |
|
|
};
|
4349 |
|
|
} else {
|
4350 |
|
|
// old school shim for old browsers
|
4351 |
|
|
module.exports = function inherits(ctor, superCtor) {
|
4352 |
|
|
ctor.super_ = superCtor
|
4353 |
|
|
var TempCtor = function () {}
|
4354 |
|
|
TempCtor.prototype = superCtor.prototype
|
4355 |
|
|
ctor.prototype = new TempCtor()
|
4356 |
|
|
ctor.prototype.constructor = ctor
|
4357 |
|
|
}
|
4358 |
|
|
}
|
4359 |
|
|
|
4360 |
|
|
},{}],58:[function(require,module,exports){
|
4361 |
|
|
(function (global){
|
4362 |
|
|
/*! JSON v3.3.2 | http://bestiejs.github.io/json3 | Copyright 2012-2014, Kit Cambridge | http://kit.mit-license.org */
|
4363 |
|
|
;(function () {
|
4364 |
|
|
// Detect the `define` function exposed by asynchronous module loaders. The
|
4365 |
|
|
// strict `define` check is necessary for compatibility with `r.js`.
|
4366 |
|
|
var isLoader = typeof define === "function" && define.amd;
|
4367 |
|
|
|
4368 |
|
|
// A set of types used to distinguish objects from primitives.
|
4369 |
|
|
var objectTypes = {
|
4370 |
|
|
"function": true,
|
4371 |
|
|
"object": true
|
4372 |
|
|
};
|
4373 |
|
|
|
4374 |
|
|
// Detect the `exports` object exposed by CommonJS implementations.
|
4375 |
|
|
var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
|
4376 |
|
|
|
4377 |
|
|
// Use the `global` object exposed by Node (including Browserify via
|
4378 |
|
|
// `insert-module-globals`), Narwhal, and Ringo as the default context,
|
4379 |
|
|
// and the `window` object in browsers. Rhino exports a `global` function
|
4380 |
|
|
// instead.
|
4381 |
|
|
var root = objectTypes[typeof window] && window || this,
|
4382 |
|
|
freeGlobal = freeExports && objectTypes[typeof module] && module && !module.nodeType && typeof global == "object" && global;
|
4383 |
|
|
|
4384 |
|
|
if (freeGlobal && (freeGlobal["global"] === freeGlobal || freeGlobal["window"] === freeGlobal || freeGlobal["self"] === freeGlobal)) {
|
4385 |
|
|
root = freeGlobal;
|
4386 |
|
|
}
|
4387 |
|
|
|
4388 |
|
|
// Public: Initializes JSON 3 using the given `context` object, attaching the
|
4389 |
|
|
// `stringify` and `parse` functions to the specified `exports` object.
|
4390 |
|
|
function runInContext(context, exports) {
|
4391 |
|
|
context || (context = root["Object"]());
|
4392 |
|
|
exports || (exports = root["Object"]());
|
4393 |
|
|
|
4394 |
|
|
// Native constructor aliases.
|
4395 |
|
|
var Number = context["Number"] || root["Number"],
|
4396 |
|
|
String = context["String"] || root["String"],
|
4397 |
|
|
Object = context["Object"] || root["Object"],
|
4398 |
|
|
Date = context["Date"] || root["Date"],
|
4399 |
|
|
SyntaxError = context["SyntaxError"] || root["SyntaxError"],
|
4400 |
|
|
TypeError = context["TypeError"] || root["TypeError"],
|
4401 |
|
|
Math = context["Math"] || root["Math"],
|
4402 |
|
|
nativeJSON = context["JSON"] || root["JSON"];
|
4403 |
|
|
|
4404 |
|
|
// Delegate to the native `stringify` and `parse` implementations.
|
4405 |
|
|
if (typeof nativeJSON == "object" && nativeJSON) {
|
4406 |
|
|
exports.stringify = nativeJSON.stringify;
|
4407 |
|
|
exports.parse = nativeJSON.parse;
|
4408 |
|
|
}
|
4409 |
|
|
|
4410 |
|
|
// Convenience aliases.
|
4411 |
|
|
var objectProto = Object.prototype,
|
4412 |
|
|
getClass = objectProto.toString,
|
4413 |
|
|
isProperty, forEach, undef;
|
4414 |
|
|
|
4415 |
|
|
// Test the `Date#getUTC*` methods. Based on work by @Yaffle.
|
4416 |
|
|
var isExtended = new Date(-3509827334573292);
|
4417 |
|
|
try {
|
4418 |
|
|
// The `getUTCFullYear`, `Month`, and `Date` methods return nonsensical
|
4419 |
|
|
// results for certain dates in Opera >= 10.53.
|
4420 |
|
|
isExtended = isExtended.getUTCFullYear() == -109252 && isExtended.getUTCMonth() === 0 && isExtended.getUTCDate() === 1 &&
|
4421 |
|
|
// Safari < 2.0.2 stores the internal millisecond time value correctly,
|
4422 |
|
|
// but clips the values returned by the date methods to the range of
|
4423 |
|
|
// signed 32-bit integers ([-2 ** 31, 2 ** 31 - 1]).
|
4424 |
|
|
isExtended.getUTCHours() == 10 && isExtended.getUTCMinutes() == 37 && isExtended.getUTCSeconds() == 6 && isExtended.getUTCMilliseconds() == 708;
|
4425 |
|
|
} catch (exception) {}
|
4426 |
|
|
|
4427 |
|
|
// Internal: Determines whether the native `JSON.stringify` and `parse`
|
4428 |
|
|
// implementations are spec-compliant. Based on work by Ken Snyder.
|
4429 |
|
|
function has(name) {
|
4430 |
|
|
if (has[name] !== undef) {
|
4431 |
|
|
// Return cached feature test result.
|
4432 |
|
|
return has[name];
|
4433 |
|
|
}
|
4434 |
|
|
var isSupported;
|
4435 |
|
|
if (name == "bug-string-char-index") {
|
4436 |
|
|
// IE <= 7 doesn't support accessing string characters using square
|
4437 |
|
|
// bracket notation. IE 8 only supports this for primitives.
|
4438 |
|
|
isSupported = "a"[0] != "a";
|
4439 |
|
|
} else if (name == "json") {
|
4440 |
|
|
// Indicates whether both `JSON.stringify` and `JSON.parse` are
|
4441 |
|
|
// supported.
|
4442 |
|
|
isSupported = has("json-stringify") && has("json-parse");
|
4443 |
|
|
} else {
|
4444 |
|
|
var value, serialized = '{"a":[1,true,false,null,"\\u0000\\b\\n\\f\\r\\t"]}';
|
4445 |
|
|
// Test `JSON.stringify`.
|
4446 |
|
|
if (name == "json-stringify") {
|
4447 |
|
|
var stringify = exports.stringify, stringifySupported = typeof stringify == "function" && isExtended;
|
4448 |
|
|
if (stringifySupported) {
|
4449 |
|
|
// A test function object with a custom `toJSON` method.
|
4450 |
|
|
(value = function () {
|
4451 |
|
|
return 1;
|
4452 |
|
|
}).toJSON = value;
|
4453 |
|
|
try {
|
4454 |
|
|
stringifySupported =
|
4455 |
|
|
// Firefox 3.1b1 and b2 serialize string, number, and boolean
|
4456 |
|
|
// primitives as object literals.
|
4457 |
|
|
stringify(0) === "0" &&
|
4458 |
|
|
// FF 3.1b1, b2, and JSON 2 serialize wrapped primitives as object
|
4459 |
|
|
// literals.
|
4460 |
|
|
stringify(new Number()) === "0" &&
|
4461 |
|
|
stringify(new String()) == '""' &&
|
4462 |
|
|
// FF 3.1b1, 2 throw an error if the value is `null`, `undefined`, or
|
4463 |
|
|
// does not define a canonical JSON representation (this applies to
|
4464 |
|
|
// objects with `toJSON` properties as well, *unless* they are nested
|
4465 |
|
|
// within an object or array).
|
4466 |
|
|
stringify(getClass) === undef &&
|
4467 |
|
|
// IE 8 serializes `undefined` as `"undefined"`. Safari <= 5.1.7 and
|
4468 |
|
|
// FF 3.1b3 pass this test.
|
4469 |
|
|
stringify(undef) === undef &&
|
4470 |
|
|
// Safari <= 5.1.7 and FF 3.1b3 throw `Error`s and `TypeError`s,
|
4471 |
|
|
// respectively, if the value is omitted entirely.
|
4472 |
|
|
stringify() === undef &&
|
4473 |
|
|
// FF 3.1b1, 2 throw an error if the given value is not a number,
|
4474 |
|
|
// string, array, object, Boolean, or `null` literal. This applies to
|
4475 |
|
|
// objects with custom `toJSON` methods as well, unless they are nested
|
4476 |
|
|
// inside object or array literals. YUI 3.0.0b1 ignores custom `toJSON`
|
4477 |
|
|
// methods entirely.
|
4478 |
|
|
stringify(value) === "1" &&
|
4479 |
|
|
stringify([value]) == "[1]" &&
|
4480 |
|
|
// Prototype <= 1.6.1 serializes `[undefined]` as `"[]"` instead of
|
4481 |
|
|
// `"[null]"`.
|
4482 |
|
|
stringify([undef]) == "[null]" &&
|
4483 |
|
|
// YUI 3.0.0b1 fails to serialize `null` literals.
|
4484 |
|
|
stringify(null) == "null" &&
|
4485 |
|
|
// FF 3.1b1, 2 halts serialization if an array contains a function:
|
4486 |
|
|
// `[1, true, getClass, 1]` serializes as "[1,true,],". FF 3.1b3
|
4487 |
|
|
// elides non-JSON values from objects and arrays, unless they
|
4488 |
|
|
// define custom `toJSON` methods.
|
4489 |
|
|
stringify([undef, getClass, null]) == "[null,null,null]" &&
|
4490 |
|
|
// Simple serialization test. FF 3.1b1 uses Unicode escape sequences
|
4491 |
|
|
// where character escape codes are expected (e.g., `\b` => `\u0008`).
|
4492 |
|
|
stringify({ "a": [value, true, false, null, "\x00\b\n\f\r\t"] }) == serialized &&
|
4493 |
|
|
// FF 3.1b1 and b2 ignore the `filter` and `width` arguments.
|
4494 |
|
|
stringify(null, value) === "1" &&
|
4495 |
|
|
stringify([1, 2], null, 1) == "[\n 1,\n 2\n]" &&
|
4496 |
|
|
// JSON 2, Prototype <= 1.7, and older WebKit builds incorrectly
|
4497 |
|
|
// serialize extended years.
|
4498 |
|
|
stringify(new Date(-8.64e15)) == '"-271821-04-20T00:00:00.000Z"' &&
|
4499 |
|
|
// The milliseconds are optional in ES 5, but required in 5.1.
|
4500 |
|
|
stringify(new Date(8.64e15)) == '"+275760-09-13T00:00:00.000Z"' &&
|
4501 |
|
|
// Firefox <= 11.0 incorrectly serializes years prior to 0 as negative
|
4502 |
|
|
// four-digit years instead of six-digit years. Credits: @Yaffle.
|
4503 |
|
|
stringify(new Date(-621987552e5)) == '"-000001-01-01T00:00:00.000Z"' &&
|
4504 |
|
|
// Safari <= 5.1.5 and Opera >= 10.53 incorrectly serialize millisecond
|
4505 |
|
|
// values less than 1000. Credits: @Yaffle.
|
4506 |
|
|
stringify(new Date(-1)) == '"1969-12-31T23:59:59.999Z"';
|
4507 |
|
|
} catch (exception) {
|
4508 |
|
|
stringifySupported = false;
|
4509 |
|
|
}
|
4510 |
|
|
}
|
4511 |
|
|
isSupported = stringifySupported;
|
4512 |
|
|
}
|
4513 |
|
|
// Test `JSON.parse`.
|
4514 |
|
|
if (name == "json-parse") {
|
4515 |
|
|
var parse = exports.parse;
|
4516 |
|
|
if (typeof parse == "function") {
|
4517 |
|
|
try {
|
4518 |
|
|
// FF 3.1b1, b2 will throw an exception if a bare literal is provided.
|
4519 |
|
|
// Conforming implementations should also coerce the initial argument to
|
4520 |
|
|
// a string prior to parsing.
|
4521 |
|
|
if (parse("0") === 0 && !parse(false)) {
|
4522 |
|
|
// Simple parsing test.
|
4523 |
|
|
value = parse(serialized);
|
4524 |
|
|
var parseSupported = value["a"].length == 5 && value["a"][0] === 1;
|
4525 |
|
|
if (parseSupported) {
|
4526 |
|
|
try {
|
4527 |
|
|
// Safari <= 5.1.2 and FF 3.1b1 allow unescaped tabs in strings.
|
4528 |
|
|
parseSupported = !parse('"\t"');
|
4529 |
|
|
} catch (exception) {}
|
4530 |
|
|
if (parseSupported) {
|
4531 |
|
|
try {
|
4532 |
|
|
// FF 4.0 and 4.0.1 allow leading `+` signs and leading
|
4533 |
|
|
// decimal points. FF 4.0, 4.0.1, and IE 9-10 also allow
|
4534 |
|
|
// certain octal literals.
|
4535 |
|
|
parseSupported = parse("01") !== 1;
|
4536 |
|
|
} catch (exception) {}
|
4537 |
|
|
}
|
4538 |
|
|
if (parseSupported) {
|
4539 |
|
|
try {
|
4540 |
|
|
// FF 4.0, 4.0.1, and Rhino 1.7R3-R4 allow trailing decimal
|
4541 |
|
|
// points. These environments, along with FF 3.1b1 and 2,
|
4542 |
|
|
// also allow trailing commas in JSON objects and arrays.
|
4543 |
|
|
parseSupported = parse("1.") !== 1;
|
4544 |
|
|
} catch (exception) {}
|
4545 |
|
|
}
|
4546 |
|
|
}
|
4547 |
|
|
}
|
4548 |
|
|
} catch (exception) {
|
4549 |
|
|
parseSupported = false;
|
4550 |
|
|
}
|
4551 |
|
|
}
|
4552 |
|
|
isSupported = parseSupported;
|
4553 |
|
|
}
|
4554 |
|
|
}
|
4555 |
|
|
return has[name] = !!isSupported;
|
4556 |
|
|
}
|
4557 |
|
|
|
4558 |
|
|
if (!has("json")) {
|
4559 |
|
|
// Common `[[Class]]` name aliases.
|
4560 |
|
|
var functionClass = "[object Function]",
|
4561 |
|
|
dateClass = "[object Date]",
|
4562 |
|
|
numberClass = "[object Number]",
|
4563 |
|
|
stringClass = "[object String]",
|
4564 |
|
|
arrayClass = "[object Array]",
|
4565 |
|
|
booleanClass = "[object Boolean]";
|
4566 |
|
|
|
4567 |
|
|
// Detect incomplete support for accessing string characters by index.
|
4568 |
|
|
var charIndexBuggy = has("bug-string-char-index");
|
4569 |
|
|
|
4570 |
|
|
// Define additional utility methods if the `Date` methods are buggy.
|
4571 |
|
|
if (!isExtended) {
|
4572 |
|
|
var floor = Math.floor;
|
4573 |
|
|
// A mapping between the months of the year and the number of days between
|
4574 |
|
|
// January 1st and the first of the respective month.
|
4575 |
|
|
var Months = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
|
4576 |
|
|
// Internal: Calculates the number of days between the Unix epoch and the
|
4577 |
|
|
// first day of the given month.
|
4578 |
|
|
var getDay = function (year, month) {
|
4579 |
|
|
return Months[month] + 365 * (year - 1970) + floor((year - 1969 + (month = +(month > 1))) / 4) - floor((year - 1901 + month) / 100) + floor((year - 1601 + month) / 400);
|
4580 |
|
|
};
|
4581 |
|
|
}
|
4582 |
|
|
|
4583 |
|
|
// Internal: Determines if a property is a direct property of the given
|
4584 |
|
|
// object. Delegates to the native `Object#hasOwnProperty` method.
|
4585 |
|
|
if (!(isProperty = objectProto.hasOwnProperty)) {
|
4586 |
|
|
isProperty = function (property) {
|
4587 |
|
|
var members = {}, constructor;
|
4588 |
|
|
if ((members.__proto__ = null, members.__proto__ = {
|
4589 |
|
|
// The *proto* property cannot be set multiple times in recent
|
4590 |
|
|
// versions of Firefox and SeaMonkey.
|
4591 |
|
|
"toString": 1
|
4592 |
|
|
}, members).toString != getClass) {
|
4593 |
|
|
// Safari <= 2.0.3 doesn't implement `Object#hasOwnProperty`, but
|
4594 |
|
|
// supports the mutable *proto* property.
|
4595 |
|
|
isProperty = function (property) {
|
4596 |
|
|
// Capture and break the object's prototype chain (see section 8.6.2
|
4597 |
|
|
// of the ES 5.1 spec). The parenthesized expression prevents an
|
4598 |
|
|
// unsafe transformation by the Closure Compiler.
|
4599 |
|
|
var original = this.__proto__, result = property in (this.__proto__ = null, this);
|
4600 |
|
|
// Restore the original prototype chain.
|
4601 |
|
|
this.__proto__ = original;
|
4602 |
|
|
return result;
|
4603 |
|
|
};
|
4604 |
|
|
} else {
|
4605 |
|
|
// Capture a reference to the top-level `Object` constructor.
|
4606 |
|
|
constructor = members.constructor;
|
4607 |
|
|
// Use the `constructor` property to simulate `Object#hasOwnProperty` in
|
4608 |
|
|
// other environments.
|
4609 |
|
|
isProperty = function (property) {
|
4610 |
|
|
var parent = (this.constructor || constructor).prototype;
|
4611 |
|
|
return property in this && !(property in parent && this[property] === parent[property]);
|
4612 |
|
|
};
|
4613 |
|
|
}
|
4614 |
|
|
members = null;
|
4615 |
|
|
return isProperty.call(this, property);
|
4616 |
|
|
};
|
4617 |
|
|
}
|
4618 |
|
|
|
4619 |
|
|
// Internal: Normalizes the `for...in` iteration algorithm across
|
4620 |
|
|
// environments. Each enumerated key is yielded to a `callback` function.
|
4621 |
|
|
forEach = function (object, callback) {
|
4622 |
|
|
var size = 0, Properties, members, property;
|
4623 |
|
|
|
4624 |
|
|
// Tests for bugs in the current environment's `for...in` algorithm. The
|
4625 |
|
|
// `valueOf` property inherits the non-enumerable flag from
|
4626 |
|
|
// `Object.prototype` in older versions of IE, Netscape, and Mozilla.
|
4627 |
|
|
(Properties = function () {
|
4628 |
|
|
this.valueOf = 0;
|
4629 |
|
|
}).prototype.valueOf = 0;
|
4630 |
|
|
|
4631 |
|
|
// Iterate over a new instance of the `Properties` class.
|
4632 |
|
|
members = new Properties();
|
4633 |
|
|
for (property in members) {
|
4634 |
|
|
// Ignore all properties inherited from `Object.prototype`.
|
4635 |
|
|
if (isProperty.call(members, property)) {
|
4636 |
|
|
size++;
|
4637 |
|
|
}
|
4638 |
|
|
}
|
4639 |
|
|
Properties = members = null;
|
4640 |
|
|
|
4641 |
|
|
// Normalize the iteration algorithm.
|
4642 |
|
|
if (!size) {
|
4643 |
|
|
// A list of non-enumerable properties inherited from `Object.prototype`.
|
4644 |
|
|
members = ["valueOf", "toString", "toLocaleString", "propertyIsEnumerable", "isPrototypeOf", "hasOwnProperty", "constructor"];
|
4645 |
|
|
// IE <= 8, Mozilla 1.0, and Netscape 6.2 ignore shadowed non-enumerable
|
4646 |
|
|
// properties.
|
4647 |
|
|
forEach = function (object, callback) {
|
4648 |
|
|
var isFunction = getClass.call(object) == functionClass, property, length;
|
4649 |
|
|
var hasProperty = !isFunction && typeof object.constructor != "function" && objectTypes[typeof object.hasOwnProperty] && object.hasOwnProperty || isProperty;
|
4650 |
|
|
for (property in object) {
|
4651 |
|
|
// Gecko <= 1.0 enumerates the `prototype` property of functions under
|
4652 |
|
|
// certain conditions; IE does not.
|
4653 |
|
|
if (!(isFunction && property == "prototype") && hasProperty.call(object, property)) {
|
4654 |
|
|
callback(property);
|
4655 |
|
|
}
|
4656 |
|
|
}
|
4657 |
|
|
// Manually invoke the callback for each non-enumerable property.
|
4658 |
|
|
for (length = members.length; property = members[--length]; hasProperty.call(object, property) && callback(property));
|
4659 |
|
|
};
|
4660 |
|
|
} else if (size == 2) {
|
4661 |
|
|
// Safari <= 2.0.4 enumerates shadowed properties twice.
|
4662 |
|
|
forEach = function (object, callback) {
|
4663 |
|
|
// Create a set of iterated properties.
|
4664 |
|
|
var members = {}, isFunction = getClass.call(object) == functionClass, property;
|
4665 |
|
|
for (property in object) {
|
4666 |
|
|
// Store each property name to prevent double enumeration. The
|
4667 |
|
|
// `prototype` property of functions is not enumerated due to cross-
|
4668 |
|
|
// environment inconsistencies.
|
4669 |
|
|
if (!(isFunction && property == "prototype") && !isProperty.call(members, property) && (members[property] = 1) && isProperty.call(object, property)) {
|
4670 |
|
|
callback(property);
|
4671 |
|
|
}
|
4672 |
|
|
}
|
4673 |
|
|
};
|
4674 |
|
|
} else {
|
4675 |
|
|
// No bugs detected; use the standard `for...in` algorithm.
|
4676 |
|
|
forEach = function (object, callback) {
|
4677 |
|
|
var isFunction = getClass.call(object) == functionClass, property, isConstructor;
|
4678 |
|
|
for (property in object) {
|
4679 |
|
|
if (!(isFunction && property == "prototype") && isProperty.call(object, property) && !(isConstructor = property === "constructor")) {
|
4680 |
|
|
callback(property);
|
4681 |
|
|
}
|
4682 |
|
|
}
|
4683 |
|
|
// Manually invoke the callback for the `constructor` property due to
|
4684 |
|
|
// cross-environment inconsistencies.
|
4685 |
|
|
if (isConstructor || isProperty.call(object, (property = "constructor"))) {
|
4686 |
|
|
callback(property);
|
4687 |
|
|
}
|
4688 |
|
|
};
|
4689 |
|
|
}
|
4690 |
|
|
return forEach(object, callback);
|
4691 |
|
|
};
|
4692 |
|
|
|
4693 |
|
|
// Public: Serializes a JavaScript `value` as a JSON string. The optional
|
4694 |
|
|
// `filter` argument may specify either a function that alters how object and
|
4695 |
|
|
// array members are serialized, or an array of strings and numbers that
|
4696 |
|
|
// indicates which properties should be serialized. The optional `width`
|
4697 |
|
|
// argument may be either a string or number that specifies the indentation
|
4698 |
|
|
// level of the output.
|
4699 |
|
|
if (!has("json-stringify")) {
|
4700 |
|
|
// Internal: A map of control characters and their escaped equivalents.
|
4701 |
|
|
var Escapes = {
|
4702 |
|
|
92: "\\\\",
|
4703 |
|
|
34: '\\"',
|
4704 |
|
|
8: "\\b",
|
4705 |
|
|
12: "\\f",
|
4706 |
|
|
10: "\\n",
|
4707 |
|
|
13: "\\r",
|
4708 |
|
|
9: "\\t"
|
4709 |
|
|
};
|
4710 |
|
|
|
4711 |
|
|
// Internal: Converts `value` into a zero-padded string such that its
|
4712 |
|
|
// length is at least equal to `width`. The `width` must be <= 6.
|
4713 |
|
|
var leadingZeroes = "000000";
|
4714 |
|
|
var toPaddedString = function (width, value) {
|
4715 |
|
|
// The `|| 0` expression is necessary to work around a bug in
|
4716 |
|
|
// Opera <= 7.54u2 where `0 == -0`, but `String(-0) !== "0"`.
|
4717 |
|
|
return (leadingZeroes + (value || 0)).slice(-width);
|
4718 |
|
|
};
|
4719 |
|
|
|
4720 |
|
|
// Internal: Double-quotes a string `value`, replacing all ASCII control
|
4721 |
|
|
// characters (characters with code unit values between 0 and 31) with
|
4722 |
|
|
// their escaped equivalents. This is an implementation of the
|
4723 |
|
|
// `Quote(value)` operation defined in ES 5.1 section 15.12.3.
|
4724 |
|
|
var unicodePrefix = "\\u00";
|
4725 |
|
|
var quote = function (value) {
|
4726 |
|
|
var result = '"', index = 0, length = value.length, useCharIndex = !charIndexBuggy || length > 10;
|
4727 |
|
|
var symbols = useCharIndex && (charIndexBuggy ? value.split("") : value);
|
4728 |
|
|
for (; index < length; index++) {
|
4729 |
|
|
var charCode = value.charCodeAt(index);
|
4730 |
|
|
// If the character is a control character, append its Unicode or
|
4731 |
|
|
// shorthand escape sequence; otherwise, append the character as-is.
|
4732 |
|
|
switch (charCode) {
|
4733 |
|
|
case 8: case 9: case 10: case 12: case 13: case 34: case 92:
|
4734 |
|
|
result += Escapes[charCode];
|
4735 |
|
|
break;
|
4736 |
|
|
default:
|
4737 |
|
|
if (charCode < 32) {
|
4738 |
|
|
result += unicodePrefix + toPaddedString(2, charCode.toString(16));
|
4739 |
|
|
break;
|
4740 |
|
|
}
|
4741 |
|
|
result += useCharIndex ? symbols[index] : value.charAt(index);
|
4742 |
|
|
}
|
4743 |
|
|
}
|
4744 |
|
|
return result + '"';
|
4745 |
|
|
};
|
4746 |
|
|
|
4747 |
|
|
// Internal: Recursively serializes an object. Implements the
|
4748 |
|
|
// `Str(key, holder)`, `JO(value)`, and `JA(value)` operations.
|
4749 |
|
|
var serialize = function (property, object, callback, properties, whitespace, indentation, stack) {
|
4750 |
|
|
var value, className, year, month, date, time, hours, minutes, seconds, milliseconds, results, element, index, length, prefix, result;
|
4751 |
|
|
try {
|
4752 |
|
|
// Necessary for host object support.
|
4753 |
|
|
value = object[property];
|
4754 |
|
|
} catch (exception) {}
|
4755 |
|
|
if (typeof value == "object" && value) {
|
4756 |
|
|
className = getClass.call(value);
|
4757 |
|
|
if (className == dateClass && !isProperty.call(value, "toJSON")) {
|
4758 |
|
|
if (value > -1 / 0 && value < 1 / 0) {
|
4759 |
|
|
// Dates are serialized according to the `Date#toJSON` method
|
4760 |
|
|
// specified in ES 5.1 section 15.9.5.44. See section 15.9.1.15
|
4761 |
|
|
// for the ISO 8601 date time string format.
|
4762 |
|
|
if (getDay) {
|
4763 |
|
|
// Manually compute the year, month, date, hours, minutes,
|
4764 |
|
|
// seconds, and milliseconds if the `getUTC*` methods are
|
4765 |
|
|
// buggy. Adapted from @Yaffle's `date-shim` project.
|
4766 |
|
|
date = floor(value / 864e5);
|
4767 |
|
|
for (year = floor(date / 365.2425) + 1970 - 1; getDay(year + 1, 0) <= date; year++);
|
4768 |
|
|
for (month = floor((date - getDay(year, 0)) / 30.42); getDay(year, month + 1) <= date; month++);
|
4769 |
|
|
date = 1 + date - getDay(year, month);
|
4770 |
|
|
// The `time` value specifies the time within the day (see ES
|
4771 |
|
|
// 5.1 section 15.9.1.2). The formula `(A % B + B) % B` is used
|
4772 |
|
|
// to compute `A modulo B`, as the `%` operator does not
|
4773 |
|
|
// correspond to the `modulo` operation for negative numbers.
|
4774 |
|
|
time = (value % 864e5 + 864e5) % 864e5;
|
4775 |
|
|
// The hours, minutes, seconds, and milliseconds are obtained by
|
4776 |
|
|
// decomposing the time within the day. See section 15.9.1.10.
|
4777 |
|
|
hours = floor(time / 36e5) % 24;
|
4778 |
|
|
minutes = floor(time / 6e4) % 60;
|
4779 |
|
|
seconds = floor(time / 1e3) % 60;
|
4780 |
|
|
milliseconds = time % 1e3;
|
4781 |
|
|
} else {
|
4782 |
|
|
year = value.getUTCFullYear();
|
4783 |
|
|
month = value.getUTCMonth();
|
4784 |
|
|
date = value.getUTCDate();
|
4785 |
|
|
hours = value.getUTCHours();
|
4786 |
|
|
minutes = value.getUTCMinutes();
|
4787 |
|
|
seconds = value.getUTCSeconds();
|
4788 |
|
|
milliseconds = value.getUTCMilliseconds();
|
4789 |
|
|
}
|
4790 |
|
|
// Serialize extended years correctly.
|
4791 |
|
|
value = (year <= 0 || year >= 1e4 ? (year < 0 ? "-" : "+") + toPaddedString(6, year < 0 ? -year : year) : toPaddedString(4, year)) +
|
4792 |
|
|
"-" + toPaddedString(2, month + 1) + "-" + toPaddedString(2, date) +
|
4793 |
|
|
// Months, dates, hours, minutes, and seconds should have two
|
4794 |
|
|
// digits; milliseconds should have three.
|
4795 |
|
|
"T" + toPaddedString(2, hours) + ":" + toPaddedString(2, minutes) + ":" + toPaddedString(2, seconds) +
|
4796 |
|
|
// Milliseconds are optional in ES 5.0, but required in 5.1.
|
4797 |
|
|
"." + toPaddedString(3, milliseconds) + "Z";
|
4798 |
|
|
} else {
|
4799 |
|
|
value = null;
|
4800 |
|
|
}
|
4801 |
|
|
} else if (typeof value.toJSON == "function" && ((className != numberClass && className != stringClass && className != arrayClass) || isProperty.call(value, "toJSON"))) {
|
4802 |
|
|
// Prototype <= 1.6.1 adds non-standard `toJSON` methods to the
|
4803 |
|
|
// `Number`, `String`, `Date`, and `Array` prototypes. JSON 3
|
4804 |
|
|
// ignores all `toJSON` methods on these objects unless they are
|
4805 |
|
|
// defined directly on an instance.
|
4806 |
|
|
value = value.toJSON(property);
|
4807 |
|
|
}
|
4808 |
|
|
}
|
4809 |
|
|
if (callback) {
|
4810 |
|
|
// If a replacement function was provided, call it to obtain the value
|
4811 |
|
|
// for serialization.
|
4812 |
|
|
value = callback.call(object, property, value);
|
4813 |
|
|
}
|
4814 |
|
|
if (value === null) {
|
4815 |
|
|
return "null";
|
4816 |
|
|
}
|
4817 |
|
|
className = getClass.call(value);
|
4818 |
|
|
if (className == booleanClass) {
|
4819 |
|
|
// Booleans are represented literally.
|
4820 |
|
|
return "" + value;
|
4821 |
|
|
} else if (className == numberClass) {
|
4822 |
|
|
// JSON numbers must be finite. `Infinity` and `NaN` are serialized as
|
4823 |
|
|
// `"null"`.
|
4824 |
|
|
return value > -1 / 0 && value < 1 / 0 ? "" + value : "null";
|
4825 |
|
|
} else if (className == stringClass) {
|
4826 |
|
|
// Strings are double-quoted and escaped.
|
4827 |
|
|
return quote("" + value);
|
4828 |
|
|
}
|
4829 |
|
|
// Recursively serialize objects and arrays.
|
4830 |
|
|
if (typeof value == "object") {
|
4831 |
|
|
// Check for cyclic structures. This is a linear search; performance
|
4832 |
|
|
// is inversely proportional to the number of unique nested objects.
|
4833 |
|
|
for (length = stack.length; length--;) {
|
4834 |
|
|
if (stack[length] === value) {
|
4835 |
|
|
// Cyclic structures cannot be serialized by `JSON.stringify`.
|
4836 |
|
|
throw TypeError();
|
4837 |
|
|
}
|
4838 |
|
|
}
|
4839 |
|
|
// Add the object to the stack of traversed objects.
|
4840 |
|
|
stack.push(value);
|
4841 |
|
|
results = [];
|
4842 |
|
|
// Save the current indentation level and indent one additional level.
|
4843 |
|
|
prefix = indentation;
|
4844 |
|
|
indentation += whitespace;
|
4845 |
|
|
if (className == arrayClass) {
|
4846 |
|
|
// Recursively serialize array elements.
|
4847 |
|
|
for (index = 0, length = value.length; index < length; index++) {
|
4848 |
|
|
element = serialize(index, value, callback, properties, whitespace, indentation, stack);
|
4849 |
|
|
results.push(element === undef ? "null" : element);
|
4850 |
|
|
}
|
4851 |
|
|
result = results.length ? (whitespace ? "[\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "]" : ("[" + results.join(",") + "]")) : "[]";
|
4852 |
|
|
} else {
|
4853 |
|
|
// Recursively serialize object members. Members are selected from
|
4854 |
|
|
// either a user-specified list of property names, or the object
|
4855 |
|
|
// itself.
|
4856 |
|
|
forEach(properties || value, function (property) {
|
4857 |
|
|
var element = serialize(property, value, callback, properties, whitespace, indentation, stack);
|
4858 |
|
|
if (element !== undef) {
|
4859 |
|
|
// According to ES 5.1 section 15.12.3: "If `gap` {whitespace}
|
4860 |
|
|
// is not the empty string, let `member` {quote(property) + ":"}
|
4861 |
|
|
// be the concatenation of `member` and the `space` character."
|
4862 |
|
|
// The "`space` character" refers to the literal space
|
4863 |
|
|
// character, not the `space` {width} argument provided to
|
4864 |
|
|
// `JSON.stringify`.
|
4865 |
|
|
results.push(quote(property) + ":" + (whitespace ? " " : "") + element);
|
4866 |
|
|
}
|
4867 |
|
|
});
|
4868 |
|
|
result = results.length ? (whitespace ? "{\n" + indentation + results.join(",\n" + indentation) + "\n" + prefix + "}" : ("{" + results.join(",") + "}")) : "{}";
|
4869 |
|
|
}
|
4870 |
|
|
// Remove the object from the traversed object stack.
|
4871 |
|
|
stack.pop();
|
4872 |
|
|
return result;
|
4873 |
|
|
}
|
4874 |
|
|
};
|
4875 |
|
|
|
4876 |
|
|
// Public: `JSON.stringify`. See ES 5.1 section 15.12.3.
|
4877 |
|
|
exports.stringify = function (source, filter, width) {
|
4878 |
|
|
var whitespace, callback, properties, className;
|
4879 |
|
|
if (objectTypes[typeof filter] && filter) {
|
4880 |
|
|
if ((className = getClass.call(filter)) == functionClass) {
|
4881 |
|
|
callback = filter;
|
4882 |
|
|
} else if (className == arrayClass) {
|
4883 |
|
|
// Convert the property names array into a makeshift set.
|
4884 |
|
|
properties = {};
|
4885 |
|
|
for (var index = 0, length = filter.length, value; index < length; value = filter[index++], ((className = getClass.call(value)), className == stringClass || className == numberClass) && (properties[value] = 1));
|
4886 |
|
|
}
|
4887 |
|
|
}
|
4888 |
|
|
if (width) {
|
4889 |
|
|
if ((className = getClass.call(width)) == numberClass) {
|
4890 |
|
|
// Convert the `width` to an integer and create a string containing
|
4891 |
|
|
// `width` number of space characters.
|
4892 |
|
|
if ((width -= width % 1) > 0) {
|
4893 |
|
|
for (whitespace = "", width > 10 && (width = 10); whitespace.length < width; whitespace += " ");
|
4894 |
|
|
}
|
4895 |
|
|
} else if (className == stringClass) {
|
4896 |
|
|
whitespace = width.length <= 10 ? width : width.slice(0, 10);
|
4897 |
|
|
}
|
4898 |
|
|
}
|
4899 |
|
|
// Opera <= 7.54u2 discards the values associated with empty string keys
|
4900 |
|
|
// (`""`) only if they are used directly within an object member list
|
4901 |
|
|
// (e.g., `!("" in { "": 1})`).
|
4902 |
|
|
return serialize("", (value = {}, value[""] = source, value), callback, properties, whitespace, "", []);
|
4903 |
|
|
};
|
4904 |
|
|
}
|
4905 |
|
|
|
4906 |
|
|
// Public: Parses a JSON source string.
|
4907 |
|
|
if (!has("json-parse")) {
|
4908 |
|
|
var fromCharCode = String.fromCharCode;
|
4909 |
|
|
|
4910 |
|
|
// Internal: A map of escaped control characters and their unescaped
|
4911 |
|
|
// equivalents.
|
4912 |
|
|
var Unescapes = {
|
4913 |
|
|
92: "\\",
|
4914 |
|
|
34: '"',
|
4915 |
|
|
47: "/",
|
4916 |
|
|
98: "\b",
|
4917 |
|
|
116: "\t",
|
4918 |
|
|
110: "\n",
|
4919 |
|
|
102: "\f",
|
4920 |
|
|
114: "\r"
|
4921 |
|
|
};
|
4922 |
|
|
|
4923 |
|
|
// Internal: Stores the parser state.
|
4924 |
|
|
var Index, Source;
|
4925 |
|
|
|
4926 |
|
|
// Internal: Resets the parser state and throws a `SyntaxError`.
|
4927 |
|
|
var abort = function () {
|
4928 |
|
|
Index = Source = null;
|
4929 |
|
|
throw SyntaxError();
|
4930 |
|
|
};
|
4931 |
|
|
|
4932 |
|
|
// Internal: Returns the next token, or `"$"` if the parser has reached
|
4933 |
|
|
// the end of the source string. A token may be a string, number, `null`
|
4934 |
|
|
// literal, or Boolean literal.
|
4935 |
|
|
var lex = function () {
|
4936 |
|
|
var source = Source, length = source.length, value, begin, position, isSigned, charCode;
|
4937 |
|
|
while (Index < length) {
|
4938 |
|
|
charCode = source.charCodeAt(Index);
|
4939 |
|
|
switch (charCode) {
|
4940 |
|
|
case 9: case 10: case 13: case 32:
|
4941 |
|
|
// Skip whitespace tokens, including tabs, carriage returns, line
|
4942 |
|
|
// feeds, and space characters.
|
4943 |
|
|
Index++;
|
4944 |
|
|
break;
|
4945 |
|
|
case 123: case 125: case 91: case 93: case 58: case 44:
|
4946 |
|
|
// Parse a punctuator token (`{`, `}`, `[`, `]`, `:`, or `,`) at
|
4947 |
|
|
// the current position.
|
4948 |
|
|
value = charIndexBuggy ? source.charAt(Index) : source[Index];
|
4949 |
|
|
Index++;
|
4950 |
|
|
return value;
|
4951 |
|
|
case 34:
|
4952 |
|
|
// `"` delimits a JSON string; advance to the next character and
|
4953 |
|
|
// begin parsing the string. String tokens are prefixed with the
|
4954 |
|
|
// sentinel `@` character to distinguish them from punctuators and
|
4955 |
|
|
// end-of-string tokens.
|
4956 |
|
|
for (value = "@", Index++; Index < length;) {
|
4957 |
|
|
charCode = source.charCodeAt(Index);
|
4958 |
|
|
if (charCode < 32) {
|
4959 |
|
|
// Unescaped ASCII control characters (those with a code unit
|
4960 |
|
|
// less than the space character) are not permitted.
|
4961 |
|
|
abort();
|
4962 |
|
|
} else if (charCode == 92) {
|
4963 |
|
|
// A reverse solidus (`\`) marks the beginning of an escaped
|
4964 |
|
|
// control character (including `"`, `\`, and `/`) or Unicode
|
4965 |
|
|
// escape sequence.
|
4966 |
|
|
charCode = source.charCodeAt(++Index);
|
4967 |
|
|
switch (charCode) {
|
4968 |
|
|
case 92: case 34: case 47: case 98: case 116: case 110: case 102: case 114:
|
4969 |
|
|
// Revive escaped control characters.
|
4970 |
|
|
value += Unescapes[charCode];
|
4971 |
|
|
Index++;
|
4972 |
|
|
break;
|
4973 |
|
|
case 117:
|
4974 |
|
|
// `\u` marks the beginning of a Unicode escape sequence.
|
4975 |
|
|
// Advance to the first character and validate the
|
4976 |
|
|
// four-digit code point.
|
4977 |
|
|
begin = ++Index;
|
4978 |
|
|
for (position = Index + 4; Index < position; Index++) {
|
4979 |
|
|
charCode = source.charCodeAt(Index);
|
4980 |
|
|
// A valid sequence comprises four hexdigits (case-
|
4981 |
|
|
// insensitive) that form a single hexadecimal value.
|
4982 |
|
|
if (!(charCode >= 48 && charCode <= 57 || charCode >= 97 && charCode <= 102 || charCode >= 65 && charCode <= 70)) {
|
4983 |
|
|
// Invalid Unicode escape sequence.
|
4984 |
|
|
abort();
|
4985 |
|
|
}
|
4986 |
|
|
}
|
4987 |
|
|
// Revive the escaped character.
|
4988 |
|
|
value += fromCharCode("0x" + source.slice(begin, Index));
|
4989 |
|
|
break;
|
4990 |
|
|
default:
|
4991 |
|
|
// Invalid escape sequence.
|
4992 |
|
|
abort();
|
4993 |
|
|
}
|
4994 |
|
|
} else {
|
4995 |
|
|
if (charCode == 34) {
|
4996 |
|
|
// An unescaped double-quote character marks the end of the
|
4997 |
|
|
// string.
|
4998 |
|
|
break;
|
4999 |
|
|
}
|
5000 |
|
|
charCode = source.charCodeAt(Index);
|
5001 |
|
|
begin = Index;
|
5002 |
|
|
// Optimize for the common case where a string is valid.
|
5003 |
|
|
while (charCode >= 32 && charCode != 92 && charCode != 34) {
|
5004 |
|
|
charCode = source.charCodeAt(++Index);
|
5005 |
|
|
}
|
5006 |
|
|
// Append the string as-is.
|
5007 |
|
|
value += source.slice(begin, Index);
|
5008 |
|
|
}
|
5009 |
|
|
}
|
5010 |
|
|
if (source.charCodeAt(Index) == 34) {
|
5011 |
|
|
// Advance to the next character and return the revived string.
|
5012 |
|
|
Index++;
|
5013 |
|
|
return value;
|
5014 |
|
|
}
|
5015 |
|
|
// Unterminated string.
|
5016 |
|
|
abort();
|
5017 |
|
|
default:
|
5018 |
|
|
// Parse numbers and literals.
|
5019 |
|
|
begin = Index;
|
5020 |
|
|
// Advance past the negative sign, if one is specified.
|
5021 |
|
|
if (charCode == 45) {
|
5022 |
|
|
isSigned = true;
|
5023 |
|
|
charCode = source.charCodeAt(++Index);
|
5024 |
|
|
}
|
5025 |
|
|
// Parse an integer or floating-point value.
|
5026 |
|
|
if (charCode >= 48 && charCode <= 57) {
|
5027 |
|
|
// Leading zeroes are interpreted as octal literals.
|
5028 |
|
|
if (charCode == 48 && ((charCode = source.charCodeAt(Index + 1)), charCode >= 48 && charCode <= 57)) {
|
5029 |
|
|
// Illegal octal literal.
|
5030 |
|
|
abort();
|
5031 |
|
|
}
|
5032 |
|
|
isSigned = false;
|
5033 |
|
|
// Parse the integer component.
|
5034 |
|
|
for (; Index < length && ((charCode = source.charCodeAt(Index)), charCode >= 48 && charCode <= 57); Index++);
|
5035 |
|
|
// Floats cannot contain a leading decimal point; however, this
|
5036 |
|
|
// case is already accounted for by the parser.
|
5037 |
|
|
if (source.charCodeAt(Index) == 46) {
|
5038 |
|
|
position = ++Index;
|
5039 |
|
|
// Parse the decimal component.
|
5040 |
|
|
for (; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
|
5041 |
|
|
if (position == Index) {
|
5042 |
|
|
// Illegal trailing decimal.
|
5043 |
|
|
abort();
|
5044 |
|
|
}
|
5045 |
|
|
Index = position;
|
5046 |
|
|
}
|
5047 |
|
|
// Parse exponents. The `e` denoting the exponent is
|
5048 |
|
|
// case-insensitive.
|
5049 |
|
|
charCode = source.charCodeAt(Index);
|
5050 |
|
|
if (charCode == 101 || charCode == 69) {
|
5051 |
|
|
charCode = source.charCodeAt(++Index);
|
5052 |
|
|
// Skip past the sign following the exponent, if one is
|
5053 |
|
|
// specified.
|
5054 |
|
|
if (charCode == 43 || charCode == 45) {
|
5055 |
|
|
Index++;
|
5056 |
|
|
}
|
5057 |
|
|
// Parse the exponential component.
|
5058 |
|
|
for (position = Index; position < length && ((charCode = source.charCodeAt(position)), charCode >= 48 && charCode <= 57); position++);
|
5059 |
|
|
if (position == Index) {
|
5060 |
|
|
// Illegal empty exponent.
|
5061 |
|
|
abort();
|
5062 |
|
|
}
|
5063 |
|
|
Index = position;
|
5064 |
|
|
}
|
5065 |
|
|
// Coerce the parsed value to a JavaScript number.
|
5066 |
|
|
return +source.slice(begin, Index);
|
5067 |
|
|
}
|
5068 |
|
|
// A negative sign may only precede numbers.
|
5069 |
|
|
if (isSigned) {
|
5070 |
|
|
abort();
|
5071 |
|
|
}
|
5072 |
|
|
// `true`, `false`, and `null` literals.
|
5073 |
|
|
if (source.slice(Index, Index + 4) == "true") {
|
5074 |
|
|
Index += 4;
|
5075 |
|
|
return true;
|
5076 |
|
|
} else if (source.slice(Index, Index + 5) == "false") {
|
5077 |
|
|
Index += 5;
|
5078 |
|
|
return false;
|
5079 |
|
|
} else if (source.slice(Index, Index + 4) == "null") {
|
5080 |
|
|
Index += 4;
|
5081 |
|
|
return null;
|
5082 |
|
|
}
|
5083 |
|
|
// Unrecognized token.
|
5084 |
|
|
abort();
|
5085 |
|
|
}
|
5086 |
|
|
}
|
5087 |
|
|
// Return the sentinel `$` character if the parser has reached the end
|
5088 |
|
|
// of the source string.
|
5089 |
|
|
return "$";
|
5090 |
|
|
};
|
5091 |
|
|
|
5092 |
|
|
// Internal: Parses a JSON `value` token.
|
5093 |
|
|
var get = function (value) {
|
5094 |
|
|
var results, hasMembers;
|
5095 |
|
|
if (value == "$") {
|
5096 |
|
|
// Unexpected end of input.
|
5097 |
|
|
abort();
|
5098 |
|
|
}
|
5099 |
|
|
if (typeof value == "string") {
|
5100 |
|
|
if ((charIndexBuggy ? value.charAt(0) : value[0]) == "@") {
|
5101 |
|
|
// Remove the sentinel `@` character.
|
5102 |
|
|
return value.slice(1);
|
5103 |
|
|
}
|
5104 |
|
|
// Parse object and array literals.
|
5105 |
|
|
if (value == "[") {
|
5106 |
|
|
// Parses a JSON array, returning a new JavaScript array.
|
5107 |
|
|
results = [];
|
5108 |
|
|
for (;; hasMembers || (hasMembers = true)) {
|
5109 |
|
|
value = lex();
|
5110 |
|
|
// A closing square bracket marks the end of the array literal.
|
5111 |
|
|
if (value == "]") {
|
5112 |
|
|
break;
|
5113 |
|
|
}
|
5114 |
|
|
// If the array literal contains elements, the current token
|
5115 |
|
|
// should be a comma separating the previous element from the
|
5116 |
|
|
// next.
|
5117 |
|
|
if (hasMembers) {
|
5118 |
|
|
if (value == ",") {
|
5119 |
|
|
value = lex();
|
5120 |
|
|
if (value == "]") {
|
5121 |
|
|
// Unexpected trailing `,` in array literal.
|
5122 |
|
|
abort();
|
5123 |
|
|
}
|
5124 |
|
|
} else {
|
5125 |
|
|
// A `,` must separate each array element.
|
5126 |
|
|
abort();
|
5127 |
|
|
}
|
5128 |
|
|
}
|
5129 |
|
|
// Elisions and leading commas are not permitted.
|
5130 |
|
|
if (value == ",") {
|
5131 |
|
|
abort();
|
5132 |
|
|
}
|
5133 |
|
|
results.push(get(value));
|
5134 |
|
|
}
|
5135 |
|
|
return results;
|
5136 |
|
|
} else if (value == "{") {
|
5137 |
|
|
// Parses a JSON object, returning a new JavaScript object.
|
5138 |
|
|
results = {};
|
5139 |
|
|
for (;; hasMembers || (hasMembers = true)) {
|
5140 |
|
|
value = lex();
|
5141 |
|
|
// A closing curly brace marks the end of the object literal.
|
5142 |
|
|
if (value == "}") {
|
5143 |
|
|
break;
|
5144 |
|
|
}
|
5145 |
|
|
// If the object literal contains members, the current token
|
5146 |
|
|
// should be a comma separator.
|
5147 |
|
|
if (hasMembers) {
|
5148 |
|
|
if (value == ",") {
|
5149 |
|
|
value = lex();
|
5150 |
|
|
if (value == "}") {
|
5151 |
|
|
// Unexpected trailing `,` in object literal.
|
5152 |
|
|
abort();
|
5153 |
|
|
}
|
5154 |
|
|
} else {
|
5155 |
|
|
// A `,` must separate each object member.
|
5156 |
|
|
abort();
|
5157 |
|
|
}
|
5158 |
|
|
}
|
5159 |
|
|
// Leading commas are not permitted, object property names must be
|
5160 |
|
|
// double-quoted strings, and a `:` must separate each property
|
5161 |
|
|
// name and value.
|
5162 |
|
|
if (value == "," || typeof value != "string" || (charIndexBuggy ? value.charAt(0) : value[0]) != "@" || lex() != ":") {
|
5163 |
|
|
abort();
|
5164 |
|
|
}
|
5165 |
|
|
results[value.slice(1)] = get(lex());
|
5166 |
|
|
}
|
5167 |
|
|
return results;
|
5168 |
|
|
}
|
5169 |
|
|
// Unexpected token encountered.
|
5170 |
|
|
abort();
|
5171 |
|
|
}
|
5172 |
|
|
return value;
|
5173 |
|
|
};
|
5174 |
|
|
|
5175 |
|
|
// Internal: Updates a traversed object member.
|
5176 |
|
|
var update = function (source, property, callback) {
|
5177 |
|
|
var element = walk(source, property, callback);
|
5178 |
|
|
if (element === undef) {
|
5179 |
|
|
delete source[property];
|
5180 |
|
|
} else {
|
5181 |
|
|
source[property] = element;
|
5182 |
|
|
}
|
5183 |
|
|
};
|
5184 |
|
|
|
5185 |
|
|
// Internal: Recursively traverses a parsed JSON object, invoking the
|
5186 |
|
|
// `callback` function for each value. This is an implementation of the
|
5187 |
|
|
// `Walk(holder, name)` operation defined in ES 5.1 section 15.12.2.
|
5188 |
|
|
var walk = function (source, property, callback) {
|
5189 |
|
|
var value = source[property], length;
|
5190 |
|
|
if (typeof value == "object" && value) {
|
5191 |
|
|
// `forEach` can't be used to traverse an array in Opera <= 8.54
|
5192 |
|
|
// because its `Object#hasOwnProperty` implementation returns `false`
|
5193 |
|
|
// for array indices (e.g., `![1, 2, 3].hasOwnProperty("0")`).
|
5194 |
|
|
if (getClass.call(value) == arrayClass) {
|
5195 |
|
|
for (length = value.length; length--;) {
|
5196 |
|
|
update(value, length, callback);
|
5197 |
|
|
}
|
5198 |
|
|
} else {
|
5199 |
|
|
forEach(value, function (property) {
|
5200 |
|
|
update(value, property, callback);
|
5201 |
|
|
});
|
5202 |
|
|
}
|
5203 |
|
|
}
|
5204 |
|
|
return callback.call(source, property, value);
|
5205 |
|
|
};
|
5206 |
|
|
|
5207 |
|
|
// Public: `JSON.parse`. See ES 5.1 section 15.12.2.
|
5208 |
|
|
exports.parse = function (source, callback) {
|
5209 |
|
|
var result, value;
|
5210 |
|
|
Index = 0;
|
5211 |
|
|
Source = "" + source;
|
5212 |
|
|
result = get(lex());
|
5213 |
|
|
// If a JSON string contains multiple tokens, it is invalid.
|
5214 |
|
|
if (lex() != "$") {
|
5215 |
|
|
abort();
|
5216 |
|
|
}
|
5217 |
|
|
// Reset the parser state.
|
5218 |
|
|
Index = Source = null;
|
5219 |
|
|
return callback && getClass.call(callback) == functionClass ? walk((value = {}, value[""] = result, value), "", callback) : result;
|
5220 |
|
|
};
|
5221 |
|
|
}
|
5222 |
|
|
}
|
5223 |
|
|
|
5224 |
|
|
exports["runInContext"] = runInContext;
|
5225 |
|
|
return exports;
|
5226 |
|
|
}
|
5227 |
|
|
|
5228 |
|
|
if (freeExports && !isLoader) {
|
5229 |
|
|
// Export for CommonJS environments.
|
5230 |
|
|
runInContext(root, freeExports);
|
5231 |
|
|
} else {
|
5232 |
|
|
// Export for web browsers and JavaScript engines.
|
5233 |
|
|
var nativeJSON = root.JSON,
|
5234 |
|
|
previousJSON = root["JSON3"],
|
5235 |
|
|
isRestored = false;
|
5236 |
|
|
|
5237 |
|
|
var JSON3 = runInContext(root, (root["JSON3"] = {
|
5238 |
|
|
// Public: Restores the original value of the global `JSON` object and
|
5239 |
|
|
// returns a reference to the `JSON3` object.
|
5240 |
|
|
"noConflict": function () {
|
5241 |
|
|
if (!isRestored) {
|
5242 |
|
|
isRestored = true;
|
5243 |
|
|
root.JSON = nativeJSON;
|
5244 |
|
|
root["JSON3"] = previousJSON;
|
5245 |
|
|
nativeJSON = previousJSON = null;
|
5246 |
|
|
}
|
5247 |
|
|
return JSON3;
|
5248 |
|
|
}
|
5249 |
|
|
}));
|
5250 |
|
|
|
5251 |
|
|
root.JSON = {
|
5252 |
|
|
"parse": JSON3.parse,
|
5253 |
|
|
"stringify": JSON3.stringify
|
5254 |
|
|
};
|
5255 |
|
|
}
|
5256 |
|
|
|
5257 |
|
|
// Export for asynchronous module loaders.
|
5258 |
|
|
if (isLoader) {
|
5259 |
|
|
define(function () {
|
5260 |
|
|
return JSON3;
|
5261 |
|
|
});
|
5262 |
|
|
}
|
5263 |
|
|
}).call(this);
|
5264 |
|
|
|
5265 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
5266 |
|
|
|
5267 |
|
|
},{}],59:[function(require,module,exports){
|
5268 |
|
|
'use strict';
|
5269 |
|
|
|
5270 |
|
|
var has = Object.prototype.hasOwnProperty;
|
5271 |
|
|
|
5272 |
|
|
/**
|
5273 |
|
|
* Decode a URI encoded string.
|
5274 |
|
|
*
|
5275 |
|
|
* @param {String} input The URI encoded string.
|
5276 |
|
|
* @returns {String} The decoded string.
|
5277 |
|
|
* @api private
|
5278 |
|
|
*/
|
5279 |
|
|
function decode(input) {
|
5280 |
|
|
return decodeURIComponent(input.replace(/\+/g, ' '));
|
5281 |
|
|
}
|
5282 |
|
|
|
5283 |
|
|
/**
|
5284 |
|
|
* Simple query string parser.
|
5285 |
|
|
*
|
5286 |
|
|
* @param {String} query The query string that needs to be parsed.
|
5287 |
|
|
* @returns {Object}
|
5288 |
|
|
* @api public
|
5289 |
|
|
*/
|
5290 |
|
|
function querystring(query) {
|
5291 |
|
|
var parser = /([^=?&]+)=?([^&]*)/g
|
5292 |
|
|
, result = {}
|
5293 |
|
|
, part;
|
5294 |
|
|
|
5295 |
|
|
while (part = parser.exec(query)) {
|
5296 |
|
|
var key = decode(part[1])
|
5297 |
|
|
, value = decode(part[2]);
|
5298 |
|
|
|
5299 |
|
|
//
|
5300 |
|
|
// Prevent overriding of existing properties. This ensures that build-in
|
5301 |
|
|
// methods like `toString` or __proto__ are not overriden by malicious
|
5302 |
|
|
// querystrings.
|
5303 |
|
|
//
|
5304 |
|
|
if (key in result) continue;
|
5305 |
|
|
result[key] = value;
|
5306 |
|
|
}
|
5307 |
|
|
|
5308 |
|
|
return result;
|
5309 |
|
|
}
|
5310 |
|
|
|
5311 |
|
|
/**
|
5312 |
|
|
* Transform a query string to an object.
|
5313 |
|
|
*
|
5314 |
|
|
* @param {Object} obj Object that should be transformed.
|
5315 |
|
|
* @param {String} prefix Optional prefix.
|
5316 |
|
|
* @returns {String}
|
5317 |
|
|
* @api public
|
5318 |
|
|
*/
|
5319 |
|
|
function querystringify(obj, prefix) {
|
5320 |
|
|
prefix = prefix || '';
|
5321 |
|
|
|
5322 |
|
|
var pairs = [];
|
5323 |
|
|
|
5324 |
|
|
//
|
5325 |
|
|
// Optionally prefix with a '?' if needed
|
5326 |
|
|
//
|
5327 |
|
|
if ('string' !== typeof prefix) prefix = '?';
|
5328 |
|
|
|
5329 |
|
|
for (var key in obj) {
|
5330 |
|
|
if (has.call(obj, key)) {
|
5331 |
|
|
pairs.push(encodeURIComponent(key) +'='+ encodeURIComponent(obj[key]));
|
5332 |
|
|
}
|
5333 |
|
|
}
|
5334 |
|
|
|
5335 |
|
|
return pairs.length ? prefix + pairs.join('&') : '';
|
5336 |
|
|
}
|
5337 |
|
|
|
5338 |
|
|
//
|
5339 |
|
|
// Expose the module.
|
5340 |
|
|
//
|
5341 |
|
|
exports.stringify = querystringify;
|
5342 |
|
|
exports.parse = querystring;
|
5343 |
|
|
|
5344 |
|
|
},{}],60:[function(require,module,exports){
|
5345 |
|
|
'use strict';
|
5346 |
|
|
|
5347 |
|
|
/**
|
5348 |
|
|
* Check if we're required to add a port number.
|
5349 |
|
|
*
|
5350 |
|
|
* @see https://url.spec.whatwg.org/#default-port
|
5351 |
|
|
* @param {Number|String} port Port number we need to check
|
5352 |
|
|
* @param {String} protocol Protocol we need to check against.
|
5353 |
|
|
* @returns {Boolean} Is it a default port for the given protocol
|
5354 |
|
|
* @api private
|
5355 |
|
|
*/
|
5356 |
|
|
module.exports = function required(port, protocol) {
|
5357 |
|
|
protocol = protocol.split(':')[0];
|
5358 |
|
|
port = +port;
|
5359 |
|
|
|
5360 |
|
|
if (!port) return false;
|
5361 |
|
|
|
5362 |
|
|
switch (protocol) {
|
5363 |
|
|
case 'http':
|
5364 |
|
|
case 'ws':
|
5365 |
|
|
return port !== 80;
|
5366 |
|
|
|
5367 |
|
|
case 'https':
|
5368 |
|
|
case 'wss':
|
5369 |
|
|
return port !== 443;
|
5370 |
|
|
|
5371 |
|
|
case 'ftp':
|
5372 |
|
|
return port !== 21;
|
5373 |
|
|
|
5374 |
|
|
case 'gopher':
|
5375 |
|
|
return port !== 70;
|
5376 |
|
|
|
5377 |
|
|
case 'file':
|
5378 |
|
|
return false;
|
5379 |
|
|
}
|
5380 |
|
|
|
5381 |
|
|
return port !== 0;
|
5382 |
|
|
};
|
5383 |
|
|
|
5384 |
|
|
},{}],61:[function(require,module,exports){
|
5385 |
|
|
(function (global){
|
5386 |
|
|
'use strict';
|
5387 |
|
|
|
5388 |
|
|
var required = require('requires-port')
|
5389 |
|
|
, qs = require('querystringify')
|
5390 |
|
|
, protocolre = /^([a-z][a-z0-9.+-]*:)?(\/\/)?([\S\s]*)/i
|
5391 |
|
|
, slashes = /^[A-Za-z][A-Za-z0-9+-.]*:\/\//;
|
5392 |
|
|
|
5393 |
|
|
/**
|
5394 |
|
|
* These are the parse rules for the URL parser, it informs the parser
|
5395 |
|
|
* about:
|
5396 |
|
|
*
|
5397 |
|
|
* 0. The char it Needs to parse, if it's a string it should be done using
|
5398 |
|
|
* indexOf, RegExp using exec and NaN means set as current value.
|
5399 |
|
|
* 1. The property we should set when parsing this value.
|
5400 |
|
|
* 2. Indication if it's backwards or forward parsing, when set as number it's
|
5401 |
|
|
* the value of extra chars that should be split off.
|
5402 |
|
|
* 3. Inherit from location if non existing in the parser.
|
5403 |
|
|
* 4. `toLowerCase` the resulting value.
|
5404 |
|
|
*/
|
5405 |
|
|
var rules = [
|
5406 |
|
|
['#', 'hash'], // Extract from the back.
|
5407 |
|
|
['?', 'query'], // Extract from the back.
|
5408 |
|
|
function sanitize(address) { // Sanitize what is left of the address
|
5409 |
|
|
return address.replace('\\', '/');
|
5410 |
|
|
},
|
5411 |
|
|
['/', 'pathname'], // Extract from the back.
|
5412 |
|
|
['@', 'auth', 1], // Extract from the front.
|
5413 |
|
|
[NaN, 'host', undefined, 1, 1], // Set left over value.
|
5414 |
|
|
[/:(\d+)$/, 'port', undefined, 1], // RegExp the back.
|
5415 |
|
|
[NaN, 'hostname', undefined, 1, 1] // Set left over.
|
5416 |
|
|
];
|
5417 |
|
|
|
5418 |
|
|
/**
|
5419 |
|
|
* These properties should not be copied or inherited from. This is only needed
|
5420 |
|
|
* for all non blob URL's as a blob URL does not include a hash, only the
|
5421 |
|
|
* origin.
|
5422 |
|
|
*
|
5423 |
|
|
* @type {Object}
|
5424 |
|
|
* @private
|
5425 |
|
|
*/
|
5426 |
|
|
var ignore = { hash: 1, query: 1 };
|
5427 |
|
|
|
5428 |
|
|
/**
|
5429 |
|
|
* The location object differs when your code is loaded through a normal page,
|
5430 |
|
|
* Worker or through a worker using a blob. And with the blobble begins the
|
5431 |
|
|
* trouble as the location object will contain the URL of the blob, not the
|
5432 |
|
|
* location of the page where our code is loaded in. The actual origin is
|
5433 |
|
|
* encoded in the `pathname` so we can thankfully generate a good "default"
|
5434 |
|
|
* location from it so we can generate proper relative URL's again.
|
5435 |
|
|
*
|
5436 |
|
|
* @param {Object|String} loc Optional default location object.
|
5437 |
|
|
* @returns {Object} lolcation object.
|
5438 |
|
|
* @public
|
5439 |
|
|
*/
|
5440 |
|
|
function lolcation(loc) {
|
5441 |
|
|
var location = global && global.location || {};
|
5442 |
|
|
loc = loc || location;
|
5443 |
|
|
|
5444 |
|
|
var finaldestination = {}
|
5445 |
|
|
, type = typeof loc
|
5446 |
|
|
, key;
|
5447 |
|
|
|
5448 |
|
|
if ('blob:' === loc.protocol) {
|
5449 |
|
|
finaldestination = new Url(unescape(loc.pathname), {});
|
5450 |
|
|
} else if ('string' === type) {
|
5451 |
|
|
finaldestination = new Url(loc, {});
|
5452 |
|
|
for (key in ignore) delete finaldestination[key];
|
5453 |
|
|
} else if ('object' === type) {
|
5454 |
|
|
for (key in loc) {
|
5455 |
|
|
if (key in ignore) continue;
|
5456 |
|
|
finaldestination[key] = loc[key];
|
5457 |
|
|
}
|
5458 |
|
|
|
5459 |
|
|
if (finaldestination.slashes === undefined) {
|
5460 |
|
|
finaldestination.slashes = slashes.test(loc.href);
|
5461 |
|
|
}
|
5462 |
|
|
}
|
5463 |
|
|
|
5464 |
|
|
return finaldestination;
|
5465 |
|
|
}
|
5466 |
|
|
|
5467 |
|
|
/**
|
5468 |
|
|
* @typedef ProtocolExtract
|
5469 |
|
|
* @type Object
|
5470 |
|
|
* @property {String} protocol Protocol matched in the URL, in lowercase.
|
5471 |
|
|
* @property {Boolean} slashes `true` if protocol is followed by "//", else `false`.
|
5472 |
|
|
* @property {String} rest Rest of the URL that is not part of the protocol.
|
5473 |
|
|
*/
|
5474 |
|
|
|
5475 |
|
|
/**
|
5476 |
|
|
* Extract protocol information from a URL with/without double slash ("//").
|
5477 |
|
|
*
|
5478 |
|
|
* @param {String} address URL we want to extract from.
|
5479 |
|
|
* @return {ProtocolExtract} Extracted information.
|
5480 |
|
|
* @private
|
5481 |
|
|
*/
|
5482 |
|
|
function extractProtocol(address) {
|
5483 |
|
|
var match = protocolre.exec(address);
|
5484 |
|
|
|
5485 |
|
|
return {
|
5486 |
|
|
protocol: match[1] ? match[1].toLowerCase() : '',
|
5487 |
|
|
slashes: !!match[2],
|
5488 |
|
|
rest: match[3]
|
5489 |
|
|
};
|
5490 |
|
|
}
|
5491 |
|
|
|
5492 |
|
|
/**
|
5493 |
|
|
* Resolve a relative URL pathname against a base URL pathname.
|
5494 |
|
|
*
|
5495 |
|
|
* @param {String} relative Pathname of the relative URL.
|
5496 |
|
|
* @param {String} base Pathname of the base URL.
|
5497 |
|
|
* @return {String} Resolved pathname.
|
5498 |
|
|
* @private
|
5499 |
|
|
*/
|
5500 |
|
|
function resolve(relative, base) {
|
5501 |
|
|
var path = (base || '/').split('/').slice(0, -1).concat(relative.split('/'))
|
5502 |
|
|
, i = path.length
|
5503 |
|
|
, last = path[i - 1]
|
5504 |
|
|
, unshift = false
|
5505 |
|
|
, up = 0;
|
5506 |
|
|
|
5507 |
|
|
while (i--) {
|
5508 |
|
|
if (path[i] === '.') {
|
5509 |
|
|
path.splice(i, 1);
|
5510 |
|
|
} else if (path[i] === '..') {
|
5511 |
|
|
path.splice(i, 1);
|
5512 |
|
|
up++;
|
5513 |
|
|
} else if (up) {
|
5514 |
|
|
if (i === 0) unshift = true;
|
5515 |
|
|
path.splice(i, 1);
|
5516 |
|
|
up--;
|
5517 |
|
|
}
|
5518 |
|
|
}
|
5519 |
|
|
|
5520 |
|
|
if (unshift) path.unshift('');
|
5521 |
|
|
if (last === '.' || last === '..') path.push('');
|
5522 |
|
|
|
5523 |
|
|
return path.join('/');
|
5524 |
|
|
}
|
5525 |
|
|
|
5526 |
|
|
/**
|
5527 |
|
|
* The actual URL instance. Instead of returning an object we've opted-in to
|
5528 |
|
|
* create an actual constructor as it's much more memory efficient and
|
5529 |
|
|
* faster and it pleases my OCD.
|
5530 |
|
|
*
|
5531 |
|
|
* It is worth noting that we should not use `URL` as class name to prevent
|
5532 |
|
|
* clashes with the global URL instance that got introduced in browsers.
|
5533 |
|
|
*
|
5534 |
|
|
* @constructor
|
5535 |
|
|
* @param {String} address URL we want to parse.
|
5536 |
|
|
* @param {Object|String} location Location defaults for relative paths.
|
5537 |
|
|
* @param {Boolean|Function} parser Parser for the query string.
|
5538 |
|
|
* @private
|
5539 |
|
|
*/
|
5540 |
|
|
function Url(address, location, parser) {
|
5541 |
|
|
if (!(this instanceof Url)) {
|
5542 |
|
|
return new Url(address, location, parser);
|
5543 |
|
|
}
|
5544 |
|
|
|
5545 |
|
|
var relative, extracted, parse, instruction, index, key
|
5546 |
|
|
, instructions = rules.slice()
|
5547 |
|
|
, type = typeof location
|
5548 |
|
|
, url = this
|
5549 |
|
|
, i = 0;
|
5550 |
|
|
|
5551 |
|
|
//
|
5552 |
|
|
// The following if statements allows this module two have compatibility with
|
5553 |
|
|
// 2 different API:
|
5554 |
|
|
//
|
5555 |
|
|
// 1. Node.js's `url.parse` api which accepts a URL, boolean as arguments
|
5556 |
|
|
// where the boolean indicates that the query string should also be parsed.
|
5557 |
|
|
//
|
5558 |
|
|
// 2. The `URL` interface of the browser which accepts a URL, object as
|
5559 |
|
|
// arguments. The supplied object will be used as default values / fall-back
|
5560 |
|
|
// for relative paths.
|
5561 |
|
|
//
|
5562 |
|
|
if ('object' !== type && 'string' !== type) {
|
5563 |
|
|
parser = location;
|
5564 |
|
|
location = null;
|
5565 |
|
|
}
|
5566 |
|
|
|
5567 |
|
|
if (parser && 'function' !== typeof parser) parser = qs.parse;
|
5568 |
|
|
|
5569 |
|
|
location = lolcation(location);
|
5570 |
|
|
|
5571 |
|
|
//
|
5572 |
|
|
// Extract protocol information before running the instructions.
|
5573 |
|
|
//
|
5574 |
|
|
extracted = extractProtocol(address || '');
|
5575 |
|
|
relative = !extracted.protocol && !extracted.slashes;
|
5576 |
|
|
url.slashes = extracted.slashes || relative && location.slashes;
|
5577 |
|
|
url.protocol = extracted.protocol || location.protocol || '';
|
5578 |
|
|
address = extracted.rest;
|
5579 |
|
|
|
5580 |
|
|
//
|
5581 |
|
|
// When the authority component is absent the URL starts with a path
|
5582 |
|
|
// component.
|
5583 |
|
|
//
|
5584 |
|
|
if (!extracted.slashes) instructions[3] = [/(.*)/, 'pathname'];
|
5585 |
|
|
|
5586 |
|
|
for (; i < instructions.length; i++) {
|
5587 |
|
|
instruction = instructions[i];
|
5588 |
|
|
|
5589 |
|
|
if (typeof instruction === 'function') {
|
5590 |
|
|
address = instruction(address);
|
5591 |
|
|
continue;
|
5592 |
|
|
}
|
5593 |
|
|
|
5594 |
|
|
parse = instruction[0];
|
5595 |
|
|
key = instruction[1];
|
5596 |
|
|
|
5597 |
|
|
if (parse !== parse) {
|
5598 |
|
|
url[key] = address;
|
5599 |
|
|
} else if ('string' === typeof parse) {
|
5600 |
|
|
if (~(index = address.indexOf(parse))) {
|
5601 |
|
|
if ('number' === typeof instruction[2]) {
|
5602 |
|
|
url[key] = address.slice(0, index);
|
5603 |
|
|
address = address.slice(index + instruction[2]);
|
5604 |
|
|
} else {
|
5605 |
|
|
url[key] = address.slice(index);
|
5606 |
|
|
address = address.slice(0, index);
|
5607 |
|
|
}
|
5608 |
|
|
}
|
5609 |
|
|
} else if ((index = parse.exec(address))) {
|
5610 |
|
|
url[key] = index[1];
|
5611 |
|
|
address = address.slice(0, index.index);
|
5612 |
|
|
}
|
5613 |
|
|
|
5614 |
|
|
url[key] = url[key] || (
|
5615 |
|
|
relative && instruction[3] ? location[key] || '' : ''
|
5616 |
|
|
);
|
5617 |
|
|
|
5618 |
|
|
//
|
5619 |
|
|
// Hostname, host and protocol should be lowercased so they can be used to
|
5620 |
|
|
// create a proper `origin`.
|
5621 |
|
|
//
|
5622 |
|
|
if (instruction[4]) url[key] = url[key].toLowerCase();
|
5623 |
|
|
}
|
5624 |
|
|
|
5625 |
|
|
//
|
5626 |
|
|
// Also parse the supplied query string in to an object. If we're supplied
|
5627 |
|
|
// with a custom parser as function use that instead of the default build-in
|
5628 |
|
|
// parser.
|
5629 |
|
|
//
|
5630 |
|
|
if (parser) url.query = parser(url.query);
|
5631 |
|
|
|
5632 |
|
|
//
|
5633 |
|
|
// If the URL is relative, resolve the pathname against the base URL.
|
5634 |
|
|
//
|
5635 |
|
|
if (
|
5636 |
|
|
relative
|
5637 |
|
|
&& location.slashes
|
5638 |
|
|
&& url.pathname.charAt(0) !== '/'
|
5639 |
|
|
&& (url.pathname !== '' || location.pathname !== '')
|
5640 |
|
|
) {
|
5641 |
|
|
url.pathname = resolve(url.pathname, location.pathname);
|
5642 |
|
|
}
|
5643 |
|
|
|
5644 |
|
|
//
|
5645 |
|
|
// We should not add port numbers if they are already the default port number
|
5646 |
|
|
// for a given protocol. As the host also contains the port number we're going
|
5647 |
|
|
// override it with the hostname which contains no port number.
|
5648 |
|
|
//
|
5649 |
|
|
if (!required(url.port, url.protocol)) {
|
5650 |
|
|
url.host = url.hostname;
|
5651 |
|
|
url.port = '';
|
5652 |
|
|
}
|
5653 |
|
|
|
5654 |
|
|
//
|
5655 |
|
|
// Parse down the `auth` for the username and password.
|
5656 |
|
|
//
|
5657 |
|
|
url.username = url.password = '';
|
5658 |
|
|
if (url.auth) {
|
5659 |
|
|
instruction = url.auth.split(':');
|
5660 |
|
|
url.username = instruction[0] || '';
|
5661 |
|
|
url.password = instruction[1] || '';
|
5662 |
|
|
}
|
5663 |
|
|
|
5664 |
|
|
url.origin = url.protocol && url.host && url.protocol !== 'file:'
|
5665 |
|
|
? url.protocol +'//'+ url.host
|
5666 |
|
|
: 'null';
|
5667 |
|
|
|
5668 |
|
|
//
|
5669 |
|
|
// The href is just the compiled result.
|
5670 |
|
|
//
|
5671 |
|
|
url.href = url.toString();
|
5672 |
|
|
}
|
5673 |
|
|
|
5674 |
|
|
/**
|
5675 |
|
|
* This is convenience method for changing properties in the URL instance to
|
5676 |
|
|
* insure that they all propagate correctly.
|
5677 |
|
|
*
|
5678 |
|
|
* @param {String} part Property we need to adjust.
|
5679 |
|
|
* @param {Mixed} value The newly assigned value.
|
5680 |
|
|
* @param {Boolean|Function} fn When setting the query, it will be the function
|
5681 |
|
|
* used to parse the query.
|
5682 |
|
|
* When setting the protocol, double slash will be
|
5683 |
|
|
* removed from the final url if it is true.
|
5684 |
|
|
* @returns {URL} URL instance for chaining.
|
5685 |
|
|
* @public
|
5686 |
|
|
*/
|
5687 |
|
|
function set(part, value, fn) {
|
5688 |
|
|
var url = this;
|
5689 |
|
|
|
5690 |
|
|
switch (part) {
|
5691 |
|
|
case 'query':
|
5692 |
|
|
if ('string' === typeof value && value.length) {
|
5693 |
|
|
value = (fn || qs.parse)(value);
|
5694 |
|
|
}
|
5695 |
|
|
|
5696 |
|
|
url[part] = value;
|
5697 |
|
|
break;
|
5698 |
|
|
|
5699 |
|
|
case 'port':
|
5700 |
|
|
url[part] = value;
|
5701 |
|
|
|
5702 |
|
|
if (!required(value, url.protocol)) {
|
5703 |
|
|
url.host = url.hostname;
|
5704 |
|
|
url[part] = '';
|
5705 |
|
|
} else if (value) {
|
5706 |
|
|
url.host = url.hostname +':'+ value;
|
5707 |
|
|
}
|
5708 |
|
|
|
5709 |
|
|
break;
|
5710 |
|
|
|
5711 |
|
|
case 'hostname':
|
5712 |
|
|
url[part] = value;
|
5713 |
|
|
|
5714 |
|
|
if (url.port) value += ':'+ url.port;
|
5715 |
|
|
url.host = value;
|
5716 |
|
|
break;
|
5717 |
|
|
|
5718 |
|
|
case 'host':
|
5719 |
|
|
url[part] = value;
|
5720 |
|
|
|
5721 |
|
|
if (/:\d+$/.test(value)) {
|
5722 |
|
|
value = value.split(':');
|
5723 |
|
|
url.port = value.pop();
|
5724 |
|
|
url.hostname = value.join(':');
|
5725 |
|
|
} else {
|
5726 |
|
|
url.hostname = value;
|
5727 |
|
|
url.port = '';
|
5728 |
|
|
}
|
5729 |
|
|
|
5730 |
|
|
break;
|
5731 |
|
|
|
5732 |
|
|
case 'protocol':
|
5733 |
|
|
url.protocol = value.toLowerCase();
|
5734 |
|
|
url.slashes = !fn;
|
5735 |
|
|
break;
|
5736 |
|
|
|
5737 |
|
|
case 'pathname':
|
5738 |
|
|
case 'hash':
|
5739 |
|
|
if (value) {
|
5740 |
|
|
var char = part === 'pathname' ? '/' : '#';
|
5741 |
|
|
url[part] = value.charAt(0) !== char ? char + value : value;
|
5742 |
|
|
} else {
|
5743 |
|
|
url[part] = value;
|
5744 |
|
|
}
|
5745 |
|
|
break;
|
5746 |
|
|
|
5747 |
|
|
default:
|
5748 |
|
|
url[part] = value;
|
5749 |
|
|
}
|
5750 |
|
|
|
5751 |
|
|
for (var i = 0; i < rules.length; i++) {
|
5752 |
|
|
var ins = rules[i];
|
5753 |
|
|
|
5754 |
|
|
if (ins[4]) url[ins[1]] = url[ins[1]].toLowerCase();
|
5755 |
|
|
}
|
5756 |
|
|
|
5757 |
|
|
url.origin = url.protocol && url.host && url.protocol !== 'file:'
|
5758 |
|
|
? url.protocol +'//'+ url.host
|
5759 |
|
|
: 'null';
|
5760 |
|
|
|
5761 |
|
|
url.href = url.toString();
|
5762 |
|
|
|
5763 |
|
|
return url;
|
5764 |
|
|
}
|
5765 |
|
|
|
5766 |
|
|
/**
|
5767 |
|
|
* Transform the properties back in to a valid and full URL string.
|
5768 |
|
|
*
|
5769 |
|
|
* @param {Function} stringify Optional query stringify function.
|
5770 |
|
|
* @returns {String} Compiled version of the URL.
|
5771 |
|
|
* @public
|
5772 |
|
|
*/
|
5773 |
|
|
function toString(stringify) {
|
5774 |
|
|
if (!stringify || 'function' !== typeof stringify) stringify = qs.stringify;
|
5775 |
|
|
|
5776 |
|
|
var query
|
5777 |
|
|
, url = this
|
5778 |
|
|
, protocol = url.protocol;
|
5779 |
|
|
|
5780 |
|
|
if (protocol && protocol.charAt(protocol.length - 1) !== ':') protocol += ':';
|
5781 |
|
|
|
5782 |
|
|
var result = protocol + (url.slashes ? '//' : '');
|
5783 |
|
|
|
5784 |
|
|
if (url.username) {
|
5785 |
|
|
result += url.username;
|
5786 |
|
|
if (url.password) result += ':'+ url.password;
|
5787 |
|
|
result += '@';
|
5788 |
|
|
}
|
5789 |
|
|
|
5790 |
|
|
result += url.host + url.pathname;
|
5791 |
|
|
|
5792 |
|
|
query = 'object' === typeof url.query ? stringify(url.query) : url.query;
|
5793 |
|
|
if (query) result += '?' !== query.charAt(0) ? '?'+ query : query;
|
5794 |
|
|
|
5795 |
|
|
if (url.hash) result += url.hash;
|
5796 |
|
|
|
5797 |
|
|
return result;
|
5798 |
|
|
}
|
5799 |
|
|
|
5800 |
|
|
Url.prototype = { set: set, toString: toString };
|
5801 |
|
|
|
5802 |
|
|
//
|
5803 |
|
|
// Expose the URL parser and some additional properties that might be useful for
|
5804 |
|
|
// others or testing.
|
5805 |
|
|
//
|
5806 |
|
|
Url.extractProtocol = extractProtocol;
|
5807 |
|
|
Url.location = lolcation;
|
5808 |
|
|
Url.qs = qs;
|
5809 |
|
|
|
5810 |
|
|
module.exports = Url;
|
5811 |
|
|
|
5812 |
|
|
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
5813 |
|
|
|
5814 |
|
|
},{"querystringify":59,"requires-port":60}]},{},[1])(1)
|
5815 |
|
|
});
|
5816 |
|
|
|
5817 |
|
|
|
5818 |
|
|
//# sourceMappingURL=sockjs.js.map
|