1 | 'use strict';
|
---|
2 |
|
---|
3 | var inherits = require('inherits')
|
---|
4 | , AjaxBasedTransport = require('./lib/ajax-based')
|
---|
5 | , XhrReceiver = require('./receiver/xhr')
|
---|
6 | , XHRCorsObject = require('./sender/xhr-cors')
|
---|
7 | , XHRLocalObject = require('./sender/xhr-local')
|
---|
8 | , browser = require('../utils/browser')
|
---|
9 | ;
|
---|
10 |
|
---|
11 | function XhrStreamingTransport(transUrl) {
|
---|
12 | if (!XHRLocalObject.enabled && !XHRCorsObject.enabled) {
|
---|
13 | throw new Error('Transport created when disabled');
|
---|
14 | }
|
---|
15 | AjaxBasedTransport.call(this, transUrl, '/xhr_streaming', XhrReceiver, XHRCorsObject);
|
---|
16 | }
|
---|
17 |
|
---|
18 | inherits(XhrStreamingTransport, AjaxBasedTransport);
|
---|
19 |
|
---|
20 | XhrStreamingTransport.enabled = function(info) {
|
---|
21 | if (info.nullOrigin) {
|
---|
22 | return false;
|
---|
23 | }
|
---|
24 | // Opera doesn't support xhr-streaming #60
|
---|
25 | // But it might be able to #92
|
---|
26 | if (browser.isOpera()) {
|
---|
27 | return false;
|
---|
28 | }
|
---|
29 |
|
---|
30 | return XHRCorsObject.enabled;
|
---|
31 | };
|
---|
32 |
|
---|
33 | XhrStreamingTransport.transportName = 'xhr-streaming';
|
---|
34 | XhrStreamingTransport.roundTrips = 2; // preflight, ajax
|
---|
35 |
|
---|
36 | // Safari gets confused when a streaming ajax request is started
|
---|
37 | // before onload. This causes the load indicator to spin indefinetely.
|
---|
38 | // Only require body when used in a browser
|
---|
39 | XhrStreamingTransport.needBody = !!global.document;
|
---|
40 |
|
---|
41 | module.exports = XhrStreamingTransport;
|
---|