( url: string, subscriber: Subscriber, optionsRef: MutableRefObject<Options>, setReadyState: (readyState: ReadyState) => void, clearSocketIoPingInterval: (() => void) | null, )
| 9 | //TODO ensure that all onClose callbacks are called |
| 10 | |
| 11 | const cleanSubscribers = ( |
| 12 | url: string, |
| 13 | subscriber: Subscriber, |
| 14 | optionsRef: MutableRefObject<Options>, |
| 15 | setReadyState: (readyState: ReadyState) => void, |
| 16 | clearSocketIoPingInterval: (() => void) | null, |
| 17 | ) => { |
| 18 | return () => { |
| 19 | removeSubscriber(url, subscriber); |
| 20 | if (!hasSubscribers(url)) { |
| 21 | try { |
| 22 | const socketLike = sharedWebSockets[url]; |
| 23 | if (socketLike instanceof WebSocket) { |
| 24 | socketLike.onclose = (event: WebSocketEventMap['close']) => { |
| 25 | if (optionsRef.current.onClose) { |
| 26 | optionsRef.current.onClose(event); |
| 27 | } |
| 28 | setReadyState(ReadyState.CLOSED); |
| 29 | }; |
| 30 | } |
| 31 | socketLike.close(); |
| 32 | } catch (e) { |
| 33 | |
| 34 | } |
| 35 | if (clearSocketIoPingInterval) clearSocketIoPingInterval(); |
| 36 | |
| 37 | delete sharedWebSockets[url]; |
| 38 | } |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | export const createOrJoinSocket = ( |
| 43 | webSocketRef: MutableRefObject<WebSocketLike | null>, |
no test coverage detected
searching dependent graphs…