aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.WebDashboard/ApiClient.js
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-03-25 23:01:47 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-03-25 23:01:47 -0400
commita6c9fdd0f26201a49dd9d2d3365f713104230eaa (patch)
tree9b0e94fbcde7515731db0d72e99ee36271538637 /MediaBrowser.WebDashboard/ApiClient.js
parent3a5e1521ed3516870ac73b3c5d2f364ec96ba7a2 (diff)
Moved some web socket classes to the model
Diffstat (limited to 'MediaBrowser.WebDashboard/ApiClient.js')
-rw-r--r--MediaBrowser.WebDashboard/ApiClient.js136
1 files changed, 73 insertions, 63 deletions
diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js
index 94dc72d54..5381a7abd 100644
--- a/MediaBrowser.WebDashboard/ApiClient.js
+++ b/MediaBrowser.WebDashboard/ApiClient.js
@@ -1,54 +1,4 @@
-(function (jQuery, window, undefined) {
- "use strict";
-
- var matched, browser;
-
- jQuery.uaMatch = function (ua) {
- ua = ua.toLowerCase();
-
- var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
- /(webkit)[ \/]([\w.]+)/.exec(ua) ||
- /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
- /(msie) ([\w.]+)/.exec(ua) ||
- ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
- [];
-
- var platform_match = /(ipad)/.exec(ua) ||
- /(iphone)/.exec(ua) ||
- /(android)/.exec(ua) ||
- [];
-
- return {
- browser: match[1] || "",
- version: match[2] || "0",
- platform: platform_match[0] || ""
- };
- };
-
- matched = jQuery.uaMatch(window.navigator.userAgent);
- browser = {};
-
- if (matched.browser) {
- browser[matched.browser] = true;
- browser.version = matched.version;
- }
-
- if (matched.platform) {
- browser[matched.platform] = true
- }
-
- // Chrome is Webkit, but Webkit is also Safari.
- if (browser.chrome) {
- browser.webkit = true;
- } else if (browser.webkit) {
- browser.safari = true;
- }
-
- jQuery.browser = browser;
-
-})(jQuery, window);
-
-if (!window.MediaBrowser) {
+if (!window.MediaBrowser) {
window.MediaBrowser = {};
}
@@ -63,6 +13,16 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
*/
return function (serverProtocol, serverHostName, serverPortNumber, clientName) {
+ if (!serverProtocol) {
+ throw new Error("Must supply a serverProtocol, e.g. http:");
+ }
+ if (!serverHostName) {
+ throw new Error("Must supply serverHostName, e.g. 192.168.1.1 or myServerName");
+ }
+ if (!serverPortNumber) {
+ throw new Error("Must supply a serverPortNumber");
+ }
+
var self = this;
var deviceName = "Web Browser";
var deviceId = MediaBrowser.SHA1(navigator.userAgent + (navigator.cpuClass || ""));
@@ -113,10 +73,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
else if ($.browser.msie) {
name = "Internet Explorer";
}
- else if ($.browser.firefox) {
- name = "Firefox";
- }
- else if ($.browser.mozilla) {
+ else if ($.browser.firefox || $.browser.mozilla) {
name = "Firefox";
}
else if ($.browser.opera) {
@@ -147,15 +104,18 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
throw new Error("Request cannot be null");
}
- var auth = 'MediaBrowser Client="' + clientName + '", Device="' + deviceName + '", DeviceId="' + deviceId + '"';
+ if (clientName) {
- if (currentUserId) {
- auth += ', UserId="' + currentUserId + '"';
- }
+ var auth = 'MediaBrowser Client="' + clientName + '", Device="' + deviceName + '", DeviceId="' + deviceId + '"';
- request.headers = {
- Authorization: auth
- };
+ if (currentUserId) {
+ auth += ', UserId="' + currentUserId + '"';
+ }
+
+ request.headers = {
+ Authorization: auth
+ };
+ }
return $.ajax(request);
};
@@ -1933,4 +1893,54 @@ MediaBrowser.SHA1 = function (msg) {
var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
return temp.toLowerCase();
-}; \ No newline at end of file
+};
+
+(function (jQuery, window, undefined) {
+ "use strict";
+
+ var matched, browser;
+
+ jQuery.uaMatch = function (ua) {
+ ua = ua.toLowerCase();
+
+ var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
+ /(webkit)[ \/]([\w.]+)/.exec(ua) ||
+ /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
+ /(msie) ([\w.]+)/.exec(ua) ||
+ ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
+ [];
+
+ var platform_match = /(ipad)/.exec(ua) ||
+ /(iphone)/.exec(ua) ||
+ /(android)/.exec(ua) ||
+ [];
+
+ return {
+ browser: match[1] || "",
+ version: match[2] || "0",
+ platform: platform_match[0] || ""
+ };
+ };
+
+ matched = jQuery.uaMatch(window.navigator.userAgent);
+ browser = {};
+
+ if (matched.browser) {
+ browser[matched.browser] = true;
+ browser.version = matched.version;
+ }
+
+ if (matched.platform) {
+ browser[matched.platform] = true
+ }
+
+ // Chrome is Webkit, but Webkit is also Safari.
+ if (browser.chrome) {
+ browser.webkit = true;
+ } else if (browser.webkit) {
+ browser.safari = true;
+ }
+
+ jQuery.browser = browser;
+
+})(jQuery, window); \ No newline at end of file