improve web socket close

pull/702/head
Luke Pulverenti 11 years ago
parent a0fea896fd
commit b1b3a280a4

@ -27,14 +27,6 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
var currentUserId; var currentUserId;
var webSocket; var webSocket;
$(window).on("beforeunload", function () {
// Close the connection gracefully when possible
if (webSocket && webSocket.readyState === WebSocket.OPEN) {
webSocket.close();
}
});
/** /**
* Gets the server host name. * Gets the server host name.
*/ */
@ -195,6 +187,12 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
}; };
}; };
self.closeWebSocket = function () {
if (webSocket && webSocket.readyState === WebSocket.OPEN) {
webSocket.close();
}
};
self.sendWebSocketMessage = function (name, data) { self.sendWebSocketMessage = function (name, data) {
var msg = { MessageType: name }; var msg = { MessageType: name };
@ -3427,17 +3425,15 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
throw new Error("null itemId"); throw new Error("null itemId");
} }
// Always use the http api in case playback is stopped by closing the browser if (self.isWebSocketOpen()) {
// See window beforeunload event at the top of this file
//if (self.isWebSocketOpen()) {
// var deferred = $.Deferred(); var deferred = $.Deferred();
// self.sendWebSocketMessage("PlaybackStopped", itemId + "|" + (positionTicks == null ? "" : positionTicks)); self.sendWebSocketMessage("PlaybackStopped", itemId + "|" + (positionTicks == null ? "" : positionTicks));
// deferred.resolveWith(null, []); deferred.resolveWith(null, []);
// return deferred.promise(); return deferred.promise();
//} }
var params = { var params = {
}; };

@ -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.172" targetFramework="net45" /> <package id="MediaBrowser.ApiClient.Javascript" version="3.0.174" targetFramework="net45" />
<package id="ServiceStack.Common" version="3.9.58" targetFramework="net45" /> <package id="ServiceStack.Common" version="3.9.58" targetFramework="net45" />
<package id="ServiceStack.Text" version="3.9.58" targetFramework="net45" /> <package id="ServiceStack.Text" version="3.9.58" targetFramework="net45" />
</packages> </packages>
Loading…
Cancel
Save