Skip to content

Commit

Permalink
added worker in webextension context
Browse files Browse the repository at this point in the history
  • Loading branch information
ritikramuka committed Oct 27, 2023
1 parent b4e9319 commit b2568e6
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 41 deletions.
8 changes: 8 additions & 0 deletions src/web/client/WebExtensionContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;
private _containerId: string;
private _connectedUsers: UserDataMap;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
Expand Down
82 changes: 41 additions & 41 deletions src/web/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
}
}
}
}
Expand Down Expand Up @@ -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
) {
Expand All @@ -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
}
Expand Down

0 comments on commit b2568e6

Please sign in to comment.