Skip to content

Commit

Permalink
Merge pull request #27781 from software-mansion-labs/ts-migration/pus…
Browse files Browse the repository at this point in the history
…her-connection-manager

[No QA] [TS migration] Migrate 'PusherConnectionManager.js' lib to TypeScript
  • Loading branch information
nkuoch authored Sep 26, 2023
2 parents c6b7eae + 7ebcd09 commit fc0e330
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import lodashGet from 'lodash/get';
import {ValueOf} from 'type-fest';
import * as Pusher from './Pusher/pusher';
import * as Session from './actions/Session';
import Log from './Log';
import CONST from '../CONST';

type EventCallbackError = {type: ValueOf<typeof CONST.ERROR>; data: {code: number}};
type CustomAuthorizerChannel = {name: string};

function init() {
/**
* When authTokens expire they will automatically be refreshed.
* The authorizer helps make sure that we are always passing the
* current valid token to generate the signed auth response
* needed to subscribe to Pusher channels.
*/
Pusher.registerCustomAuthorizer((channel) => ({
authorize: (socketID, callback) => {
Pusher.registerCustomAuthorizer((channel: CustomAuthorizerChannel) => ({
authorize: (socketID: string, callback: () => void) => {
Session.authenticatePusher(socketID, channel.name, callback);
},
}));

/**
* @params {string} eventName
*/
Pusher.registerSocketEventCallback((eventName, error) => {
Pusher.registerSocketEventCallback((eventName: string, error: EventCallbackError) => {
switch (eventName) {
case 'error': {
const errorType = lodashGet(error, 'type');
const code = lodashGet(error, 'data.code');
const errorType = error?.type;
const code = error?.data?.code;
if (errorType === CONST.ERROR.PUSHER_ERROR && code === 1006) {
// 1006 code happens when a websocket connection is closed. There may or may not be a reason attached indicating why the connection was closed.
// https://datatracker.ietf.org/doc/html/rfc6455#section-7.1.5
Expand Down

0 comments on commit fc0e330

Please sign in to comment.