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

[android] Reset room when JS thread reloads while on call #560

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,56 @@ public class CustomTwilioVideoView extends View implements LifecycleEventListene
private final Map<RemoteDataTrack, RemoteParticipant> dataTrackRemoteParticipantMap =
new HashMap<>();

public void releaseResource() {
thumbnailVideoView = null;
roomName = null;
accessToken = null;

/*
* Remove stream voice control
*/
if (themedReactContext != null && themedReactContext.getCurrentActivity() != null) {
themedReactContext.getCurrentActivity().setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
themedReactContext.removeLifecycleEventListener(this);
}
/*
* Always disconnect from the room before leaving the Activity to
* ensure any memory allocated to the Room resource is freed.
*/
if (room != null && room.getState() != Room.State.DISCONNECTED) {
room.disconnect();
disconnectedFromOnDestroy = true;
}
room = null;


if (localParticipant != null) {
localParticipant.unpublishTrack(localVideoTrack);
Copy link
Collaborator

@slycoder slycoder Oct 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to verify that localVideoTrack is not null?

localParticipant = null;
}

if (localVideoTrack != null) {
localVideoTrack.release();
localVideoTrack = null;
}

if (localAudioTrack != null) {
localAudioTrack.release();
localAudioTrack = null;
}

if (cameraCapturer != null) {
cameraCapturer.stopCapture();
cameraCapturer = null;
}

// Quit the data track message thread
dataTrackMessageThread.quit();
}

public CustomTwilioVideoView(ThemedReactContext context) {
super(context);
releaseResource();
this.themedReactContext = context;
this.eventEmitter = themedReactContext.getJSModule(RCTEventEmitter.class);

Expand Down Expand Up @@ -382,46 +430,7 @@ public void onHostPause() {

@Override
public void onHostDestroy() {
/*
* Remove stream voice control
*/
if (themedReactContext.getCurrentActivity() != null) {
themedReactContext.getCurrentActivity().setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);
}
/*
* Always disconnect from the room before leaving the Activity to
* ensure any memory allocated to the Room resource is freed.
*/
if (room != null && room.getState() != Room.State.DISCONNECTED) {
room.disconnect();
disconnectedFromOnDestroy = true;
}

/*
* Release the local media ensuring any memory allocated to audio or video is freed.
*/
if (localVideoTrack != null) {
localVideoTrack.release();
localVideoTrack = null;
}

if (localAudioTrack != null) {
localAudioTrack.release();
localAudioTrack = null;
}

// Quit the data track message thread
dataTrackMessageThread.quit();


}

public void releaseResource() {
themedReactContext.removeLifecycleEventListener(this);
room = null;
localVideoTrack = null;
thumbnailVideoView = null;
cameraCapturer = null;
releaseResource();
}

// ====== CONNECTING ===========================================================================
Expand Down