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

fix p2p if createLocalVideoTrack false #107

Merged
merged 4 commits into from
Oct 21, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@ public void onConnected(String streamId) {
}
});
}
streamStoppedByUser = false;
}

public void onPeerConnectionClosed() {
Expand All @@ -1488,9 +1489,13 @@ public boolean isStreaming(String streamId) {
public void onTakeConfiguration(String streamId, SessionDescription sdp) {
this.handler.post(() -> {
if (sdp.type == SessionDescription.Type.OFFER) {
PeerConnection pc = getPeerConnectionFor(streamId);
if (pc == null) {
createPeerConnection(streamId, false);
PeerInfo peerInfo = getPeerInfoFor(streamId);
if(peerInfo != null){
PeerConnection pc = peerInfo.peerConnection;
if (pc == null) {
boolean createLocalTrack = peerInfo.mode == Mode.P2P;
createPeerConnection(streamId, createLocalTrack);
}
}

setRemoteDescription(streamId, sdp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import android.content.Context;
Expand All @@ -25,6 +26,9 @@
import androidx.test.espresso.IdlingRegistry;
import androidx.test.espresso.IdlingResource;

import androidx.test.espresso.UiController;
import androidx.test.espresso.ViewAction;
import androidx.test.espresso.matcher.ViewMatchers;
import androidx.test.ext.junit.rules.ActivityScenarioRule;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.rule.GrantPermissionRule;
Expand All @@ -34,6 +38,7 @@
import androidx.test.uiautomator.Until;


import org.hamcrest.Matcher;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -231,7 +236,7 @@ public void testConferenceSwitchStreamSource() throws InterruptedException {

onView(withId(R.id. stats_popup_container)).perform(swipeUp());

//Thread.sleep(3000);
onView(withId(R.id.stats_popup_container)).perform(waitFor(2000));

onView(withId(R.id.multitrack_stats_popup_close_button)).perform(click());

Expand Down Expand Up @@ -281,4 +286,23 @@ public void testConferenceSwitchStreamSource() throws InterruptedException {
.check(matches(withText(R.string.disconnected)));
}

public static ViewAction waitFor(long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return ViewMatchers.isDisplayed(); // No constraints, can be used on any view
}

@Override
public String getDescription() {
return "Wait for " + millis + " milliseconds.";
}

@Override
public void perform(UiController uiController, View view) {
uiController.loopMainThreadForAtLeast(millis);
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import androidx.test.rule.GrantPermissionRule;
import androidx.test.uiautomator.UiDevice;

import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -54,6 +55,8 @@
public class PeerActivityTest {
private IdlingResource mIdlingResource;
private String runningTest;
private float videoBytesSent = 0;
private float videoBytesReceived = 0;

@Rule
public GrantPermissionRule permissionRule
Expand Down Expand Up @@ -111,16 +114,16 @@ public void testPeerToPeer() throws InterruptedException {

onView(withId(R.id.start_streaming_button)).check(matches(withText("Join")));
Espresso.closeSoftKeyboard();
onView(withId(R.id.stream_id_edittext)).perform(replaceText(PeerActivity.PEER_ROOM_ID_FOR_TEST));
String randomPeerRoomId = "p2p"+ RandomStringUtils.randomAlphanumeric(6);
onView(withId(R.id.stream_id_edittext)).perform(replaceText(randomPeerRoomId));

onView(withId(R.id.start_streaming_button)).perform(click());

onView(withId(R.id.start_streaming_button)).check(matches(withText("Leave")));

onView(withId(R.id.broadcasting_text_view))
.check(matches(anyOf(withText(R.string.connecting), withText(R.string.live))));

RemoteP2PParticipant remoteP2PParticipant = RemoteP2PParticipant.addP2PParticipant(PeerActivity.PEER_ROOM_ID_FOR_TEST, runningTest);
RemoteP2PParticipant remoteP2PParticipant = RemoteP2PParticipant.addP2PParticipant(randomPeerRoomId, runningTest);

Thread.sleep(10000);

Expand Down Expand Up @@ -172,10 +175,11 @@ public void testPeerToPeerReconnection() throws InterruptedException, IOExceptio
IdlingRegistry.getInstance().register(mIdlingResource);
activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
});
String randomPeerRoomId = "p2p"+ RandomStringUtils.randomAlphanumeric(6);

onView(withId(R.id.start_streaming_button)).check(matches(withText("Join")));
Espresso.closeSoftKeyboard();
onView(withId(R.id.stream_id_edittext)).perform(replaceText(PeerActivity.PEER_ROOM_ID_FOR_TEST));
onView(withId(R.id.stream_id_edittext)).perform(replaceText(randomPeerRoomId));

onView(withId(R.id.start_streaming_button)).perform(click());

Expand All @@ -184,7 +188,7 @@ public void testPeerToPeerReconnection() throws InterruptedException, IOExceptio
onView(withId(R.id.broadcasting_text_view))
.check(matches(anyOf(withText(R.string.connecting), withText(R.string.live))));

RemoteP2PParticipant remoteP2PParticipant = RemoteP2PParticipant.addP2PParticipant(PeerActivity.PEER_ROOM_ID_FOR_TEST, runningTest);
RemoteP2PParticipant remoteP2PParticipant = RemoteP2PParticipant.addP2PParticipant(randomPeerRoomId, runningTest);

Thread.sleep(10000);

Expand All @@ -198,6 +202,15 @@ public void testPeerToPeerReconnection() throws InterruptedException, IOExceptio

onView(withId(R.id.multitrack_stats_popup_play_stats_video_track_recyclerview)).inRoot(isDialog()).check(matches(isDisplayed()));


onView(withId(R.id.multitrack_stats_popup_bytes_sent_video_textview)).check((view, noViewFoundException) -> {
String text = ((TextView) view).getText().toString();
float value = Float.parseFloat(text);
assertTrue(value > 0f);
videoBytesSent = value;
});


onView(withId(R.id.multitrack_stats_popup_play_stats_video_track_recyclerview))
.check((view, noViewFoundException) -> {
if (noViewFoundException != null) {
Expand All @@ -206,8 +219,11 @@ public void testPeerToPeerReconnection() throws InterruptedException, IOExceptio
RecyclerView recyclerView = (RecyclerView) view;
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(0);
TextView bytesReceivedText = viewHolder.itemView.findViewById(R.id.track_stats_item_bytes_received_textview);

int bytesReceived = Integer.parseInt(( bytesReceivedText).getText().toString());

assertTrue(bytesReceived > 0);
videoBytesReceived = bytesReceived;
});

onView(withId(R.id. stats_popup_container)).perform(swipeUp());
Expand Down Expand Up @@ -240,6 +256,16 @@ public void testPeerToPeerReconnection() throws InterruptedException, IOExceptio

onView(withId(R.id.multitrack_stats_popup_play_stats_video_track_recyclerview)).inRoot(isDialog()).check(matches(isDisplayed()));


onView(withId(R.id.multitrack_stats_popup_bytes_sent_video_textview)).check((view, noViewFoundException) -> {
String text = ((TextView) view).getText().toString();
float value = Float.parseFloat(text);
assertTrue(value > 0f);
assertTrue(value > videoBytesSent);
videoBytesSent = value;
});


onView(withId(R.id.multitrack_stats_popup_play_stats_video_track_recyclerview))
.check((view, noViewFoundException) -> {
if (noViewFoundException != null) {
Expand All @@ -248,8 +274,11 @@ public void testPeerToPeerReconnection() throws InterruptedException, IOExceptio
RecyclerView recyclerView = (RecyclerView) view;
RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(0);
TextView bytesReceivedText = viewHolder.itemView.findViewById(R.id.track_stats_item_bytes_received_textview);

int bytesReceived = Integer.parseInt(( bytesReceivedText).getText().toString());

assertTrue(bytesReceived > 0);
assertTrue(bytesReceived > videoBytesReceived);
});

onView(withId(R.id. stats_popup_container)).perform(swipeUp());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package io.antmedia.webrtc_android_sample_app;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Window;
Expand All @@ -12,11 +11,12 @@
import androidx.test.espresso.IdlingResource;
import androidx.test.espresso.idling.CountingIdlingResource;

import org.apache.commons.lang3.RandomStringUtils;

public abstract class TestableActivity extends AppCompatActivity {
public CountingIdlingResource idlingResource = new CountingIdlingResource("Load", true);
protected SharedPreferences sharedPreferences;
public static String CONFERENCE_ROOM_ID_FOR_TEST = "room_12877";
public static String PEER_ROOM_ID_FOR_TEST = "p2pRoom_12877";
public static String PEER_ROOM_ID_FOR_TEST = "p2p"+ RandomStringUtils.randomAlphanumeric(3);

public void incrementIdle() {
idlingResource.increment();
Expand Down
Loading