From 87f6f14af6fd768c9e033d2da68552e8fb5afe0f Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Wed, 27 Feb 2019 00:55:27 -0800 Subject: [PATCH] Add connection termination message for unexpected terminations --- main.cpp | 8 +++++--- static/js/messages.js | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index 777bb6c..d23d9b2 100644 --- a/main.cpp +++ b/main.cpp @@ -18,7 +18,7 @@ // Requests the NaCl module stop streaming #define MSG_STOP_REQUEST "stopRequest" // Sent by the NaCl module when the stream has stopped whether user-requested or not -#define MSG_STREAM_TERMINATED "streamTerminated" +#define MSG_STREAM_TERMINATED "streamTerminated: " #define MSG_OPENURL "openUrl" @@ -59,7 +59,7 @@ void MoonlightInstance::OnConnectionStopped(uint32_t error) { UnlockMouse(); // Notify the JS code that the stream has ended - pp::Var response(MSG_STREAM_TERMINATED); + pp::Var response(std::string(MSG_STREAM_TERMINATED) + std::to_string((int)error)); PostMessage(response); } @@ -137,7 +137,9 @@ void* MoonlightInstance::ConnectionThreadFunc(void* context) { NULL, 0); if (err != 0) { // Notify the JS code that the stream has ended - pp::Var response(MSG_STREAM_TERMINATED); + // NB: We pass error code 0 here to avoid triggering a "Connection terminated" + // warning message. + pp::Var response(MSG_STREAM_TERMINATED + std::to_string(0)); me->PostMessage(response); return NULL; } diff --git a/static/js/messages.js b/static/js/messages.js index 8e4a9c1..07cb05f 100644 --- a/static/js/messages.js +++ b/static/js/messages.js @@ -36,10 +36,16 @@ function handleMessage(msg) { delete callbacks[msg.data.callbackId] } else { // else, it's just info, or an event console.log('%c[messages.js, handleMessage]', 'color:gray;', 'Message data: ', msg.data) - if (msg.data === 'streamTerminated') { // if it's a recognized event, notify the appropriate function + if (msg.data.indexOf('streamTerminated: ') === 0) { // if it's a recognized event, notify the appropriate function // Release our keep awake request chrome.power.releaseKeepAwake(); + // Show a termination snackbar message if the termination was unexpected + var errorCode = parseInt(msg.data.replace('streamTerminated: ', '')); + if (errorCode !== 0) { + snackbarLogLong("Connection terminated"); + } + api.refreshServerInfo().then(function(ret) { // Return to app list with new currentgame showApps(api);