Skip to content

Commit

Permalink
fix: android sdk reconnection (#7015)
Browse files Browse the repository at this point in the history
* Do not save client before connected request is approved

* Cleanup logging
  • Loading branch information
elefantel authored Aug 18, 2023
1 parent 27fbcdf commit ddda0fd
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Binary file modified android/libs/nativesdk.aar
Binary file not shown.
22 changes: 15 additions & 7 deletions app/core/SDKConnect/AndroidSDK/AndroidService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ export default class AndroidService extends EventEmitter2 {

if (this.connectedClients?.[clientInfo.clientId]) {
// Skip existing client -- bridge has been setup
Logger.log(
`AndroidService::clients_connected - existing client, sending ready`,
);

this.sendMessage(
{
type: MessageType.READY,
Expand All @@ -103,7 +107,7 @@ export default class AndroidService extends EventEmitter2 {
},
false,
).catch((err) => {
console.error(
Logger.log(
`AndroidService::clients_connected - error sending ready message to client ${clientInfo.clientId}`,
err,
);
Expand All @@ -121,6 +125,7 @@ export default class AndroidService extends EventEmitter2 {
try {
if (!this.connectedClients?.[clientInfo.clientId]) {
await this.requestApproval(clientInfo);
this.setupBridge(clientInfo);
// Save session to SDKConnect
SDKConnect.getInstance().addAndroidConnection({
id: clientInfo.clientId,
Expand All @@ -131,8 +136,6 @@ export default class AndroidService extends EventEmitter2 {
});
}

this.setupBridge(clientInfo);

this.sendMessage(
{
type: MessageType.READY,
Expand All @@ -148,6 +151,10 @@ export default class AndroidService extends EventEmitter2 {
);
});
} catch (error) {
Logger.log(
error,
`AndroidService::clients_connected sending jsonrpc error to client - connection rejected`,
);
this.sendMessage({
data: {
error,
Expand All @@ -157,9 +164,10 @@ export default class AndroidService extends EventEmitter2 {
}).catch((err) => {
Logger.log(
err,
`AndroidService::clients_connected error sending jsonrpc error to client`,
`AndroidService::clients_connected error failed sending jsonrpc error to client`,
);
});
Minimizer.goBack();
return;
}

Expand Down Expand Up @@ -296,7 +304,7 @@ export default class AndroidService extends EventEmitter2 {
origin: 'Android',
type: ApprovalTypes.CONNECT_ACCOUNTS,
requestData: {
hostname: 'Android Demo',
hostname: 'Android SDK',
pageMeta: {
channelId: clientInfo.clientId,
url: clientInfo.originatorInfo.url ?? '',
Expand All @@ -310,9 +318,9 @@ export default class AndroidService extends EventEmitter2 {
},
};

this.connectedClients[clientInfo.clientId] = clientInfo;

await approvalController.add(approvalRequest);

this.connectedClients[clientInfo.clientId] = clientInfo;
}

private setupBridge(clientInfo: AndroidClient) {
Expand Down

0 comments on commit ddda0fd

Please sign in to comment.