Minor Issue
Found while testing with @finos/fdc3 version 2.2.2 (latest published version).
When subscribing via fdc3.addEventListener, leaving a user channel results in a callback with an incorrect event type (channelChangedEvent instead of the expected userChannelChanged). Those are the repro steps of my tests:
// Add event listener and log received events. It fails in both cases when I do and do not pass listener type as first arg
fdc3.addEventListener(null, console.warn);
// Join a channel
await fdc3.joinUserChannel("fdc3.channel.1");
/* The handler is invoked with:
{
type: "userChannelChanged",
details: {
currentChannelId: "fdc3.channel.1"
}
}
*/
// Leave the current channel
await fdc3.leaveCurrentChannel();
// The handler is invoked with:
/*
{
type: "channelChangedEvent",
newChannelId: null
}
*/
The issue appears to originate from this code of the handler wrapper. When leaving a channel, the payload contains newChannelId: null (since there is no active channel). Because of this, the logic falls in the else block, which forwards message coming from the DACP right to the FDC3 API which is not the one described in the standard.
Also, newChannelId is deprecated in favor of currentChannelId . Both should be taken into consideration but the newer currentChannelId field is not being used in this logic.
@ksgeorgieva suggested the following fix of the wrapHandler function. She has already tested this suggestion and found that it works as expected:
function wrapHandler(handler: EventHandler): (msg: AgentEventMessage) => void {
return (m: AgentEventMessage) => {
if (m.type !== "channelChangedEvent") {
// Ignore unsupported event types (or throw if appropriate)
return;
}
// 'currentChannelId' takes precedence over deprecated 'newChannelId' if it's set.
const currentChannelId =
m.payload.currentChannelId ?? m.payload.newChannelId ?? null;
// Creating correct channel changed even which follows the typings of the standard
const channelChangedEvent: FDC3ChannelChangedEvent = {
type: "userChannelChanged",
details: { currentChannelId }
};
handler(channelChangedEvent);
};
}
Area of Issue
Issue Description
Additional Context
Minor Issue
Found while testing with
@finos/fdc3version 2.2.2 (latest published version).When subscribing via
fdc3.addEventListener, leaving a user channel results in a callback with an incorrect event type (channelChangedEventinstead of the expecteduserChannelChanged). Those are the repro steps of my tests:The issue appears to originate from this code of the handler wrapper. When leaving a channel, the payload contains
newChannelId: null(since there is no active channel). Because of this, the logic falls in theelseblock, which forwards message coming from the DACP right to the FDC3 API which is not the one described in the standard.Also,
newChannelIdis deprecated in favor ofcurrentChannelId. Both should be taken into consideration but the newercurrentChannelIdfield is not being used in this logic.@ksgeorgieva suggested the following fix of the
wrapHandlerfunction. She has already tested this suggestion and found that it works as expected:Area of Issue
Issue Description
Additional Context