MCPcopy Index your code
hub / github.com/NativeScript/capacitor / receiveMessage

Method receiveMessage

testing/browser.ts:141–227  ·  view source on GitHub ↗
(msg: any)

Source from the content-addressed store, hash-verified

139 }
140
141 receiveMessage(msg: any) {
142 if (DEBUGGING) {
143 nativeLog('Received Message:', JSON.stringify(msg));
144 }
145 // Special case for Events and Messages directly from other side of bridge
146 if (msg.tracking === -1) {
147 switch (msg.cmd) {
148 case NS_MARSHALL_PLATFORM:
149 nativeLog(
150 'Setting Platform to',
151 msg.platform === true
152 ? 'Android'
153 : msg.platform === false
154 ? 'ios'
155 : 'unknown',
156 );
157 if (msg.platform) {
158 (<any>window).native.__func.__android = true;
159 } else {
160 (<any>window).native.__func.__ios = true;
161 }
162 break;
163
164 case NS_MARSHALL_CALLBACK:
165 if (!this._callbacks[msg.id]) {
166 nativeLog('Missing Callback', msg.id);
167 return;
168 }
169 this._callbacks[msg.id].apply(null, msg.args);
170 break;
171
172 default:
173 nativeLog('Unknown Receive message', msg.cmd);
174 }
175 return;
176 }
177
178 if (typeof msg.tracking === 'undefined') {
179 throw new Error('RM: undefined TID, ' + JSON.stringify(msg));
180 }
181
182 const callbacks = this._tracking[msg.tracking];
183 if (!callbacks) {
184 throw new Error('RM: Missing TID, ' + JSON.stringify(msg));
185 }
186 delete this._tracking[msg.tracking];
187 if (msg.error) {
188 if (callbacks.reject) {
189 callbacks.reject(msg.error);
190 }
191 } else {
192 if (callbacks.resolve) {
193 // TODO: .return doesn't seem to be used anymore; should revisit/delete? this code
194 if (callbacks.return) {
195 if (callbacks.func) {
196 callbacks.func[NS_PROXY_HAS_WAITING_VALUE] =
197 typeof msg.result !== 'undefined';
198 if (typeof msg.result !== 'undefined') {

Callers 1

constructorMethod · 0.95

Calls 1

nativeLogFunction · 0.85

Tested by

no test coverage detected