MCPcopy Create free account
hub / github.com/NativeScript/android / dispatchMessage

Method dispatchMessage

test-app/runtime/src/main/cpp/JsV8InspectorClient.cpp:111–194  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

109
110
111void JsV8InspectorClient::dispatchMessage(const std::string& message) {
112 v8::Locker locker(isolate_);
113 Isolate::Scope isolate_scope(isolate_);
114 v8::HandleScope handleScope(isolate_);
115 auto context = Runtime::GetRuntime(isolate_)->GetContext();
116 Context::Scope context_scope(context);
117
118 std::vector<uint16_t> vector = tns::Util::ToVector(message);
119 StringView messageView(vector.data(), vector.size());
120 bool success;
121
122 /*
123 // livesync uses the inspector socket for HMR/LiveSync...
124 if(message.find("Page.reload") != std::string::npos) {
125 success = tns::LiveSync(this->isolate_);
126 if (!success) {
127 NSLog(@"LiveSync failed");
128 }
129 // todo: should we return here, or is it OK to pass onto a possible Page.reload domain handler?
130 }
131 */
132
133
134 if(message.find("Tracing.start") != std::string::npos) {
135 tracing_agent_->start();
136
137 // echo back the request to notify frontend the action was a success
138 // todo: send an empty response for the incoming message id instead.
139 this->sendNotification(StringBuffer::create(messageView));
140 return;
141 }
142
143 if(message.find("Tracing.end") != std::string::npos) {
144 tracing_agent_->end();
145 std::string res = tracing_agent_->getLastTrace();
146 tracing_agent_->SendToDevtools(context, res);
147 return;
148 }
149
150
151 // parse incoming message as JSON
152 Local<Value> arg;
153 success = v8::JSON::Parse(context, tns::ArgConverter::ConvertToV8String(isolate_, message)).ToLocal(&arg);
154
155 // stop processing invalid messages
156 if(!success) {
157
158 // NSLog(@"Inspector failed to parse incoming message: %s", message.c_str());
159 // ignore failures to parse.
160 return;
161 }
162
163
164
165
166 // Pass incoming message to a registerd domain handler if any
167 if(!arg.IsEmpty() && arg->IsObject()) {
168 Local<Object> domainDebugger;

Calls 14

sendNotificationMethod · 0.95
GetContextMethod · 0.80
getLastTraceMethod · 0.80
SendToDevtoolsMethod · 0.80
ToLocalMethod · 0.80
ToLocalCheckedMethod · 0.80
startMethod · 0.65
dataMethod · 0.45
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected