MCPcopy Create free account
hub / github.com/MonaSolutions/MonaServer / readMessage

Method readMessage

MonaCore/sources/WebSocket/WSSession.cpp:142–199  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140
141
142void WSSession::readMessage(Exception& ex, DataReader& reader, UInt8 responseType) {
143
144 std::string name("onMessage");
145
146 if (typeid(reader).name() != typeid(StringReader).name() && reader.readString(name)) {
147
148 if(name=="__publish") {
149 if(!reader.readString(name)) {
150 ex.set(Exception::PROTOCOL, "__publish method takes a stream name in first parameter",WS::CODE_MALFORMED_PAYLOAD);
151 return;
152 }
153 Publication::Type type(Publication::LIVE);
154 std::string mode;
155 if (reader.readString(mode)) {
156 if(String::ICompare(mode,"record") == 0)
157 type = Publication::RECORD;
158 }
159 EXCEPTION_TO_LOG(openPublication(ex, name, type),"Publish ",name);
160 return;
161
162 }
163
164 if(name=="__play") {
165 if(!reader.readString(name)) {
166 ex.set(Exception::PROTOCOL, "__play method takes a stream name in first parameter",WS::CODE_MALFORMED_PAYLOAD);
167 return;
168 }
169 EXCEPTION_TO_LOG(openSubscribtion(ex, name, _writer),"Play ",name);
170 return;
171 }
172
173 if (name == "__closePublish") {
174 closePublication();
175 return;
176 }
177
178 if (name == "__closePlay") {
179 closeSusbcription();
180 return;
181 }
182
183 if (name == "__close") {
184 closePublication();
185 closeSusbcription();
186 return;
187 }
188
189 if (_pPublication) {
190 reader.reset();
191 _pPublication->pushData(reader, peer.ping());
192 return;
193 }
194
195 }
196
197 if(!peer.onMessage(ex, name,reader,responseType))
198 ex.set(Exception::APPLICATION, "Method '",name,"' not found on application ", peer.path);
199}

Callers

nothing calls this directly

Calls 6

readStringMethod · 0.80
setMethod · 0.45
resetMethod · 0.45
pushDataMethod · 0.45
pingMethod · 0.45
onMessageMethod · 0.45

Tested by

no test coverage detected