arrpc: fix link handling
This commit is contained in:
@@ -29,19 +29,19 @@ export async function initArRPC() {
|
||||
transferList: [workerPort]
|
||||
});
|
||||
|
||||
hostPort.on("message", async (e: ArRpcEvent) => {
|
||||
switch (e.type) {
|
||||
hostPort.on("message", async ({ type, nonce, data }: ArRpcEvent) => {
|
||||
switch (type) {
|
||||
case "activity": {
|
||||
sendRendererCommand(IpcCommands.RPC_ACTIVITY, e.data);
|
||||
sendRendererCommand(IpcCommands.RPC_ACTIVITY, data);
|
||||
break;
|
||||
}
|
||||
|
||||
case "invite": {
|
||||
const invite = String(e.data);
|
||||
const invite = String(data);
|
||||
|
||||
const response: ArRpcHostEvent = {
|
||||
type: "ack-invite",
|
||||
nonce: e.nonce,
|
||||
nonce,
|
||||
data: false
|
||||
};
|
||||
|
||||
@@ -56,19 +56,13 @@ export async function initArRPC() {
|
||||
}
|
||||
|
||||
case "link": {
|
||||
const link = String(e.data);
|
||||
|
||||
const response: ArRpcHostEvent = {
|
||||
type: "ack-link",
|
||||
nonce: e.nonce,
|
||||
nonce: nonce,
|
||||
data: false
|
||||
};
|
||||
|
||||
if (!inviteCodeRegex.test(link)) {
|
||||
return hostPort.postMessage(response);
|
||||
}
|
||||
|
||||
response.data = await sendRendererCommand(IpcCommands.RPC_DEEP_LINK, link).catch(() => false);
|
||||
response.data = await sendRendererCommand(IpcCommands.RPC_DEEP_LINK, data).catch(() => false);
|
||||
|
||||
hostPort.postMessage(response);
|
||||
break;
|
||||
|
||||
@@ -9,6 +9,7 @@ export type ArRpcHostEvent = ArRpcHostAckInviteEvent | ArRpcHostAckLinkEvent;
|
||||
|
||||
export interface ArRpcActivityEvent {
|
||||
type: "activity";
|
||||
nonce: string;
|
||||
data: string;
|
||||
}
|
||||
|
||||
@@ -21,7 +22,7 @@ export interface ArRpcInviteEvent {
|
||||
export interface ArRpcLinkEvent {
|
||||
type: "link";
|
||||
nonce: string;
|
||||
data: string;
|
||||
data: any;
|
||||
}
|
||||
|
||||
export interface ArRpcHostAckInviteEvent {
|
||||
|
||||
@@ -26,7 +26,8 @@ const linkCallbacks = new Map<string, LinkCallback>();
|
||||
server.on("activity", (data: any) => {
|
||||
const event: ArRpcEvent = {
|
||||
type: "activity",
|
||||
data: JSON.stringify(data)
|
||||
data: JSON.stringify(data),
|
||||
nonce: randomUUID()
|
||||
};
|
||||
workerPort.postMessage(event);
|
||||
});
|
||||
@@ -43,6 +44,18 @@ const linkCallbacks = new Map<string, LinkCallback>();
|
||||
workerPort.postMessage(event);
|
||||
});
|
||||
|
||||
server.on("link", async (data: any, callback: LinkCallback) => {
|
||||
const nonce = randomUUID();
|
||||
linkCallbacks.set(nonce, callback);
|
||||
|
||||
const event: ArRpcEvent = {
|
||||
type: "link",
|
||||
data,
|
||||
nonce
|
||||
};
|
||||
workerPort.postMessage(event);
|
||||
});
|
||||
|
||||
workerPort.on("message", (e: ArRpcHostEvent) => {
|
||||
switch (e.type) {
|
||||
case "ack-invite": {
|
||||
|
||||
Reference in New Issue
Block a user