mirror of
https://github.com/jellyfin/jellyfin-web.git
synced 2024-11-17 19:08:18 -07:00
close web socket gracefully to reduce error messages in server log
This commit is contained in:
parent
03598341b1
commit
5783b78b08
26
ApiClient.js
26
ApiClient.js
@ -2,7 +2,7 @@
|
||||
window.MediaBrowser = {};
|
||||
}
|
||||
|
||||
MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
|
||||
MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout, window) {
|
||||
|
||||
/**
|
||||
* Creates a new api client instance
|
||||
@ -27,6 +27,14 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
|
||||
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.
|
||||
*/
|
||||
@ -3419,15 +3427,17 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
|
||||
throw new Error("null itemId");
|
||||
}
|
||||
|
||||
if (self.isWebSocketOpen()) {
|
||||
// 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()) {
|
||||
|
||||
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 = {
|
||||
};
|
||||
@ -3535,7 +3545,7 @@ MediaBrowser.ApiClient = function ($, navigator, JSON, WebSocket, setTimeout) {
|
||||
};
|
||||
}
|
||||
|
||||
}(jQuery, navigator, window.JSON, window.WebSocket, setTimeout);
|
||||
}(jQuery, navigator, window.JSON, window.WebSocket, setTimeout, window);
|
||||
|
||||
/**
|
||||
* Provides a friendly way to create an api client instance using information from the browser's current url
|
||||
|
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.171" targetFramework="net45" />
|
||||
<package id="MediaBrowser.ApiClient.Javascript" version="3.0.172" targetFramework="net45" />
|
||||
<package id="ServiceStack.Common" version="3.9.58" targetFramework="net45" />
|
||||
<package id="ServiceStack.Text" version="3.9.58" targetFramework="net45" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user