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

Video 3730 add conversation hooks #438

Merged
merged 14 commits into from
Mar 2, 2021
Prev Previous commit
Next Next commit
Make error handling more user friendly
  • Loading branch information
Tim Mendoza committed Feb 25, 2021
commit 98614e971e11cc701027578d042b99e7231802ee
8 changes: 6 additions & 2 deletions src/components/ChatProvider/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ describe('the ChatProvider component', () => {
result.current.connect('mockToken');

setImmediate(() => {
expect(mockOnError).toHaveBeenCalledWith('mockError');
expect(mockOnError).toHaveBeenCalledWith(
new Error("There was a problem connecting to Twilio's conversation service.")
);
done();
});
});
Expand All @@ -152,6 +154,8 @@ describe('the ChatProvider component', () => {
result.current.connect('mockToken');
await waitForNextUpdate();

expect(mockOnError).toHaveBeenCalledWith('mockError');
expect(mockOnError).toHaveBeenCalledWith(
new Error('There was a problem getting the Conversation associated with this room.')
);
});
});
8 changes: 6 additions & 2 deletions src/components/ChatProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export function ChatProvider({ children }: ChatProviderProps) {
window.chatClient = client;
setChatClient(client);
})
.catch(onError);
.catch(() => {
onError(new Error("There was a problem connecting to Twilio's conversation service."));
});
},
[onError]
);
Expand Down Expand Up @@ -74,7 +76,9 @@ export function ChatProvider({ children }: ChatProviderProps) {
window.chatConversation = newConversation;
setConversation(newConversation);
})
.catch(onError);
.catch(() => {
onError(new Error('There was a problem getting the Conversation associated with this room.'));
});
}
}, [room, chatClient, onError]);

Expand Down
2 changes: 1 addition & 1 deletion src/components/ErrorDialog/ErrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { TwilioError } from 'twilio-video';

interface ErrorDialogProps {
dismissError: Function;
error: TwilioError | null;
error: TwilioError | Error | null;
}

function ErrorDialog({ dismissError, error }: PropsWithChildren<ErrorDialogProps>) {
Expand Down
11 changes: 2 additions & 9 deletions src/components/VideoProvider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import React, { createContext, ReactNode } from 'react';
import {
CreateLocalTrackOptions,
ConnectOptions,
LocalAudioTrack,
LocalVideoTrack,
Room,
TwilioError,
} from 'twilio-video';
import { CreateLocalTrackOptions, ConnectOptions, LocalAudioTrack, LocalVideoTrack, Room } from 'twilio-video';
import { ErrorCallback } from '../../types';
import { SelectedParticipantProvider } from './useSelectedParticipant/useSelectedParticipant';

Expand Down Expand Up @@ -49,7 +42,7 @@ interface VideoProviderProps {
}

export function VideoProvider({ options, children, onError = () => {} }: VideoProviderProps) {
const onErrorCallback = (error: TwilioError) => {
const onErrorCallback: ErrorCallback = error => {
console.log(`ERROR: ${error.message}`, error);
onError(error);
};
Expand Down
4 changes: 2 additions & 2 deletions src/state/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import usePasscodeAuth from './usePasscodeAuth/usePasscodeAuth';
import { User } from 'firebase';

export interface StateContextType {
error: TwilioError | null;
setError(error: TwilioError | null): void;
error: TwilioError | Error | null;
setError(error: TwilioError | Error | null): void;
getToken(name: string, room: string, passcode?: string): Promise<string>;
user?: User | null | { displayName: undefined; photoURL: undefined; passcode?: string };
signIn?(passcode?: string): Promise<void>;
Expand Down
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,16 @@ declare global {
interface HTMLMediaElement {
setSinkId?(sinkId: string): Promise<undefined>;
}

// Helps create a union type with TwilioError
interface Error {
code: undefined;
}
}

export type Callback = (...args: any[]) => void;

export type ErrorCallback = (error: TwilioError) => void;
export type ErrorCallback = (error: TwilioError | Error) => void;

export type IVideoTrack = LocalVideoTrack | RemoteVideoTrack;

Expand Down