Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

odspDocumentDeltaConnection targetClientId check #22749

Merged
merged 12 commits into from
Oct 22, 2024
18 changes: 9 additions & 9 deletions packages/drivers/odsp-driver/src/odspDocumentDeltaConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,28 +664,28 @@ export class OdspDocumentDeltaConnection extends DocumentDeltaConnection {
super.addTrackedListener(
event,
(msg: ISignalMessage | ISignalMessage[], documentId?: string) => {
const msgs = Array.isArray(msg) ? msg : [msg];
if (!this.enableMultiplexing || !documentId) {
if (!documentId) {
assert(
msgs.every((m) => !m.targetClientId),
"targetClientId defined while documentId is not",
);
}
if (!this.enableMultiplexing) {
listener(msg, documentId);
return;
}

assert(
documentId !== undefined,
"documentId is required when multiplexing is enabled.",
);

if (documentId !== this.documentId) {
return;
}

const msgs = Array.isArray(msg) ? msg : [msg];

const filteredMsgs = msgs.filter(
(m) => !m.targetClientId || m.targetClientId === this.clientId,
);

if (filteredMsgs.length > 0) {
listener(filteredMsgs, documentId);
listener(filteredMsgs.length === 1 ? filteredMsgs[0] : filteredMsgs, documentId);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this complication added?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signal layer compat tests fails without this, specifically the layer version combination where you have a very old loader and the most recent driver layer. Old loader doesn't handle batched signals (ISignalMessage[]) so only individual ISignalMessage's should be passed when there's one element for backcompat,

},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ describe("DeltaConnectionMetadata update tests", () => {

service.on("metadataUpdate", handler);

socket.emit("signal", signalMessage1);
socket.emit("signal", signalMessage1, joinSessionResponse.id);
assert(eventRaised, "event2 should have been raised");
service.off("metadataUpdate", handler);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ describeCompat("Targeted Signals", "NoCompat", (getTestObjectProvider) => {
*
* TODO: Re-enable tests once {@link https://dev.azure.com/fluidframework/internal/_workitems/edit/19030} is completed.
*/
if (provider.driver.type === "odsp") {
if (provider.driver.endpointName === "odsp") {
this.skip();
}

Expand Down
Loading