diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-08 14:50:55 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-09-08 14:50:55 -0400 |
| commit | 8398a5a32e98e5ae00e7f463b6ec009b1ef0c3e2 (patch) | |
| tree | 557785da08d2a0bee287cb35d4ad244f72f4812d /MediaBrowser.WebDashboard/ApiClient.js | |
| parent | 52ca9527cc00f2d6fc53aa2615070cf3e6990331 (diff) | |
close web socket gracefully to reduce error messages in server log
Diffstat (limited to 'MediaBrowser.WebDashboard/ApiClient.js')
| -rw-r--r-- | MediaBrowser.WebDashboard/ApiClient.js | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/MediaBrowser.WebDashboard/ApiClient.js b/MediaBrowser.WebDashboard/ApiClient.js index 4bdd3f779..66bf34248 100644 --- a/MediaBrowser.WebDashboard/ApiClient.js +++ b/MediaBrowser.WebDashboard/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 |
