Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
31 changes: 22 additions & 9 deletions ExampleApp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,27 @@ const Example = () => {
setStatus("connected");
};

const _onRoomDidDisconnect = () => {
const _onRoomDidDisconnect = (event: any) => {
if (event.error) {
setErrorMessage(_formatErrorMessage(event));
}
resetStates();
};

const _onRoomDidFailToConnect = (event: any) => {
setStatus("disconnected");
setErrorMessage(_formatErrorMessage(event));
};

let errorMsg = event?.error || "Failed to connect to room";

const _formatErrorMessage = (event: any) => {
let errorMsg = event?.error || "Something went wrong";
if (event?.code) {
errorMsg += `\n\nError Code: ${event.code}`;
}

if (event?.errorExplanation) {
errorMsg += `\n\nDetails: ${event.errorExplanation}`;
}

setErrorMessage(errorMsg);
return errorMsg;
};

const _onParticipantAddedVideoTrack = ({ participant, track }: any) => {
Expand All @@ -233,6 +236,16 @@ const Example = () => {
});
};

const _onRoomIsReconnecting = (event: any) => {
setStatus("reconnecting");
_log(`Room Is Reconnecting ${event.roomName} ${event.error}`);
};

const _onRoomDidReconnect = (event: any) => {
setStatus("connected");
_log(`Room Did Reconnect ${event.roomName}`);
};

return (
<SafeAreaView style={styles.container}>
{status === "disconnected" && (
Expand All @@ -252,7 +265,7 @@ const Example = () => {
</ScrollView>
)}

{(status === "connected" || status === "connecting") && (
{(status === "connected" || status === "connecting" || status === "reconnecting") && (
<View style={styles.connectedWrapper}>
<View style={styles.headerContainer}>
<Text style={{ fontSize: 12 }}>Room Name: {roomDetails.roomName}</Text>
Expand Down Expand Up @@ -304,9 +317,9 @@ const Example = () => {
onNetworkQualityLevelsChanged={e => _log(`Network Quality ${e.participant.identity || 'local'} -> ${e.quality}`)}
onDominantSpeakerDidChange={e => _log(`Dominant Speaker -> ${e.participant?.identity || 'none'}`)}
onDataTrackMessageReceived={e => _log(`Data Track Message ${e.message}`)}
onRoomIsReconnecting={_onRoomIsReconnecting}
onRoomDidReconnect={_onRoomDidReconnect}
onDataChanged={_onDataChanged}
onRoomIsReconnecting={e => _log(`Room Is Reconnecting ${e.roomName} ${e.error}`)}
onRoomDidReconnect={e => _log(`Room Did Reconnect ${e.roomName}`)}
/>

<Modal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_REMOVED_AUDIO_TRACK;
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_REMOVED_DATA_TRACK;
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_PARTICIPANT_REMOVED_VIDEO_TRACK;
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_RECONNECTED;
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_RECONNECTING;
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_SCREEN_SHARE_CHANGED;
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_STATS_RECEIVED;
import static com.twiliorn.library.CustomTwilioVideoView.Events.ON_VIDEO_CHANGED;
Expand Down Expand Up @@ -569,6 +571,14 @@ public void connectToRoom() {
/*
* Create a VideoClient allowing you to connect to a Room
*/

if (this.accessToken == null || this.accessToken.isEmpty()) {
WritableMap event = new WritableNativeMap();
event.putString("error", "Access token is required");
pushEvent(CustomTwilioVideoView.this, ON_CONNECT_FAILURE, event);
return;
}

ConnectOptions.Builder connectOptionsBuilder = new ConnectOptions.Builder(this.accessToken);

if (this.roomName != null) {
Expand Down
14 changes: 11 additions & 3 deletions ios/RCTTWVideoModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ - (void)_toggleDataTrack:(bool)enabled {
}
// If track doesn't exist, do nothing
}

// Emit data changed event
[self sendEventCheckingListenerWithName:dataChanged
body:@{@"dataEnabled": @(enabled)}];
Expand Down Expand Up @@ -721,6 +721,13 @@ - (NSMutableDictionary *)convertLocalVideoTrackStats:
enableNetworkQualityReporting dominantSpeakerEnabled : (BOOL)
dominantSpeakerEnabled cameraType : (NSString *)
cameraType enableDataTrack : (BOOL) enableDataTrack) {

if (accessToken == nil || [accessToken length] == 0) {
NSMutableDictionary *body = [@{@"error": @"Access token is required"} mutableCopy];
[self sendEventCheckingListenerWithName:roomDidFailToConnect body:body];
return;
}

// Only create video track if enabled during connect
if (enableVideo) {
[self _createVideoTrack:cameraType];
Expand Down Expand Up @@ -965,7 +972,7 @@ - (void)room:(TVIRoom *)room didDisconnectWithError:(nullable NSError *)error {

- (void)room:(TVIRoom *)room
didFailToConnectWithError:(nonnull NSError *)error {
// Ensure any lingering local media is cleaned up
// Ensure any lingering local media is cleaned up
[self clearAudioInstance];
[self clearCameraInstance];
[self clearDataInstance];
Expand All @@ -981,7 +988,8 @@ - (void)room:(TVIRoom *)room
[body addEntriesFromDictionary:@{
@"error": error.localizedDescription ?: @"",
@"code": @(error.code),
@"errorExplanation": error.localizedFailureReason ?: error.localizedDescription ?: @""
@"errorExplanation": error.localizedFailureReason ?: error.localizedDescription ?
: @""
}];
}

Expand Down