Skip to content

Instantly share code, notes, and snippets.

@tauren
Last active February 10, 2017 19:18
Show Gist options
  • Save tauren/dbc37a3ee1404cb73415cdaa6ccfd65d to your computer and use it in GitHub Desktop.
Save tauren/dbc37a3ee1404cb73415cdaa6ccfd65d to your computer and use it in GitHub Desktop.
RxJS websocket issue
let candidatesToSend = []
let candidatesReceived = []
let socketSubject = Observable.webSocket({
url: 'wss://...',
openObserver: {
next: e => {
e.currentTarget.binaryType = 'arraybuffer'
candidatesToSend.forEach(candidate => {
console.log('sending candidate', candidate)
socketSubject.next(candidate)
})
candidatesToSend = []
}
}
})
candidatesToSend.push({ candidate: 1 })
candidatesToSend.push({ candidate: 2 })
socketSubject.subscribe({
next: msg => {
console.log('received candidate', msg)
candidatesReceived.push(msg)
}
})
socketSubject.next({ candidate: 3 })
socketSubject.unsubscribe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment