1
1
import type { ChannelAuthorizationCallback } from 'pusher-js/with-encryption' ;
2
2
import CONST from '@src/CONST' ;
3
- import * as Session from './actions/Session' ;
3
+ import { authenticatePusher } from './actions/Session' ;
4
4
import Log from './Log' ;
5
5
import type { SocketEventName } from './Pusher/library/types' ;
6
- import * as Pusher from './Pusher/pusher' ;
6
+ import { reconnect , registerCustomAuthorizer , registerSocketEventCallback } from './Pusher/pusher' ;
7
7
import type { EventCallbackError , States } from './Pusher/pusher' ;
8
8
9
9
function init ( ) {
@@ -13,22 +13,30 @@ function init() {
13
13
* current valid token to generate the signed auth response
14
14
* needed to subscribe to Pusher channels.
15
15
*/
16
- Pusher . registerCustomAuthorizer ( ( channel ) => ( {
16
+ registerCustomAuthorizer ( ( channel ) => ( {
17
17
authorize : ( socketId : string , callback : ChannelAuthorizationCallback ) => {
18
- Session . authenticatePusher ( socketId , channel . name , callback ) ;
18
+ authenticatePusher ( socketId , channel . name , callback ) ;
19
19
} ,
20
20
} ) ) ;
21
21
22
- Pusher . registerSocketEventCallback ( ( eventName : SocketEventName , error ?: EventCallbackError | States ) => {
22
+ registerSocketEventCallback ( ( eventName : SocketEventName , error ?: EventCallbackError | States ) => {
23
23
switch ( eventName ) {
24
24
case 'error' : {
25
25
if ( error && 'type' in error ) {
26
26
const errorType = error ?. type ;
27
27
const code = error ?. data ?. code ;
28
+ const errorMessage = error ?. data ?. message ?? '' ;
28
29
if ( errorType === CONST . ERROR . PUSHER_ERROR && code === 1006 ) {
29
30
// 1006 code happens when a websocket connection is closed. There may or may not be a reason attached indicating why the connection was closed.
30
31
// https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.5
31
32
Log . hmmm ( '[PusherConnectionManager] Channels Error 1006' , { error} ) ;
33
+
34
+ // The 1006 errors don't always have a message, but when they do, it seems that it prevents the pusher client from reconnecting.
35
+ // On the advice from Pusher directly, they suggested to manually reconnect in those scenarios.
36
+ if ( errorMessage ) {
37
+ Log . hmmm ( '[PusherConnectionManager] Channels Error 1006 message' , { errorMessage} ) ;
38
+ reconnect ( ) ;
39
+ }
32
40
} else if ( errorType === CONST . ERROR . PUSHER_ERROR && code === 4201 ) {
33
41
// This means the connection was closed because Pusher did not receive a reply from the client when it pinged them for a response
34
42
// https://pusher.com/docs/channels/library_auth_reference/pusher-websockets-protocol/#4200-4299
0 commit comments