diff --git a/ApiClient.js b/ApiClient.js index 94dc72d543..5381a7abd4 100644 --- a/ApiClient.js +++ b/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,16 +104,19 @@ 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 + '"'; + + if (currentUserId) { + auth += ', UserId="' + currentUserId + '"'; + } + + request.headers = { + Authorization: auth + }; } - 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 diff --git a/packages.config b/packages.config index cd8da27323..5599c176d5 100644 --- a/packages.config +++ b/packages.config @@ -1,6 +1,6 @@  - + \ No newline at end of file