How to use the sourcegraph/module/protocol/jsonrpc2/connection.createConnection function in sourcegraph

To help you get started, we’ve selected a few sourcegraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sourcegraph / sourcegraph / src / messaging.ts View on Github external
function connectAs(source: Source): Promise {
    const connection = createConnection({
        reader: new SubscribableMessageReader(
            fromEvent(window, 'message').pipe(
                // Filter to relevant messages, ignoring our own
                filter(m => m.data && m.data.source && m.data.source !== source && m.data.message),
                map(m => m.data.message)
            )
        ),
        writer: new CallbackMessageWriter(message => {
            window.postMessage({ source, message }, '*')
        }),
    })

    connection.listen()

    return new Promise(resolve => {
        connection.onNotification('Ping', () => {