From 2dcaca425d8af67d1779da0ff76b94376c8a4578 Mon Sep 17 00:00:00 2001 From: Rishi Ghan Date: Mon, 13 Nov 2023 16:42:20 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=97=20Wired=20up=20the=20event=20emit?= =?UTF-8?q?=20correctly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/store/index.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/client/store/index.ts b/src/client/store/index.ts index 0352997..513a9d2 100644 --- a/src/client/store/index.ts +++ b/src/client/store/index.ts @@ -1,5 +1,5 @@ import { create } from "zustand"; -import { isEmpty } from "lodash"; +import { isEmpty, isNil } from "lodash"; import io from "socket.io-client"; import { SOCKET_BASE_URI } from "../constants/endpoints"; import { produce } from "immer"; @@ -49,8 +49,9 @@ export const useStore = create((set, get) => ({ const { getState, setState } = useStore; -// socket.io instantiation +// Fetch sessionId from localStorage const sessionId = localStorage.getItem("sessionId"); +// socket.io instantiation const socketIOInstance = io(SOCKET_BASE_URI, { transports: ["websocket"], withCredentials: true, @@ -60,6 +61,23 @@ setState({ socketIOInstance, }); +if (!isNil(sessionId)) { + // Resume the session + socketIOInstance.emit( + "call", + "socket.resumeSession", + { + session: { sessionId }, + }, + (data) => console.log(data), + ); +} else { + // Inititalize the session and persist the sessionId to localStorage + socketIOInstance.on("sessionInitialized", (sessionId) => { + localStorage.setItem("sessionId", sessionId); + }); +} + /** * Method to init AirDC++ Socket with supplied settings * @param configuration - credentials, and hostname details to init AirDC++ connection