microsoft / azure-devops-extension-sdk

Client SDK for developing Azure DevOps extensions
MIT License
122 stars 38 forks source link

Expose packaged XDM files #108

Open gburning opened 1 month ago

gburning commented 1 month ago

At the moment the XDM files are packaged but not included in the manifest. I'd like to be able to import the channelManager that was previously exposed by the package as I need to bridge the gap between an iframe my extension loads and the parent channel.

Here's the code for my use case:

/**
 * Bridge XDM channel of child window (iframe) to host/parent window's channel.
 * This allows the loaded iframe to access the DevOps SDK as if it was loaded directly (with some caveats).
 */
function createChannelBridge(childWindow: Window) {
    const parentChannel = channelManager.addChannel(window.parent)
    const childChannel = channelManager.addChannel(
        childWindow,
        childWindow.origin
    )

    const childRegister = childChannel.getObjectRegistry()

    childRegister.register(
        'DevOps.HostControl',
        parentChannel.getRemoteObjectProxy('DevOps.HostControl')
    )

    childRegister.register('DevOps.ServiceManager', {
        getService,
    })
}

Ideally you would also export the hostControlId and serviceManagerId constants from the SDK file.