diff --git a/src/output/output_json.cpp b/src/output/output_json.cpp index 6c7096f9..b2fa08f6 100644 --- a/src/output/output_json.cpp +++ b/src/output/output_json.cpp @@ -2,8 +2,16 @@ #include namespace Mist { - OutJSON::OutJSON(Socket::Connection & conn) : HTTPOutput(conn){realTime = 0;} - OutJSON::~OutJSON() {} + OutJSON::OutJSON(Socket::Connection & conn) : HTTPOutput(conn){ + ws = 0; + realTime = 0; + } + OutJSON::~OutJSON() { + if (ws){ + delete ws; + ws = 0; + } + } void OutJSON::init(Util::Config * cfg){ HTTPOutput::init(cfg); @@ -16,9 +24,17 @@ namespace Mist { capa["methods"][0u]["type"] = "html5/text/javascript"; capa["methods"][0u]["priority"] = 0ll; capa["methods"][0u]["url_rel"] = "/$.json"; + capa["methods"][1u]["handler"] = "ws"; + capa["methods"][1u]["type"] = "html5/text/javascript"; + capa["methods"][1u]["priority"] = 0ll; + capa["methods"][1u]["url_rel"] = "/$.json"; } void OutJSON::sendNext(){ + if (ws){ + ws->sendFrame(thisPacket.toJSON().toString()); + return; + } if (!jsonp.size()){ if(!first) { myConn.SendNow(", ", 2); @@ -63,6 +79,19 @@ namespace Mist { selectedTracks.insert(JSON::Value(H.GetVar("track")).asInt()); } + if (H.GetHeader("Upgrade") == "websocket"){ + ws = new HTTP::Websocket(myConn, H); + if (!(*ws)){ + delete ws; + ws = 0; + return; + } + sentHeader = true; + parseData = true; + wantRequest = false; + return; + } + H.Clean(); H.setCORSHeaders(); if(method == "OPTIONS" || method == "HEAD"){ diff --git a/src/output/output_json.h b/src/output/output_json.h index 29ad92c0..3e8c7023 100644 --- a/src/output/output_json.h +++ b/src/output/output_json.h @@ -1,5 +1,5 @@ #include "output_http.h" - +#include namespace Mist { class OutJSON : public HTTPOutput { @@ -14,6 +14,7 @@ namespace Mist { protected: std::string jsonp; bool first; + HTTP::Websocket * ws; }; }