1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00

improve web socket close

This commit is contained in:
Luke Pulverenti 2013-09-09 14:23:55 -04:00
parent 4056a61775
commit abef9d9254
3 changed files with 23 additions and 18 deletions

View file

@ -27,14 +27,6 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
var currentUserId;
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.
*/
@ -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) {
var msg = { MessageType: name };
@ -3427,17 +3425,15 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, wi
throw new Error("null itemId");
}
// Always use the http api in case playback is stopped by closing the browser
// See window beforeunload event at the top of this file
//if (self.isWebSocketOpen()) {
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, []);
// return deferred.promise();
//}
deferred.resolveWith(null, []);
return deferred.promise();
}
var params = {
};