Skip to content

Commit

Permalink
Bug fixed valueChanged event listener on selection dictionary of Shar…
Browse files Browse the repository at this point in the history
…edMap in loadContainer function
  • Loading branch information
ritikramuka committed Jan 29, 2024
1 parent c87b341 commit 9a84d19
Showing 1 changed file with 26 additions and 39 deletions.
65 changes: 26 additions & 39 deletions src/web/client/common/worker/webworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ const containerSchema = {
},
};

let initial = false;

class AzureFluidClient {
static _clientInstance;
static _container;
Expand Down Expand Up @@ -84,15 +82,14 @@ async function loadContainer(config, swpId, entityInfo) {
try {
const { container, audience, map } =
await AzureFluidClient.fetchContainerAndService(config, swpId);

const existingMembers = audience.getMembers();

const myself = audience.getMyself();
const selectionSharedMap = await (await map.get('selection')).get();

if (audience && myself) {
const myConnectionId = audience['container'].clientId;
const entityIdObj = new Array(entityInfo.rootWebPageId);
(await container.initialObjects.sharedState.get('selection').get()).set(myConnectionId, entityIdObj);
selectionSharedMap.set(myConnectionId, entityIdObj);
}

audience.on("memberRemoved", (clientId, member) => {
Expand All @@ -104,51 +101,41 @@ async function loadContainer(config, swpId, entityInfo) {
}
});

if (!initial) {
existingMembers.forEach(async (value, key) => {
const otherUser = value;

const userConnections = otherUser.connections;

const userEntityIdArray = [];

const connectionIdInContainer = await (container.initialObjects.sharedState.get('selection').get());

userConnections.forEach((connection) => {
userEntityIdArray.push(connectionIdInContainer.get(connection.id));
});
const getUserIdByConnectionId = (targetConnectionId) => {
const members = audience.getMembers();
for (const [userId, member] of members.entries()) {
const connections = member.connections;
if (connections.some((connection) => connection.id === targetConnectionId)) {
return { userId: userId, userName: member.userName };
}
}

self.postMessage({
type: "client-data",
userName: otherUser.userName,
userId: otherUser.additionalDetails.AadObjectId,
containerId: swpId,
entityId: userEntityIdArray,
});
});
initial = true;
}
return null;
};

map.on("valueChanged", async (changed, local) => {
if (local) {
return;
} else {
const otherUser = map.get(changed.key);
const userConnections = otherUser.connections;
selectionSharedMap.on("valueChanged", async (changed, local) => {
const user = getUserIdByConnectionId(changed.key);
if (user) {
const userConnections = audience
.getMembers()
.get(user.userId).connections;

const userEntityIdArray = [];

const connectionIdInContainer = await (container.initialObjects.sharedState.get('selection').get());
const connectionIdInContainer = await map
.get("selection")
.get();

userConnections.forEach((connection) => {
userEntityIdArray.push(connectionIdInContainer.get(connection.id));
userEntityIdArray.push(
connectionIdInContainer.get(connection.id)
);
});

// eslint-disable-next-line no-undef
await self.postMessage({
type: "client-data",
userId: otherUser.additionalDetails.AadObjectId,
userName: otherUser.userName,
userId: user.userId,
userName: user.userName,
containerId: swpId,
entityId: userEntityIdArray,
});
Expand Down

0 comments on commit 9a84d19

Please sign in to comment.