Skip to content

Commit

Permalink
refactor(write): simplify message sending logic
Browse files Browse the repository at this point in the history
• Remove conditional analytics sending
• Always send RPC requests via network
• Add debug logging for triggeredInstaller state
• Remove redundant RPC method tracking
  • Loading branch information
abretonc7s committed Dec 19, 2024
1 parent 812480e commit b8e0acc
Showing 1 changed file with 5 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export async function write(
deeplinkProtocolAvailable && mobileWeb && authorized;

try {
if (!activeDeeplinkProtocol || triggeredInstaller) {
console.warn(
`[RCPMS: _write()] triggeredInstaller=${triggeredInstaller} activeDeeplinkProtocol=${activeDeeplinkProtocol}`,
);

if (!triggeredInstaller) {
// The only reason not to send via network is because the rpc call will be sent in the deeplink
instance.state.remote
?.sendMessage(data?.data)
Expand All @@ -72,43 +76,6 @@ export async function write(
.catch((err: unknown) => {
logger(`[RCPMS: _write()] error sending message`, err);
});
} else {
try {
// Add to rpc method tracker first then send the event to simulate sending from network.
const rpcMethodTracker = instance.state.remote?.getRPCMethodTracker();
if (rpcMethodTracker) {
const rpcId = data?.data?.id;
if (rpcId) {
rpcMethodTracker[rpcId] = {
id: rpcId,
method: targetMethod,
timestamp: Date.now(),
};
}

logger(
`[RCPMS: _write()] rpcMethodTracker`,
rpcMethodTracker,
data?.data,
);
}

// Only send analytics if we are not sending via network.
await SendAnalytics(
{
id: channelId,
event: TrackingEvents.SDK_RPC_REQUEST,
params: {
method: targetMethod,
from: 'mobile',
},
},
instance.state.remote?.state.communicationServerUrl ??
DEFAULT_SERVER_URL,
);
} catch (error) {
logger(`[RCPMS: _write()] error sending analytics`, error);
}
}

if (!isSecure) {
Expand Down

0 comments on commit b8e0acc

Please sign in to comment.