Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: android sdk reconnection #7015

Merged
merged 3 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading