Skip to content

Commit

Permalink
Allowed null/no channel to be set in the channel change callback
Browse files Browse the repository at this point in the history
  • Loading branch information
robmoffat committed Sep 25, 2024
1 parent 8eac00b commit ec2306a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class DefaultChannelSupport implements ChannelSupport {
constructor(messaging: Messaging, channelSelector: ChannelSelector) {
this.messaging = messaging;
this.channelSelector = channelSelector
this.channelSelector.setChannelChangeCallback((channelId: string) => {
this.channelSelector.setChannelChangeCallback((channelId: string | null) => {
if (channelId == null) {
this.leaveUserChannel()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type IframeChannelSelected = BrowserTypes.IframeChannelSelected
*/
export class DefaultDesktopAgentChannelSelector extends AbstractUIComponent implements ChannelSelector {

private callback: ((channelId: string) => void) | null = null
private callback: ((channelId: string | null) => void) | null = null

constructor(url: string | null) {
super(url ?? "https://fdc3.finos.org/webui/channel_selector.html", "FDC3 Channel Selector")
Expand All @@ -27,7 +27,7 @@ export class DefaultDesktopAgentChannelSelector extends AbstractUIComponent impl
port.addEventListener("message", (e) => {
if (e.data.type == 'iframeChannelSelected') {
const choice = e.data as IframeChannelSelected
if ((choice.payload.selected) && (this.callback)) {
if (this.callback) {
this.callback(choice.payload.selected)
}
}
Expand All @@ -51,7 +51,7 @@ export class DefaultDesktopAgentChannelSelector extends AbstractUIComponent impl
} as IframeChannels)
}

setChannelChangeCallback(callback: (channelId: string) => void): void {
setChannelChangeCallback(callback: (channelId: string | null) => void): void {
this.callback = callback
}

Expand Down
2 changes: 1 addition & 1 deletion packages/fdc3-get-agent/src/ui/NullChannelSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class NullChannelSelector implements ChannelSelector, Connectable {
updateChannel(_channelId: string | null, _availableChannels: Channel[]): void {
}

setChannelChangeCallback(_callback: (channelId: string) => void): void {
setChannelChangeCallback(_callback: (channelId: string | null) => void): void {
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { CustomWorld } from "../world";
Given('A Channel Selector in {string} with callback piping to {string}', async function (this: CustomWorld, field: string, cb: string) {
const cs = new DefaultDesktopAgentChannelSelector(CHANNEL_SELECTOR_URL);

cs.setChannelChangeCallback((channelId: string) => {
cs.setChannelChangeCallback((channelId: string | null) => {
this.props[cb] = channelId
})

Expand Down
2 changes: 1 addition & 1 deletion packages/fdc3-standard/src/ui/ChannelSelector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export interface ChannelSelector extends Connectable {
* Called on initialisation. The channel selector will invoke the callback after the
* channel is changed.
*/
setChannelChangeCallback(callback: (channelId: string) => void): void
setChannelChangeCallback(callback: (channelId: string | null) => void): void

}
2 changes: 1 addition & 1 deletion packages/testing/src/agent/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class SimpleChannelSelector implements ChannelSelector {
this.cw.props['channels'] = availableChannels
}

setChannelChangeCallback(_callback: (channelId: string) => void): void {
setChannelChangeCallback(_callback: (channelId: string | null) => void): void {
}

async connect(): Promise<void> {
Expand Down

0 comments on commit ec2306a

Please sign in to comment.