Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions packages/@webex/plugin-meetings/src/hashTree/hashTreeParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ class HashTreeParser {
// object mapping dataset names to arrays of leaf data
const leafInfo: Record<string, Array<LeafInfo>> = {};

const findAndStoreMetaData = (currentLocusPart: any) => {
const findAndStoreMetaData = (currentLocusPart: any, currentLocusPartName: string) => {
if (typeof currentLocusPart !== 'object' || currentLocusPart === null) {
return;
}
Expand All @@ -465,10 +465,18 @@ class HashTreeParser {
};

if (copyData) {
newLeafInfo.data = cloneDeep(currentLocusPart);
if ((type as string).toLowerCase() === ObjectType.control) {
// control entries require special handling, because they are signalled by Locus
// differently when coming in messages vs API responses
newLeafInfo.data = {
[currentLocusPartName]: cloneDeep(currentLocusPart),
};
} else {
newLeafInfo.data = cloneDeep(currentLocusPart);

// remove any nested other objects that have their own htMeta
deleteNestedObjectsWithHtMeta(newLeafInfo.data);
// remove any nested other objects that have their own htMeta
deleteNestedObjectsWithHtMeta(newLeafInfo.data);
}
}

for (const dataSetName of dataSetNames) {
Expand All @@ -480,19 +488,19 @@ class HashTreeParser {
}

if (Array.isArray(currentLocusPart)) {
for (const item of currentLocusPart) {
findAndStoreMetaData(item);
for (const [index, item] of currentLocusPart.entries()) {
findAndStoreMetaData(item, index.toString());
}
} else {
for (const key of Object.keys(currentLocusPart)) {
if (Object.prototype.hasOwnProperty.call(currentLocusPart, key)) {
findAndStoreMetaData(currentLocusPart[key]);
findAndStoreMetaData(currentLocusPart[key], key);
}
}
}
};

findAndStoreMetaData(locus);
findAndStoreMetaData(locus, 'locus');

return leafInfo;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,116 @@ describe('HashTreeParser', () => {
});
});

it('handles updates to control entries correctly', () => {
const parser = createHashTreeParser();

const mainPutItemsSpy = sinon.spy(parser.dataSets.main.hashTree, 'putItems');

// Create a locus update with new htMeta information for some things
const locusUpdate = {
dataSets: [
createDataSet('main', 16, 1100),
],
locus: {
url: 'https://locus-a.wbx2.com/locus/api/v1/loci/97d64a5f',
htMeta: {
elementId: {
type: 'locus',
id: 0,
version: 200, // same version
},
dataSetNames: ['main'],
},
participants: [],
controls: {
lock: {
locked: true,
htMeta: {
elementId: {
type: 'ControlEntry',
id: 10100,
version: 100,
},
dataSetNames: ['main'],
},
},
stream: {
streaming: true,
htMeta: {
elementId: {
type: 'ControlEntry',
id: 10101,
version: 100,
},
dataSetNames: ['main'],
},
}
}
},
};

// Call handleLocusUpdate
parser.handleLocusUpdate(locusUpdate);

// Verify putItems was called on main hash tree with correct data
assert.calledOnceWithExactly(mainPutItemsSpy, [
{type: 'locus', id: 0, version: 200},
{type: 'ControlEntry', id: 10100, version: 100},
{type: 'ControlEntry', id: 10101, version: 100}
]);

assert.calledOnceWithExactly(callback, LocusInfoUpdateType.OBJECTS_UPDATED, {
updatedObjects: [
{
htMeta: {
elementId: {
type: 'ControlEntry',
id: 10100,
version: 100,
},
dataSetNames: ['main'],
},
data: {
lock: {
locked: true,
htMeta: {
elementId: {
type: 'ControlEntry',
id: 10100,
version: 100,
},
dataSetNames: ['main'],
},
},
},
},
{
htMeta: {
elementId: {
type: 'ControlEntry',
id: 10101,
version: 100,
},
dataSetNames: ['main'],
},
data: {
stream: {
streaming: true,
htMeta: {
elementId: {
type: 'ControlEntry',
id: 10101,
version: 100,
},
dataSetNames: ['main'],
},
},
},
}
],
});
});

it('handles unknown datasets gracefully', () => {
const parser = createHashTreeParser();

Expand Down
Loading