onFail on a WS connection, send the error back using the websocket request handler

This commit is contained in:
Marco van Dijk 2022-03-16 13:45:37 +01:00 committed by Thulinma
parent 54a46146c2
commit c10d5a7ec1
2 changed files with 19 additions and 2 deletions

View file

@ -36,6 +36,7 @@ namespace Mist{
OutHTTP::OutHTTP(Socket::Connection &conn) : HTTPOutput(conn){ OutHTTP::OutHTTP(Socket::Connection &conn) : HTTPOutput(conn){
stayConnected = false; stayConnected = false;
thisError = "";
// If this connection is a socket and not already connected to stdio, connect it to stdio. // If this connection is a socket and not already connected to stdio, connect it to stdio.
if (myConn.getPureSocket() != -1 && myConn.getSocket() != STDIN_FILENO && myConn.getSocket() != STDOUT_FILENO){ if (myConn.getPureSocket() != -1 && myConn.getSocket() != STDIN_FILENO && myConn.getSocket() != STDOUT_FILENO){
std::string host = getConnectedHost(); std::string host = getConnectedHost();
@ -63,6 +64,11 @@ namespace Mist{
bool OutHTTP::listenMode(){return !(config->getString("ip").size());} bool OutHTTP::listenMode(){return !(config->getString("ip").size());}
void OutHTTP::onFail(const std::string &msg, bool critical){ void OutHTTP::onFail(const std::string &msg, bool critical){
// If we are connected through WS, the websockethandler should return the error message
if (stayConnected){
thisError = msg;
return;
}
if (responded){ if (responded){
HTTPOutput::onFail(msg, critical); HTTPOutput::onFail(msg, critical);
return; return;
@ -78,7 +84,6 @@ namespace Mist{
return; return;
} }
if (H.url.size() >= 3 && H.url.substr(H.url.size() - 3) == ".js"){ if (H.url.size() >= 3 && H.url.substr(H.url.size() - 3) == ".js"){
if (websocketHandler()){return;}
JSON::Value json_resp; JSON::Value json_resp;
json_resp["error"] = "Could not retrieve stream. Sorry."; json_resp["error"] = "Could not retrieve stream. Sorry.";
json_resp["error_guru"] = msg; json_resp["error_guru"] = msg;
@ -1149,12 +1154,23 @@ namespace Mist{
if (meta){meta.reloadReplacedPagesIfNeeded();} if (meta){meta.reloadReplacedPagesIfNeeded();}
if (newState != prevState || (newState == STRMSTAT_READY && M.getValidTracks() != prevTracks)){ if (newState != prevState || (newState == STRMSTAT_READY && M.getValidTracks() != prevTracks)){
if (newState == STRMSTAT_READY){ if (newState == STRMSTAT_READY){
thisError = "";
reconnect(); reconnect();
prevTracks = M.getValidTracks(); prevTracks = M.getValidTracks();
}else{ }else{
disconnect(); disconnect();
} }
JSON::Value resp = getStatusJSON(reqHost, useragent); JSON::Value resp;
// Check if we have an error message set
if (thisError == ""){
resp = getStatusJSON(reqHost, useragent);
}else{
resp["error"] = "Could not retrieve stream. Sorry.";
resp["error_guru"] = thisError;
if (config->getString("nostreamtext") != ""){
resp["on_error"] = config->getString("nostreamtext");
}
}
if (currStreamName != streamName){ if (currStreamName != streamName){
currStreamName = streamName; currStreamName = streamName;
snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_STATE, streamName.c_str()); snprintf(pageName, NAME_BUFFER_SIZE, SHM_STREAM_STATE, streamName.c_str());

View file

@ -21,6 +21,7 @@ namespace Mist{
private: private:
std::string origStreamName; std::string origStreamName;
std::string mistPath; std::string mistPath;
std::string thisError;
}; };
}// namespace Mist }// namespace Mist