c64d4a02 by David LaPalomento

Merge pull request #35 from videojs/withcredentials

Withcredentials
2 parents 45ec53ae 5587efc9
...@@ -13,27 +13,28 @@ ...@@ -13,27 +13,28 @@
13 "test": "grunt test-local" 13 "test": "grunt test-local"
14 }, 14 },
15 "devDependencies": { 15 "devDependencies": {
16 "grunt": "~0.4.1",
17 "grunt-concurrent": "0.4.3",
18 "grunt-contrib-clean": "~0.4.0",
19 "grunt-contrib-concat": "~0.3.0",
20 "grunt-contrib-connect": "~0.6.0",
16 "grunt-contrib-jshint": "~0.6.0", 21 "grunt-contrib-jshint": "~0.6.0",
17 "grunt-contrib-qunit": "~0.2.0", 22 "grunt-contrib-qunit": "~0.2.0",
18 "grunt-contrib-concat": "~0.3.0",
19 "grunt-contrib-uglify": "~0.2.0", 23 "grunt-contrib-uglify": "~0.2.0",
20 "grunt-contrib-watch": "~0.4.0", 24 "grunt-contrib-watch": "~0.4.0",
21 "grunt-contrib-clean": "~0.4.0", 25 "grunt-karma": "~0.6.2",
22 "grunt-contrib-connect": "~0.6.0",
23 "grunt-concurrent": "0.4.3",
24 "grunt-open": "0.2.3", 26 "grunt-open": "0.2.3",
25 "grunt-shell": "0.6.1", 27 "grunt-shell": "0.6.1",
26 "grunt": "~0.4.1",
27 "grunt-karma": "~0.6.2",
28 "karma": "~0.10.0", 28 "karma": "~0.10.0",
29 "karma-sauce-launcher": "~0.1.8",
30 "karma-chrome-launcher": "~0.1.2", 29 "karma-chrome-launcher": "~0.1.2",
31 "karma-firefox-launcher": "~0.1.3", 30 "karma-firefox-launcher": "~0.1.3",
32 "karma-ie-launcher": "~0.1.1", 31 "karma-ie-launcher": "~0.1.1",
33 "karma-opera-launcher": "~0.1.0", 32 "karma-opera-launcher": "~0.1.0",
34 "karma-phantomjs-launcher": "~0.1.1", 33 "karma-phantomjs-launcher": "~0.1.1",
35 "karma-safari-launcher": "~0.1.1",
36 "karma-qunit": "~0.1.1", 34 "karma-qunit": "~0.1.1",
35 "karma-safari-launcher": "~0.1.1",
36 "karma-sauce-launcher": "~0.1.8",
37 "sinon": "^1.9.1",
37 "video.js": "^4.5" 38 "video.js": "^4.5"
38 }, 39 },
39 "peerDependencies": { 40 "peerDependencies": {
......
...@@ -31,6 +31,9 @@ videojs.hls = { ...@@ -31,6 +31,9 @@ videojs.hls = {
31 }; 31 };
32 32
33 var 33 var
34
35 settings,
36
34 // the desired length of video to maintain in the buffer, in seconds 37 // the desired length of video to maintain in the buffer, in seconds
35 goalBufferLength = 5, 38 goalBufferLength = 5,
36 39
...@@ -109,12 +112,26 @@ var ...@@ -109,12 +112,26 @@ var
109 method: 'GET' 112 method: 'GET'
110 }, 113 },
111 request; 114 request;
115
116 if (typeof callback !== 'function') {
117 callback = function() {};
118 }
119
112 if (typeof url === 'object') { 120 if (typeof url === 'object') {
113 options = videojs.util.mergeOptions(options, url); 121 options = videojs.util.mergeOptions(options, url);
114 url = options.url; 122 url = options.url;
115 } 123 }
124
116 request = new window.XMLHttpRequest(); 125 request = new window.XMLHttpRequest();
117 request.open(options.method, url); 126 request.open(options.method, url);
127
128 if (options.responseType) {
129 request.responseType = options.responseType;
130 }
131 if (settings.withCredentials) {
132 request.withCredentials = true;
133 }
134
118 request.onreadystatechange = function() { 135 request.onreadystatechange = function() {
119 // wait until the request completes 136 // wait until the request completes
120 if (this.readyState !== 4) { 137 if (this.readyState !== 4) {
...@@ -286,6 +303,8 @@ var ...@@ -286,6 +303,8 @@ var
286 return; 303 return;
287 } 304 }
288 305
306 settings = videojs.util.mergeOptions({}, options);
307
289 srcUrl = (function() { 308 srcUrl = (function() {
290 var 309 var
291 extname, 310 extname,
...@@ -299,7 +318,7 @@ var ...@@ -299,7 +318,7 @@ var
299 // use the URL specified in options if one was provided 318 // use the URL specified in options if one was provided
300 if (typeof options === 'string') { 319 if (typeof options === 'string') {
301 return options; 320 return options;
302 } else if (options) { 321 } else if (options && options.url) {
303 return options.url; 322 return options.url;
304 } 323 }
305 324
...@@ -627,24 +646,20 @@ var ...@@ -627,24 +646,20 @@ var
627 segment.uri); 646 segment.uri);
628 } 647 }
629 648
630 // request the next segment 649 startTime = +new Date();
631 segmentXhr = new window.XMLHttpRequest();
632 segmentXhr.open('GET', segmentUri);
633 segmentXhr.responseType = 'arraybuffer';
634 segmentXhr.onreadystatechange = function() {
635 // wait until the request completes
636 if (this.readyState !== 4) {
637 return;
638 }
639 650
651 // request the next segment
652 segmentXhr = xhr({
653 url: segmentUri,
654 responseType: 'arraybuffer'
655 }, function(error, url) {
640 // the segment request is no longer outstanding 656 // the segment request is no longer outstanding
641 segmentXhr = null; 657 segmentXhr = null;
642 658
643 // trigger an error if the request was not successful 659 if (error) {
644 if (this.status >= 400) {
645 player.hls.error = { 660 player.hls.error = {
646 status: this.status, 661 status: this.status,
647 message: 'HLS segment request error at URL: ' + segmentUri, 662 message: 'HLS segment request error at URL: ' + url,
648 code: (this.status >= 500) ? 4 : 2 663 code: (this.status >= 500) ? 4 : 2
649 }; 664 };
650 665
...@@ -694,9 +709,7 @@ var ...@@ -694,9 +709,7 @@ var
694 // figure out what stream the next segment should be downloaded from 709 // figure out what stream the next segment should be downloaded from
695 // with the updated bandwidth information 710 // with the updated bandwidth information
696 updateCurrentPlaylist(); 711 updateCurrentPlaylist();
697 }; 712 });
698 startTime = +new Date();
699 segmentXhr.send(null);
700 }; 713 };
701 714
702 // load the MediaSource into the player 715 // load the MediaSource into the player
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
28 "strictEqual", 28 "strictEqual",
29 "notStrictEqual", 29 "notStrictEqual",
30 "throws", 30 "throws",
31 "sinon",
31 "process" 32 "process"
32 ] 33 ]
33 } 34 }
......
...@@ -3,6 +3,12 @@ ...@@ -3,6 +3,12 @@
3 <head> 3 <head>
4 <meta charset="utf-8"> 4 <meta charset="utf-8">
5 <title>video.js HLS Plugin Test Suite</title> 5 <title>video.js HLS Plugin Test Suite</title>
6 <!-- Load sinon server for fakeXHR -->
7 <script src="../node_modules/sinon/lib/sinon.js"></script>
8 <script src="../node_modules/sinon/lib/sinon/util/event.js"></script>
9 <script src="../node_modules/sinon/lib/sinon/util/xhr_ie.js"></script>
10 <script src="../node_modules/sinon/lib/sinon/util/fake_xml_http_request.js"></script>
11
6 <!-- Load local QUnit. --> 12 <!-- Load local QUnit. -->
7 <link rel="stylesheet" href="../libs/qunit/qunit.css" media="screen"> 13 <link rel="stylesheet" href="../libs/qunit/qunit.css" media="screen">
8 <script src="../libs/qunit/qunit.js"></script> 14 <script src="../libs/qunit/qunit.js"></script>
......