Skip to content

Commit

Permalink
fix: Merge branch 'main' into deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammeds1992 committed Aug 3, 2023
2 parents f9c5178 + d821535 commit 8b97fa0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
24 changes: 17 additions & 7 deletions packages/socket/src/lib/client/socketClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ export function createSocketConnection({
env,
socketType = 'notification',
apiKey,
socketOptions
}: SocketInputOptions
) {
const { autoConnect = true, reconnectionAttempts = 5, } = socketOptions || {};
socketOptions,
}: SocketInputOptions) {
const {
autoConnect = true,
reconnectionAttempts = 5,
reconnectionDelay,
reconnectionDelayMax,
} = socketOptions || {};

const pushWSUrl = API_URLS[env];

Expand All @@ -26,17 +30,23 @@ export function createSocketConnection({
let query;
if (socketType === 'notification') query = { address: userAddressInCAIP };
else query = { mode: 'chat', did: userAddressInCAIP };
pushSocket = io(pushWSUrl, {

// Build options object
const options = {
transports,
query,
autoConnect,
reconnectionAttempts,
});
...(reconnectionDelay !== undefined && { reconnectionDelay }),
...(reconnectionDelayMax !== undefined && { reconnectionDelayMax }),
};

pushSocket = io(pushWSUrl, options);
} catch (e) {
console.error('[PUSH-SDK] - Socket connection error: ');
console.error(e);
} finally {
// eslint-disable-next-line no-unsafe-finally
return pushSocket;
}
}
}
26 changes: 14 additions & 12 deletions packages/socket/src/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
import { ENV } from './constants';

export type SocketInputOptions = {
user: string,
env: ENV,
socketType?: 'notification' | 'chat',
apiKey?: string,
socketOptions?: SocketOptions
user: string;
env: ENV;
socketType?: 'notification' | 'chat';
apiKey?: string;
socketOptions?: SocketOptions;
};

export type SocketOptions = {
autoConnect: boolean,
reconnectionAttempts?: number
}
autoConnect: boolean;
reconnectionAttempts?: number;
reconnectionDelayMax?: number;
reconnectionDelay?: number;
};

/**
* TODO define types for
*
*
* TODO define types for
*
*
* ServerToClientEvents
* ClientToServerEvents
* SocketData
*
*
* like https://socket.io/docs/v4/typescript/
*/

0 comments on commit 8b97fa0

Please sign in to comment.