Skip to content

Commit

Permalink
renamed ping/pong to init/ready
Browse files Browse the repository at this point in the history
  • Loading branch information
edeykholt committed Jan 4, 2025
1 parent f84c30f commit becb2e8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export enum CsSwMsgEnum {
POLARIS_CLEAR_SESSION = "/signify/clear-session",
POLARIS_CREATE_DATA_ATTESTATION = "/signify/credential/create/data-attestation",
POLARIS_GET_CREDENTIAL = "/signify/credential/get",
PING = "ping"
INIT = "init"
}

// Message types from Extension to CS (and typically forward to Page and sometimes of type FooResponse)
Expand All @@ -34,14 +34,14 @@ export interface ISwCsMsg {
}

export enum SwCsMsgEnum {
PONG = "pong",
READY = "ready",
CANCELED = "canceled",
REPLY = "/signify/reply",
FSW = "fromServiceWorker"
}

export interface ISwCsMsgPong extends ISwCsMsg {
type: SwCsMsgEnum.PONG
type: SwCsMsgEnum.READY
}

// This IIdentifier is used in the context of responses from the extension service-worker, CS, to page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function handleMsgFromSW(message: PW.MessageData<unknown>): void {

console.info(`KeriAuthCs from SW: ${message.type}`, message);
switch (message.type) {
case SwCsMsgEnum.PONG:
case SwCsMsgEnum.READY:
break;

case SwCsMsgEnum.REPLY:
Expand Down Expand Up @@ -129,9 +129,9 @@ function createPortWithSw(): void {
});

// Send a ping message to the service worker to help complete the setup of connection port
const pingMsg: ICsSwMsg = { type: CsSwMsgEnum.PING };
console.log("KeriAuthCs to SW Ping:", pingMsg);
portWithSw.postMessage(pingMsg);
const initMsg: ICsSwMsg = { type: CsSwMsgEnum.INIT };
console.log("KeriAuthCs to SW Init:", initMsg);
portWithSw.postMessage(initMsg);
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,16 +580,16 @@ async function handleMessageFromPageCs(message: ICsSwMsg, cSPort: chrome.runtime
// TODO P2 any is a code smell
await handleSignRequest(message as any, pageCsConnections[connectionId].port);
break;
case CsSwMsgEnum.PING:
case CsSwMsgEnum.INIT:
pageCsConnections[connectionId].tabId = tabId;
const url = new URL(String(cSPort.sender?.url));
pageCsConnections[connectionId].pageAuthority = url.host;
const response: ISwCsMsgPong = {
type: SwCsMsgEnum.PONG,
type: SwCsMsgEnum.READY,
requestId: message.requestId,
payload: {}
};
console.log("SW to CS: ", SwCsMsgEnum.PONG)
console.log("SW to CS: ", SwCsMsgEnum.READY)
cSPort.postMessage(response);
break;
case CsSwMsgEnum.POLARIS_SIGN_DATA:
Expand Down

0 comments on commit becb2e8

Please sign in to comment.