Moved some web socket classes to the model
This commit is contained in:
parent
78e7572d76
commit
2936fc63a1
2 changed files with 74 additions and 64 deletions
136
ApiClient.js
136
ApiClient.js
|
@ -1,54 +1,4 @@
|
||||||
(function (jQuery, window, undefined) {
|
if (!window.MediaBrowser) {
|
||||||
"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) {
|
|
||||||
window.MediaBrowser = {};
|
window.MediaBrowser = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +13,16 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
|
||||||
*/
|
*/
|
||||||
return function (serverProtocol, serverHostName, serverPortNumber, clientName) {
|
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 self = this;
|
||||||
var deviceName = "Web Browser";
|
var deviceName = "Web Browser";
|
||||||
var deviceId = MediaBrowser.SHA1(navigator.userAgent + (navigator.cpuClass || ""));
|
var deviceId = MediaBrowser.SHA1(navigator.userAgent + (navigator.cpuClass || ""));
|
||||||
|
@ -113,10 +73,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
|
||||||
else if ($.browser.msie) {
|
else if ($.browser.msie) {
|
||||||
name = "Internet Explorer";
|
name = "Internet Explorer";
|
||||||
}
|
}
|
||||||
else if ($.browser.firefox) {
|
else if ($.browser.firefox || $.browser.mozilla) {
|
||||||
name = "Firefox";
|
|
||||||
}
|
|
||||||
else if ($.browser.mozilla) {
|
|
||||||
name = "Firefox";
|
name = "Firefox";
|
||||||
}
|
}
|
||||||
else if ($.browser.opera) {
|
else if ($.browser.opera) {
|
||||||
|
@ -147,16 +104,19 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
|
||||||
throw new Error("Request cannot be null");
|
throw new Error("Request cannot be null");
|
||||||
}
|
}
|
||||||
|
|
||||||
var auth = 'MediaBrowser Client="' + clientName + '", Device="' + deviceName + '", DeviceId="' + deviceId + '"';
|
if (clientName) {
|
||||||
|
|
||||||
if (currentUserId) {
|
var auth = 'MediaBrowser Client="' + clientName + '", Device="' + deviceName + '", DeviceId="' + deviceId + '"';
|
||||||
auth += ', UserId="' + currentUserId + '"';
|
|
||||||
|
if (currentUserId) {
|
||||||
|
auth += ', UserId="' + currentUserId + '"';
|
||||||
|
}
|
||||||
|
|
||||||
|
request.headers = {
|
||||||
|
Authorization: auth
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
request.headers = {
|
|
||||||
Authorization: auth
|
|
||||||
};
|
|
||||||
|
|
||||||
return $.ajax(request);
|
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);
|
var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
|
||||||
|
|
||||||
return temp.toLowerCase();
|
return temp.toLowerCase();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
(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);
|
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<packages>
|
<packages>
|
||||||
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.65" targetFramework="net45" />
|
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.67" targetFramework="net45" />
|
||||||
<package id="ServiceStack.Common" version="3.9.42" targetFramework="net45" />
|
<package id="ServiceStack.Common" version="3.9.42" targetFramework="net45" />
|
||||||
<package id="ServiceStack.Text" version="3.9.42" targetFramework="net45" />
|
<package id="ServiceStack.Text" version="3.9.42" targetFramework="net45" />
|
||||||
</packages>
|
</packages>
|
Loading…
Add table
Add a link
Reference in a new issue