Skip to content

Commit

Permalink
fix: socket error restart delay
Browse files Browse the repository at this point in the history
  • Loading branch information
xstelea committed Jun 1, 2023
1 parent 2a01539 commit f63b38e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/connector/signaling/signaling-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import { Logger } from 'tslog'
import {
concatMap,
delay,
filter,
first,
from,
Expand Down Expand Up @@ -95,7 +96,6 @@ export const SignalingClient = (input: {
const onError = (event: Event) => {
logger?.debug(`🛰❌ signaling server error`, event)
subjects.onErrorSubject.next(event)
input.restart()
}

const prepareMessage = ({
Expand Down Expand Up @@ -234,6 +234,17 @@ export const SignalingClient = (input: {

subscription.add(onRemoteClientConnectionStateChange$.subscribe())

subscription.add(
subjects.onErrorSubject
.pipe(
delay(1_000),
tap(() => {
input.restart()
})
)
.subscribe()
)

ws.onmessage = onMessage
ws.onopen = onOpen
ws.onclose = onClose
Expand Down Expand Up @@ -265,7 +276,9 @@ export const SignalingClient = (input: {
onIceCandidate$,
subjects,
disconnect: () => {
ws.close()
if (ws.readyState === 1) {
ws.close()
}
},
destroy: () => {
subscription.unsubscribe()
Expand Down

0 comments on commit f63b38e

Please sign in to comment.