diff --git a/src/web/client/WebExtensionContext.ts b/src/web/client/WebExtensionContext.ts index 8be8f952..9fed6a18 100644 --- a/src/web/client/WebExtensionContext.ts +++ b/src/web/client/WebExtensionContext.ts @@ -104,6 +104,7 @@ class WebExtensionContext implements IWebExtensionContext { private _formsProEligibilityId: string; private _concurrencyHandler: ConcurrencyHandler // Co-Presence for Power Pages Vscode for web + private _worker: Worker | undefined; private _sharedWorkSpaceMap: Map; private _containerId: string; private _connectedUsers: UserDataMap; @@ -189,6 +190,9 @@ class WebExtensionContext implements IWebExtensionContext { public get concurrencyHandler() { return this._concurrencyHandler; } + public get worker() { + return this._worker; + } public get sharedWorkSpaceMap() { return this._sharedWorkSpaceMap; } @@ -670,6 +674,10 @@ class WebExtensionContext implements IWebExtensionContext { return this._vscodeWorkspaceState.get(key); } + public setWorker(worker: Worker) { + this._worker = worker; + } + private async populateSharedworkspace( // eslint-disable-next-line @typescript-eslint/no-explicit-any headers: any, diff --git a/src/web/client/extension.ts b/src/web/client/extension.ts index 5f44d4f2..1c369978 100644 --- a/src/web/client/extension.ts +++ b/src/web/client/extension.ts @@ -240,25 +240,26 @@ export function processWorkspaceStateChanges(context: vscode.ExtensionContext) { WebExtensionContext.updateVscodeWorkspaceState(document.uri.fsPath, entityInfo); // sending message to webworker event listener for Co-Presence feature - // eslint-disable-next-line no-constant-condition - if (false && isCoPresenceEnabled()) { - worker.postMessage({ - afrConfig: { - swpId: WebExtensionContext.sharedWorkSpaceMap.get( - Constants.sharedWorkspaceParameters.SHAREWORKSPACE_ID - ) as string, - swptenantId: WebExtensionContext.sharedWorkSpaceMap.get( - Constants.sharedWorkspaceParameters.TENANT_ID - ) as string, - discoveryendpoint: WebExtensionContext.sharedWorkSpaceMap.get( - Constants.sharedWorkspaceParameters.DISCOVERY_ENDPOINT - ) as string, - swpAccessToken: WebExtensionContext.sharedWorkSpaceMap.get( - Constants.sharedWorkspaceParameters.ACCESS_TOKEN - ) as string, - }, - entityInfo - }); + if (isCoPresenceEnabled()) { + if (WebExtensionContext.worker !== undefined) { + WebExtensionContext.worker.postMessage({ + afrConfig: { + swpId: WebExtensionContext.sharedWorkSpaceMap.get( + Constants.sharedWorkspaceParameters.SHAREWORKSPACE_ID + ) as string, + swptenantId: WebExtensionContext.sharedWorkSpaceMap.get( + Constants.sharedWorkspaceParameters.TENANT_ID + ) as string, + discoveryendpoint: WebExtensionContext.sharedWorkSpaceMap.get( + Constants.sharedWorkspaceParameters.DISCOVERY_ENDPOINT + ) as string, + swpAccessToken: WebExtensionContext.sharedWorkSpaceMap.get( + Constants.sharedWorkspaceParameters.ACCESS_TOKEN + ) as string, + }, + entityInfo + }); + } } } } @@ -293,14 +294,11 @@ export function processWillSaveDocument(context: vscode.ExtensionContext) { export function processWillStartCollaboartion(context: vscode.ExtensionContext) { // feature in progress, hence disabling it - // eslint-disable-next-line no-constant-condition - if (false && isCoPresenceEnabled()) { + if (isCoPresenceEnabled()) { createWebWorkerInstance(context); } } -let worker: Worker; - export function createWebWorkerInstance( context: vscode.ExtensionContext ) { @@ -322,27 +320,29 @@ export function createWebWorkerInstance( const workerUrl = URL.createObjectURL(workerBlob); - worker = new Worker(workerUrl); + WebExtensionContext.setWorker(new Worker(workerUrl)); - worker.onmessage = (event) => { - const { data } = event; + if (WebExtensionContext.worker !== undefined) { + WebExtensionContext.worker.onmessage = (event) => { + const { data } = event; - WebExtensionContext.containerId = event.data.containerId; + WebExtensionContext.containerId = event.data.containerId; - if (data.type === Constants.workerEventMessages.REMOVE_CONNECTED_USER) { - WebExtensionContext.removeConnectedUserInContext( - data.userId - ); - } - if (data.type === Constants.workerEventMessages.UPDATE_CONNECTED_USERS) { - WebExtensionContext.updateConnectedUsersInContext( - data.containerId, - data.userName, - data.userId, - data.entityId - ); - } - }; + if (data.type === Constants.workerEventMessages.REMOVE_CONNECTED_USER) { + WebExtensionContext.removeConnectedUserInContext( + data.userId + ); + } + if (data.type === Constants.workerEventMessages.UPDATE_CONNECTED_USERS) { + WebExtensionContext.updateConnectedUsersInContext( + data.containerId, + data.userName, + data.userId, + data.entityId + ); + } + }; + } }) // TODO: add Telemetry }