Skip to content

Commit

Permalink
Update expo rn sdk to match bare
Browse files Browse the repository at this point in the history
  • Loading branch information
Ariflo committed Mar 4, 2024
1 parent c9c56e6 commit 466d5b3
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,20 @@ export class ReactNativeWebViewController extends ViewController {
}

protected async _post(data: any) {
const methodType = data.payload.method;
const messageId = data.payload.id;
// Safely access `method` and `id` from `payload`, defaulting to undefined if not present
const methodType = data.payload?.method;
const messageId = data.payload?.id;

if (this.webView && (this.webView as any).postMessage) {
// Setup timeout for message response
const timeout = setTimeout(() => {
this.messageTimeouts.delete(messageId);
throw createResponseTimeoutError(methodType, messageId);
}, 10000); // 10-second timeout
if (methodType && messageId) {
const timeout = setTimeout(() => {
this.messageTimeouts.delete(messageId);
throw createResponseTimeoutError(methodType, messageId);
}, 10000); // 10-second timeout

this.messageTimeouts.set(messageId, timeout);
this.messageTimeouts.set(messageId, timeout);
}

(this.webView as any).postMessage(
JSON.stringify(data, (key, value) => {
Expand Down

0 comments on commit 466d5b3

Please sign in to comment.