Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] [TS migration] Migrate 'PusherConnectionManager.js' lib to TypeScript #27781

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
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}};

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: {name: string}) => ({
authorize: (socketID: string, callback: () => void) => {
BartoszGrajdek marked this conversation as resolved.
Show resolved Hide resolved
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
Loading