Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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', () => {