diff --git a/src/api/DesktopAgent.ts b/src/api/DesktopAgent.ts index e947b4015..b3b2c26b1 100644 --- a/src/api/DesktopAgent.ts +++ b/src/api/DesktopAgent.ts @@ -170,4 +170,12 @@ export interface DesktopAgent { * Returns `null` if the app is not joined to a channel. */ getCurrentChannel(): Promise; + + /** + * Removes the app from any channel membership. + * + * Context broadcast and listening through the top-level `fdc3.broadcast` and `fdc3.addContextListener` will be + * in a no-op when the app is not on a channel. + */ + leaveCurrentChannel(): Promise; } diff --git a/src/api/methods.ts b/src/api/methods.ts index 2929eeb08..35935d2c8 100644 --- a/src/api/methods.ts +++ b/src/api/methods.ts @@ -74,3 +74,7 @@ export const getOrCreateChannel: ( export const getCurrentChannel: () => Promise = () => { return window.fdc3.getCurrentChannel(); }; + +export const leaveCurrentChannel: () => Promise = () => { + return window.fdc3.leaveCurrentChannel(); +}; diff --git a/test/methods.test.ts b/test/methods.test.ts index 4323de80a..7c4486757 100644 --- a/test/methods.test.ts +++ b/test/methods.test.ts @@ -11,6 +11,7 @@ import { getOrCreateChannel, getSystemChannels, joinChannel, + leaveCurrentChannel, open, raiseIntent, } from '../src'; @@ -167,4 +168,12 @@ describe('test ES6 module', () => { expect(mock.mock.calls.length).toBe(1); expect(mock.mock.calls[0]).toEqual([]); }); + + it('leaveCurrentChannel should delegate to window.fdc3.leaveCurrentChannel', () => { + leaveCurrentChannel(); + + const mock = getMock('leaveCurrentChannel'); + expect(mock.mock.calls.length).toBe(1); + expect(mock.mock.calls[0]).toEqual([]); + }); });