From 41f5c5d88ca3ee6f2290d78242109853ee94c889 Mon Sep 17 00:00:00 2001 From: burak-58 <39169933+burak-58@users.noreply.github.com> Date: Sun, 19 Nov 2023 23:39:47 +0300 Subject: [PATCH 1/4] Remove reconnection in activity (#44) * delete reconnection releated codes in MainActivity * fix py script * change selenium version * remove tests for deprecated class --------- Co-authored-by: burak-58 --- .github/workflows/gradle.yml | 12 +- multitrack-conference-server.py | 65 +++-- webrtc-android-sample-app/build.gradle | 1 + .../ConferenceActivityTest.java | 5 +- .../MultitrackConferenceActivityTest.java | 233 +----------------- .../RemoteParticipant.java | 95 +++++++ .../TrackBasedConferenceActivityTest.java | 105 +++----- .../MainActivity.java | 34 --- .../SettingsActivity.java | 11 + .../TrackBasedConferenceActivity.java | 2 + 10 files changed, 201 insertions(+), 362 deletions(-) create mode 100644 webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/RemoteParticipant.java diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 88b6d8d2..1121fd60 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -40,9 +40,12 @@ jobs: python-version: '3.9' - name: Install python packages - run: pip3 install requests selenium==3.141.0 flask webdriver-manager - - + run: | + wget https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/119.0.6045.105/linux64/chromedriver-linux64.zip + unzip chromedriver-linux64.zip + cp chromedriver-linux64/chromedriver /home/ubuntu + pip3 install requests selenium==4.14 flask + - name: Run Multitrack Conference Test Server run: python3 multitrack-conference-server.py & @@ -60,7 +63,7 @@ jobs: script: | touch emulator.log chmod 777 emulator.log - adb logcat >> emulator.log & + adb logcat io.antmedia:I >> emulator.log & ./gradlew jacocoTestReport; EXIT_CODE=$?; exit $EXIT_CODE - name: Archive Test Report @@ -72,6 +75,7 @@ jobs: webrtc-android-sample-app/build/reports/tests/testDebugUnitTest/ webrtc-android-sample-app/build/reports/jacoco/jacocoTestReport/ webrtc-android-sample-app/build/reports/androidTests/ + webrtc-android-sample-app/build/outputs/connected_android_test_additional_output/ webrtc-android-framework/build/reports/tests/testDebugUnitTest/ webrtc-android-framework/build/reports/jacoco/jacocoTestReport/ webrtc-android-framework/build/reports/androidTests/ diff --git a/multitrack-conference-server.py b/multitrack-conference-server.py index 3dc6ec42..9e610c97 100644 --- a/multitrack-conference-server.py +++ b/multitrack-conference-server.py @@ -8,32 +8,36 @@ from selenium.webdriver.common.alert import Alert from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from flask import Flask, request -from webdriver_manager.chrome import ChromeDriverManager +from selenium.webdriver.chrome.service import Service + class Browser: def init(self, is_headless): - chrome_options = Options() - chrome_options.add_experimental_option("detach", True) - chrome_options.add_argument("--use-fake-ui-for-media-stream") - chrome_options.add_argument("--use-fake-device-for-media-stream") - chrome_options.add_argument('--log-level=3') - chrome_options.add_argument('--no-sandbox') - chrome_options.add_argument('--disable-extensions') - chrome_options.add_argument('--disable-gpu') - chrome_options.add_argument('--disable-dev-shm-usage') - chrome_options.add_argument('--disable-setuid-sandbox') + browser_options = Options() + browser_options.add_experimental_option("detach", True) + browser_options.add_argument("--use-fake-ui-for-media-stream") + browser_options.add_argument("--use-fake-device-for-media-stream") + browser_options.add_argument('--log-level=3') + browser_options.add_argument('--no-sandbox') + browser_options.add_argument('--disable-extensions') + browser_options.add_argument('--disable-gpu') + browser_options.add_argument('--disable-dev-shm-usage') + browser_options.add_argument('--disable-setuid-sandbox') if is_headless: - chrome_options.add_argument("--headless") - + browser_options.add_argument("--headless") + dc = DesiredCapabilities.CHROME.copy() dc['goog:loggingPrefs'] = { 'browser':'ALL' } + service = Service(executable_path='/home/ubuntu/chromedriver') + #service = Service(executable_path='C:/WebDriver/chromedriver.exe') - self.driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options) + self.driver = webdriver.Chrome(service=service, options=browser_options) def open_in_new_tab(self, url, tab_id): + self.driver.switch_to.window(self.driver.window_handles[0]) self.driver.execute_script("window.open('about:blank', '"+tab_id+"');") print (self.driver.window_handles) self.driver.switch_to.window(tab_id) @@ -57,6 +61,9 @@ def write_to_element(self, element, text): def click_element(self, element): element.click() + def switch_to_tab(self, tab_id): + self.driver.switch_to.window(tab_id) + def close(self): self.driver.close() @@ -75,29 +82,45 @@ def close_all(self): @app.route('/create', methods=['GET']) def create(): -# room = request.args.get('room') - chrome.open_in_new_tab(url, "p1") + room = request.args.get('room') + test = request.args.get('test') + participant = request.args.get('participant') + print("\n create for room:"+room+":"+participant+" in "+test) + chrome.open_in_new_tab(url+"?roomId="+room+"&streamId="+participant, participant) return f'Room created', 200 @app.route('/join', methods=['GET']) def join(): + room = request.args.get('room') + test = request.args.get('test') + participant = request.args.get('participant') + print("\n join for room:"+room+":"+participant+" in "+test) + chrome.switch_to_tab(participant) join_button = chrome.get_element_by_id("join_publish_button") join_button.click() return f'Joined the room', 200 @app.route('/leave', methods=['GET']) def leave(): + room = request.args.get('room') + test = request.args.get('test') + participant = request.args.get('participant') + print("\n leave for room:"+room+":"+participant+" in "+test) + chrome.switch_to_tab(participant) leave_button = chrome.get_element_by_id("stop_publish_button") leave_button.click() return f'Left the room', 200 @app.route('/delete', methods=['GET']) def delete(): - #chrome.close() - #return f'Tab closed', 200 - for handle in chrome.window_handles: - chrome.switch_to.window(handle) - chrome.close() + room = request.args.get('room') + test = request.args.get('test') + participant = request.args.get('participant') + print("\n delete for room:"+room+":"+participant+" in "+test) + chrome.switch_to_tab(participant) + chrome.close() + return f'Tab closed', 200 + if __name__ == '__main__': app.run(host='0.0.0.0', port=3030) \ No newline at end of file diff --git a/webrtc-android-sample-app/build.gradle b/webrtc-android-sample-app/build.gradle index 08bfca51..2fb09e53 100644 --- a/webrtc-android-sample-app/build.gradle +++ b/webrtc-android-sample-app/build.gradle @@ -14,6 +14,7 @@ android { versionName "1.0" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunnerArguments useTestStorageService: "true" } diff --git a/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/ConferenceActivityTest.java b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/ConferenceActivityTest.java index 62789c2c..cbac37b8 100644 --- a/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/ConferenceActivityTest.java +++ b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/ConferenceActivityTest.java @@ -20,6 +20,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.rule.GrantPermissionRule; +import org.apache.commons.lang3.RandomStringUtils; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -52,6 +53,7 @@ public class ConferenceActivityTest { @Rule public GrantPermissionRule permissionRule = GrantPermissionRule.grant(AbstractSampleSDKActivity.REQUIRED_PUBLISH_PERMISSIONS); + private String roomName; @Before public void before() { @@ -93,12 +95,13 @@ protected void finished(Description description) { @Test public void testJoinConfereceActivity() { Intent intent = new Intent(ApplicationProvider.getApplicationContext(), ConferenceActivity.class); - + roomName = "room_"+RandomStringUtils.randomNumeric(3); ActivityScenario scenario = ActivityScenario.launch(intent); scenario.onActivity(new ActivityScenario.ActivityAction() { @Override public void perform(ConferenceActivity activity) { + SettingsActivity.changeRoomName(activity, roomName); mIdlingResource = activity.getIdlingResource(); IdlingRegistry.getInstance().register(mIdlingResource); activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); diff --git a/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/MultitrackConferenceActivityTest.java b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/MultitrackConferenceActivityTest.java index 0676062b..03669143 100644 --- a/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/MultitrackConferenceActivityTest.java +++ b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/MultitrackConferenceActivityTest.java @@ -23,6 +23,7 @@ import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.GrantPermissionRule; +import org.apache.commons.lang3.RandomStringUtils; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -34,6 +35,7 @@ import java.io.IOException; import okhttp3.Call; +import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -55,6 +57,7 @@ public class MultitrackConferenceActivityTest { @Rule public GrantPermissionRule permissionRule = GrantPermissionRule.grant(AbstractSampleSDKActivity.REQUIRED_PUBLISH_PERMISSIONS); + private String runningTest; @Before public void before() { @@ -90,6 +93,7 @@ protected void succeeded(Description description) { protected void starting(Description description) { Log.i("TestWatcher", "******\n*** "+description + " starting!\n"); + runningTest = description.toString(); } protected void finished(Description description) { @@ -98,102 +102,18 @@ protected void finished(Description description) { }; - @Test + @Test public void testJoinMultitrackRoom() { Intent intent = new Intent(ApplicationProvider.getApplicationContext(), MultitrackConferenceActivity.class); + final String roomName = "room_" + RandomStringUtils.randomNumeric(3); ActivityScenario scenario = ActivityScenario.launch(intent); scenario.onActivity(new ActivityScenario.ActivityAction() { @Override public void perform(MultitrackConferenceActivity activity) { - mIdlingResource = activity.getIdlingResource(); - IdlingRegistry.getInstance().register(mIdlingResource); - activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); - } - }); - - onView(withId(R.id.join_conference_button)).check(matches(withText("Join Conference"))); - onView(withId(R.id.join_conference_button)).perform(click()); - - onView(withId(R.id.join_conference_button)).check(matches(withText("Leave"))); - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - - onView(withId(R.id.broadcasting_text_view)).check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); - - onView(withId(R.id.join_conference_button)).perform(click()); - - onView(withId(R.id.broadcasting_text_view)).check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); - - IdlingRegistry.getInstance().unregister(mIdlingResource); - - } - - public class NetworkClient { - //private static final String BASE_URL = "http://192.168.1.26:3030/"; - private static final String BASE_URL = "http://10.0.2.2:3030/"; - - private final OkHttpClient client = new OkHttpClient(); - - public String get(String path) throws IOException { - Request request = new Request.Builder() - .url(BASE_URL + path) - .header("Connection", "close") // <== solution, not declare in Interceptor - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - return response.body().string(); - } - } - - class RemoteParticipant { - NetworkClient client = new NetworkClient(); - String response = null; - - public void join() { - try { - response = client.get("create"); - assertNotNull(response); - - response = client.get("join"); - assertNotNull(response); - - Log.i("RemoteParticipant", "join: " + response); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public void leave() { - try { - response = client.get("leave"); - assertNotNull(response); - - response = client.get("delete"); - assertNotNull(response); - - Log.i("RemoteParticipant", "leave: " + response); + SettingsActivity.changeRoomName(activity, roomName); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - } - - @Test - public void testJoinWithExternalParticipant() { - Intent intent = new Intent(ApplicationProvider.getApplicationContext(), MultitrackConferenceActivity.class); - - ActivityScenario scenario = ActivityScenario.launch(intent); - - scenario.onActivity(new ActivityScenario.ActivityAction() { - @Override - public void perform(MultitrackConferenceActivity activity) { mIdlingResource = activity.getIdlingResource(); IdlingRegistry.getInstance().register(mIdlingResource); activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); @@ -203,70 +123,12 @@ public void perform(MultitrackConferenceActivity activity) { onView(withId(R.id.join_conference_button)).check(matches(withText("Join Conference"))); onView(withId(R.id.join_conference_button)).perform(click()); - - addParticipant(); - - onView(withId(R.id.join_conference_button)).check(matches(withText("Leave"))); - - onView(withId(R.id.broadcasting_text_view)).check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); - - onView(withId(R.id.join_conference_button)).perform(click()); - - onView(withId(R.id.broadcasting_text_view)).check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); - - IdlingRegistry.getInstance().unregister(mIdlingResource); - - } - - - - - private void addParticipant() { - RemoteParticipant participant = new RemoteParticipant(); - participant.join(); try { - Thread.sleep(10000); + Thread.sleep(5000); } catch (InterruptedException e) { e.printStackTrace(); } - participant.leave(); - } - - - //@Test - public void testJoinWithoutVideo() { - Intent intent = new Intent(ApplicationProvider.getApplicationContext(), MultitrackConferenceActivity.class); - - ActivityScenario scenario = ActivityScenario.launch(intent); - - scenario.onActivity(new ActivityScenario.ActivityAction() { - @Override - public void perform(MultitrackConferenceActivity activity) { - mIdlingResource = activity.getIdlingResource(); - IdlingRegistry.getInstance().register(mIdlingResource); - activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); - } - }); - - onView(withId(R.id.control_audio_button)).check(matches(withText("Disable Audio"))); - onView(withId(R.id.control_audio_button)).perform(click()); - - onView(withId(R.id.control_video_button)).check(matches(withText("Disable Video"))); - onView(withId(R.id.control_video_button)).perform(click()); - - onView(withId(R.id.join_conference_button)).check(matches(withText("Join Conference"))); - onView(withId(R.id.join_conference_button)).perform(click()); - - addParticipant(); - - onView(withId(R.id.control_audio_button)).check(matches(withText("Enable Audio"))); - onView(withId(R.id.control_audio_button)).perform(click()); - - onView(withId(R.id.control_video_button)).check(matches(withText("Enable Video"))); - onView(withId(R.id.control_video_button)).perform(click()); - - onView(withId(R.id.join_conference_button)).check(matches(withText("Leave"))); onView(withId(R.id.broadcasting_text_view)).check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); @@ -279,83 +141,4 @@ public void perform(MultitrackConferenceActivity activity) { } - @Test - public void testJoinPlayOnlyAsFirstPerson() { - Intent intent = new Intent(ApplicationProvider.getApplicationContext(), MultitrackConferenceActivity.class); - - ActivityScenario scenario = ActivityScenario.launch(intent); - - scenario.onActivity(new ActivityScenario.ActivityAction() { - @Override - public void perform(MultitrackConferenceActivity activity) { - mIdlingResource = activity.getIdlingResource(); - IdlingRegistry.getInstance().register(mIdlingResource); - activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); - } - }); - - onView(withId(R.id.play_only_switch)).check(matches(withText("Play Only"))); - onView(withId(R.id.play_only_switch)).perform(click()); - - onView(withId(R.id.join_conference_button)).check(matches(withText("Join Conference"))); - onView(withId(R.id.join_conference_button)).perform(click()); - - addParticipant(); - - - onView(withId(R.id.join_conference_button)).check(matches(withText("Leave"))); - - onView(withId(R.id.join_conference_button)).perform(click()); - - IdlingRegistry.getInstance().unregister(mIdlingResource); - - } - - @Test - public void testReconnect() { - Intent intent = new Intent(ApplicationProvider.getApplicationContext(), MultitrackConferenceActivity.class); - - ActivityScenario scenario = ActivityScenario.launch(intent); - - final MultitrackConferenceActivity[] mactivity = new MultitrackConferenceActivity[1]; - scenario.onActivity(new ActivityScenario.ActivityAction() { - @Override - public void perform(MultitrackConferenceActivity activity) { - mIdlingResource = activity.getIdlingResource(); - IdlingRegistry.getInstance().register(mIdlingResource); - activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); - mactivity[0] = activity; - } - }); - - onView(withId(R.id.join_conference_button)).check(matches(withText("Join Conference"))); - onView(withId(R.id.join_conference_button)).perform(click()); - - - addParticipant(); - - mactivity[0].changeWifiState(false); - - try { - Thread.sleep(3000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - mactivity[0].changeWifiState(true); - - - - onView(withId(R.id.join_conference_button)).check(matches(withText("Leave"))); - - onView(withId(R.id.broadcasting_text_view)).check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE))); - - onView(withId(R.id.join_conference_button)).perform(click()); - - //onView(withId(R.id.broadcasting_text_view)).check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); - - IdlingRegistry.getInstance().unregister(mIdlingResource); - - } - - } diff --git a/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/RemoteParticipant.java b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/RemoteParticipant.java new file mode 100644 index 00000000..f261e46c --- /dev/null +++ b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/RemoteParticipant.java @@ -0,0 +1,95 @@ +package io.antmedia.webrtc_android_sample_app; + +import static org.junit.Assert.assertNotNull; + +import android.util.Log; + +import org.apache.commons.lang3.RandomStringUtils; + +import java.io.IOException; + +import okhttp3.Call; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +class RemoteParticipant { + + NetworkClient client = new NetworkClient(); + String response = null; + String participantName = "p_"+ RandomStringUtils.randomNumeric(3); + + private String roomName; + private String runningTest; + + public RemoteParticipant(String roomName, String runningTest) { + this.roomName = roomName; + this.runningTest = runningTest; + } + + public class NetworkClient { + + private static final String REST_IP = "10.0.2.2"; + private static final int REST_PORT = 3030; + + private final OkHttpClient client = new OkHttpClient(); + + public String get(String path, String participantName) throws IOException { + HttpUrl httpUrl = new HttpUrl.Builder() + .scheme("http") + .host(REST_IP) + .port(REST_PORT) + .addPathSegment(path) + .addQueryParameter("room", roomName) + .addQueryParameter("test", runningTest) + .addQueryParameter("participant", participantName) + .build(); + + + Request request = new Request.Builder() + .url(httpUrl) + .header("Connection", "close") // <== solution, not declare in Interceptor + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + return response.body().string(); + } + } + + public void join() { + try { + response = client.get("create", participantName); + Log.i("RemoteParticipant", "create: " + response); + assertNotNull(response); + + response = client.get("join", participantName); + Log.i("RemoteParticipant", "join: " + response); + assertNotNull(response); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public void leave() { + try { + response = client.get("leave", participantName); + Log.i("RemoteParticipant", "leave: " + response); + assertNotNull(response); + + response = client.get("delete", participantName); + Log.i("RemoteParticipant", "delete: " + response); + assertNotNull(response); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static RemoteParticipant addParticipant(String roomName, String runningTest) { + RemoteParticipant participant = new RemoteParticipant(roomName, runningTest); + participant.join(); + + return participant; + } +} \ No newline at end of file diff --git a/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivityTest.java b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivityTest.java index 58e20529..bcd1048f 100644 --- a/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivityTest.java +++ b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivityTest.java @@ -8,7 +8,6 @@ import static androidx.test.espresso.matcher.ViewMatchers.withText; import static org.junit.Assert.assertNotNull; -import android.app.Instrumentation; import android.content.Intent; import android.util.Log; @@ -23,6 +22,7 @@ import androidx.test.platform.app.InstrumentationRegistry; import androidx.test.rule.GrantPermissionRule; +import org.apache.commons.lang3.RandomStringUtils; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -34,6 +34,7 @@ import java.io.IOException; import okhttp3.Call; +import okhttp3.HttpUrl; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; @@ -58,14 +59,14 @@ public class TrackBasedConferenceActivityTest { @Rule public ActivityScenarioRule activityScenarioRule = new ActivityScenarioRule<>(TrackBasedConferenceActivity.class); - + private String runningTest; @Before public void before() { //try before method to make @Rule run properly System.out.println("before test"); + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); - System.out.println("after sleep"); } @After @@ -81,6 +82,7 @@ public void after() { @Rule public TestWatcher watchman= new TestWatcher() { + @Override protected void failed(Throwable e, Description description) { Log.i("TestWatcher", "*** "+description + " failed!\n"); @@ -93,6 +95,7 @@ protected void succeeded(Description description) { protected void starting(Description description) { Log.i("TestWatcher", "******\n*** "+description + " starting!\n"); + runningTest = description.toString(); } protected void finished(Description description) { @@ -100,77 +103,14 @@ protected void finished(Description description) { } }; - public class NetworkClient { - - //private static final String BASE_URL = "http://192.168.1.26:3030/"; - private static final String BASE_URL = "http://10.0.2.2:3030/"; - - private final OkHttpClient client = new OkHttpClient(); - - public String get(String path) throws IOException { - Request request = new Request.Builder() - .url(BASE_URL + path) - .header("Connection", "close") // <== solution, not declare in Interceptor - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - return response.body().string(); - } - } - - class RemoteParticipant { - NetworkClient client = new NetworkClient(); - String response = null; - - public void join() { - try { - response = client.get("create"); - assertNotNull(response); - - response = client.get("join"); - assertNotNull(response); - - Log.i("RemoteParticipant", "join: " + response); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public void leave() { - try { - response = client.get("leave"); - assertNotNull(response); - - response = client.get("delete"); - assertNotNull(response); - - Log.i("RemoteParticipant", "leave: " + response); - - } catch (IOException e) { - //throw new RuntimeException(e); - } - } - } - - private void addParticipant() { - RemoteParticipant participant = new RemoteParticipant(); - participant.join(); - try { - Thread.sleep(10000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - participant.leave(); - } - - @Test public void testJoinMultitrackRoom() { + final String roomName = "room_" + RandomStringUtils.randomNumeric(3); + activityScenarioRule.getScenario().onActivity(new ActivityScenario.ActivityAction() { @Override public void perform(TrackBasedConferenceActivity activity) { - + SettingsActivity.changeRoomName(activity, roomName); mIdlingResource = activity.getIdlingResource(); IdlingRegistry.getInstance().register(mIdlingResource); activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); @@ -200,9 +140,11 @@ public void perform(TrackBasedConferenceActivity activity) { @Test public void testJoinWithExternalParticipant() { + final String roomName = "room_" + RandomStringUtils.randomNumeric(3); activityScenarioRule.getScenario().onActivity(new ActivityScenario.ActivityAction() { @Override public void perform(TrackBasedConferenceActivity activity) { + SettingsActivity.changeRoomName(activity, roomName); mIdlingResource = activity.getIdlingResource(); IdlingRegistry.getInstance().register(mIdlingResource); activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); @@ -213,8 +155,7 @@ public void perform(TrackBasedConferenceActivity activity) { onView(withId(R.id.join_conference_button)).perform(click()); - addParticipant(); - + RemoteParticipant participant = RemoteParticipant.addParticipant(roomName, runningTest); onView(withId(R.id.join_conference_button)).check(matches(withText("Leave"))); @@ -224,16 +165,19 @@ public void perform(TrackBasedConferenceActivity activity) { onView(withId(R.id.broadcasting_text_view)).check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); + participant.leave(); IdlingRegistry.getInstance().unregister(mIdlingResource); } //@Test public void testJoinWithoutVideo() { + final String roomName = "room_" + RandomStringUtils.randomNumeric(3); + activityScenarioRule.getScenario().onActivity(new ActivityScenario.ActivityAction() { @Override public void perform(TrackBasedConferenceActivity activity) { - + SettingsActivity.changeRoomName(activity, roomName); mIdlingResource = activity.getIdlingResource(); IdlingRegistry.getInstance().register(mIdlingResource); activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); @@ -249,7 +193,7 @@ public void perform(TrackBasedConferenceActivity activity) { onView(withId(R.id.join_conference_button)).check(matches(withText("Join Conference"))); onView(withId(R.id.join_conference_button)).perform(click()); - addParticipant(); + RemoteParticipant participant = RemoteParticipant.addParticipant(roomName, runningTest); onView(withId(R.id.control_audio_button)).check(matches(withText("Enable Audio"))); onView(withId(R.id.control_audio_button)).perform(click()); @@ -265,6 +209,7 @@ public void perform(TrackBasedConferenceActivity activity) { onView(withId(R.id.broadcasting_text_view)).check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); + participant.leave(); IdlingRegistry.getInstance().unregister(mIdlingResource); } @@ -272,9 +217,12 @@ public void perform(TrackBasedConferenceActivity activity) { @Test public void testJoinPlayOnlyAsFirstPerson() { + final String roomName = "room_" + RandomStringUtils.randomNumeric(3); + activityScenarioRule.getScenario().onActivity(new ActivityScenario.ActivityAction() { @Override public void perform(TrackBasedConferenceActivity activity) { + SettingsActivity.changeRoomName(activity, roomName); mIdlingResource = activity.getIdlingResource(); IdlingRegistry.getInstance().register(mIdlingResource); activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); @@ -287,23 +235,26 @@ public void perform(TrackBasedConferenceActivity activity) { onView(withId(R.id.join_conference_button)).check(matches(withText("Join Conference"))); onView(withId(R.id.join_conference_button)).perform(click()); - addParticipant(); - + RemoteParticipant participant = RemoteParticipant.addParticipant(roomName, runningTest); onView(withId(R.id.join_conference_button)).check(matches(withText("Leave"))); onView(withId(R.id.join_conference_button)).perform(click()); + participant.leave(); IdlingRegistry.getInstance().unregister(mIdlingResource); } @Test public void testReconnect() { + final String roomName = "room_" + RandomStringUtils.randomNumeric(3); + final TrackBasedConferenceActivity[] mactivity = new TrackBasedConferenceActivity[1]; activityScenarioRule.getScenario().onActivity(new ActivityScenario.ActivityAction() { @Override public void perform(TrackBasedConferenceActivity activity) { + SettingsActivity.changeRoomName(activity, roomName); mIdlingResource = activity.getIdlingResource(); IdlingRegistry.getInstance().register(mIdlingResource); activity.sendBroadcast(new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)); @@ -314,8 +265,7 @@ public void perform(TrackBasedConferenceActivity activity) { onView(withId(R.id.join_conference_button)).check(matches(withText("Join Conference"))); onView(withId(R.id.join_conference_button)).perform(click()); - - addParticipant(); + RemoteParticipant participant = RemoteParticipant.addParticipant(roomName, runningTest); mactivity[0].changeWifiState(false); @@ -336,6 +286,7 @@ public void perform(TrackBasedConferenceActivity activity) { //onView(withId(R.id.broadcasting_text_view)).check(ViewAssertions.matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE))); + participant.leave(); IdlingRegistry.getInstance().unregister(mIdlingResource); } diff --git a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/MainActivity.java b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/MainActivity.java index a97aa87f..9a6002b8 100644 --- a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/MainActivity.java +++ b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/MainActivity.java @@ -68,31 +68,7 @@ public class MainActivity extends AbstractSampleSDKActivity { private Spinner streamInfoListSpinner; public static final String WEBRTC_MODE = "WebRTC_MODE"; - // variables for handling reconnection attempts after disconnected - final int RECONNECTION_PERIOD_MLS = 1000; - - final int RECONNECTION_CONTROL_PERIOD_MLS = 10000; - private boolean stoppedStream = false; - Handler reconnectionHandler = new Handler(); - Runnable reconnectionRunnable = new Runnable() { - @Override - public void run() { - if (!stoppedStream && !webRTCClient.isStreaming()) { - Log.i(MainActivity.class.getSimpleName(),"Try to reconnect in reconnectionRunnable"); - webRTCClient.stopStream(); - - webRTCClient.startStream(); - if (webRTCMode == IWebRTCClient.MODE_JOIN) - { - pipViewRenderer.setZOrderOnTop(true); - } - } - if (!stoppedStream) { - reconnectionHandler.postDelayed(this, RECONNECTION_CONTROL_PERIOD_MLS); - } - } - }; private TextView broadcastingView; private EditText streamIdEditText; @@ -206,12 +182,9 @@ public void startStreaming(View v) { else { ((Button)v).setText("Start " + operationName); Log.i(getClass().getSimpleName(), "Calling stopStream"); - reconnectionHandler.removeCallbacks(reconnectionRunnable); webRTCClient.stopStream(); stoppedStream = true; - } - } @Override @@ -300,13 +273,6 @@ public void onDisconnected(String streamId) { if (!stoppedStream) { Log.i(getClass().getSimpleName(),"Disconnected. Trying to reconnect"); Toast.makeText(this, "Disconnected.Trying to reconnect", Toast.LENGTH_LONG).show(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { - if (!reconnectionHandler.hasCallbacks(reconnectionRunnable)) { - reconnectionHandler.postDelayed(reconnectionRunnable, RECONNECTION_PERIOD_MLS); - } - } else { - reconnectionHandler.postDelayed(reconnectionRunnable, RECONNECTION_PERIOD_MLS); - } } else { Toast.makeText(this, "Stopped the stream", Toast.LENGTH_LONG).show(); } diff --git a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/SettingsActivity.java b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/SettingsActivity.java index 79c72ea6..0dfa701b 100644 --- a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/SettingsActivity.java +++ b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/SettingsActivity.java @@ -1,6 +1,7 @@ package io.antmedia.webrtc_android_sample_app; import android.app.Activity; +import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.view.View; @@ -60,4 +61,14 @@ private void saveSettings() { Toast.makeText(this, "Saved", Toast.LENGTH_LONG).show(); } + + public static void changeRoomName(Context context, String roomName) { + SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); + editor.putString(context.getString(R.string.roomId), roomName); + editor.apply(); + } + + public static String getRoomName(Context context) { + return PreferenceManager.getDefaultSharedPreferences(context).getString(context.getString(R.string.roomId), DEFAULT_ROOM_NAME); + } } diff --git a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivity.java b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivity.java index cf365de4..567caf6c 100644 --- a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivity.java +++ b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivity.java @@ -189,6 +189,7 @@ public void onPublishStarted(String streamId) { broadcastingView.setVisibility(View.VISIBLE); scheduleSendStatusTimer(); + decrementIdle(); } @Override @@ -252,6 +253,7 @@ public void onLeftTheRoom(String roomId) { } public void publishStream(String streamId) { + incrementIdle(); if (!this.playOnlyMode) { webRTCClient.publish(streamId, token, videoCallEnabled, audioCallEnabled, subscriberId, subscriberCode, streamName, roomId); } From 7d4eb04b54ca95294fe8777e3e1dba02ebca5ac6 Mon Sep 17 00:00:00 2001 From: Mustafa BOLEKEN Date: Sun, 19 Nov 2023 23:40:53 +0300 Subject: [PATCH 2/4] If we get stream id in use during reconnection start publish again during (#43) --- .../io/antmedia/webrtc_android_sample_app/MainActivity.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/MainActivity.java b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/MainActivity.java index 9a6002b8..9afc6552 100644 --- a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/MainActivity.java +++ b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/MainActivity.java @@ -236,6 +236,10 @@ public void noStreamExistsToPlay(String streamId) { public void streamIdInUse(String streamId) { Log.w(getClass().getSimpleName(), "streamIdInUse"); Toast.makeText(this, "Stream id is already in use.", Toast.LENGTH_LONG).show(); + if (webRTCClient.isReconnectionInProgress()) { + webRTCClient.stopStream(streamId); + webRTCClient.startStream(streamId); + } decrementIdle(); } From cb09edbece5637cf01adc43d203a795109d7f5dd Mon Sep 17 00:00:00 2001 From: Mustafa BOLEKEN Date: Wed, 22 Nov 2023 22:07:29 +0300 Subject: [PATCH 3/4] Move rotation logic from onFrame to OrientationEventListener (#28) * Move rotation logic from onFrame to OrientationEventListener * Add testRotateScreen * Get video capturer from getter * Change ci test device arch * Revert "Change ci test device arch" * Update WebRTCClientTest.java * change timeout * ignore sample activities coverage * add new test --------- Co-authored-by: burak-58 Co-authored-by: burak-58 <39169933+burak-58@users.noreply.github.com> --- codecov.yml | 2 ++ .../org/webrtc/ScreenCapturerAndroid.java | 27 ++++++++++--------- .../ScreenCapturerAndroidTest.java | 18 ++++++++----- .../WebRTCClientTest.java | 3 ++- .../MultitrackConferenceActivityTest.java | 2 ++ .../ScreenCaptureActivityTest.java | 4 +-- .../ScreenCaptureActivity.java | 24 +++++++++++++++++ 7 files changed, 58 insertions(+), 22 deletions(-) diff --git a/codecov.yml b/codecov.yml index df3d704f..c19a2cc5 100644 --- a/codecov.yml +++ b/codecov.yml @@ -3,4 +3,6 @@ coverage: patch: default: target: 75.0 +ignore: + - "webrtc-android-sample-app" diff --git a/webrtc-android-framework/src/main/java/org/webrtc/ScreenCapturerAndroid.java b/webrtc-android-framework/src/main/java/org/webrtc/ScreenCapturerAndroid.java index 315823cd..996f4f5f 100644 --- a/webrtc-android-framework/src/main/java/org/webrtc/ScreenCapturerAndroid.java +++ b/webrtc-android-framework/src/main/java/org/webrtc/ScreenCapturerAndroid.java @@ -53,7 +53,7 @@ public class ScreenCapturerAndroid implements VideoCapturer, VideoSink { @Nullable private MediaProjection mediaProjection; private boolean isDisposed; private WindowManager windowManager; - private int deviceRotation = 0; + public int deviceRotation = 0; private static final String TAG = ScreenCapturerAndroid.class.getSimpleName(); @Nullable private MediaProjectionManager mediaProjectionManager; @@ -213,25 +213,28 @@ VIRTUAL_DISPLAY_DPI, DISPLAY_FLAGS, new Surface(surfaceTextureHelper.getSurfaceT null /* callback */, null /* callback handler */); } - // This is called on the internal looper thread of {@Code SurfaceTextureHelper}. - @Override - public void onFrame(VideoFrame frame) { - numCapturedFrames++; - Log.v(TAG, "Frame received " + numCapturedFrames); - int rotation = windowManager.getDefaultDisplay().getRotation(); + public void rotateScreen(int rotation) { if (deviceRotation != rotation) { Log.w("Rotation", "onFrame: " + rotation); deviceRotation = rotation; - if (deviceRotation*90 % 180 != 0) { - virtualDisplay.resize(height, width, VIRTUAL_DISPLAY_DPI); - surfaceTextureHelper.setTextureSize(height, width); - } - else { + if (deviceRotation == 0) { virtualDisplay.resize(width, height, VIRTUAL_DISPLAY_DPI); surfaceTextureHelper.setTextureSize(width, height); + } else if (deviceRotation == 180) { + // 180 degree is not supported by MediaProjection + } else { + virtualDisplay.resize(height, width, VIRTUAL_DISPLAY_DPI); + surfaceTextureHelper.setTextureSize(height, width); } } + } + + // This is called on the internal looper thread of {@Code SurfaceTextureHelper}. + @Override + public void onFrame(VideoFrame frame) { + numCapturedFrames++; + Log.v(TAG, "Frame received " + numCapturedFrames); capturerObserver.onFrameCaptured(frame); } diff --git a/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/ScreenCapturerAndroidTest.java b/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/ScreenCapturerAndroidTest.java index 0cf23dba..fa8abbbf 100644 --- a/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/ScreenCapturerAndroidTest.java +++ b/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/ScreenCapturerAndroidTest.java @@ -29,7 +29,7 @@ public class ScreenCapturerAndroidTest { @Test - public void testOnFrameRotation() { + public void testRotateScreen() { ScreenCapturerAndroid screenCapturerAndroid = spy(new ScreenCapturerAndroid(null, null)); WindowManager windowManager = Mockito.spy(WindowManager.class); @@ -43,30 +43,34 @@ public void testOnFrameRotation() { screenCapturerAndroid.setVirtualDisplay(virtualDisplay); screenCapturerAndroid.setSurfaceTextureHelper(surfaceTextureHelper); - screenCapturerAndroid.setCapturerObserver(mock(CapturerObserver.class)); + CapturerObserver capturerObserver = mock(CapturerObserver.class); + screenCapturerAndroid.setCapturerObserver(capturerObserver); int width = 540; int height = 960; screenCapturerAndroid.setWidth(width); screenCapturerAndroid.setHeight(height); - VideoFrame frame = new VideoFrame(mock(VideoFrame.Buffer.class), 0, 0); - screenCapturerAndroid.onFrame(frame); + screenCapturerAndroid.deviceRotation = 0; + + screenCapturerAndroid.rotateScreen(90); Mockito.when(display.getRotation()).thenReturn(1); - screenCapturerAndroid.onFrame(frame); + screenCapturerAndroid.rotateScreen(0); Mockito.verify(virtualDisplay).resize(height, width, VIRTUAL_DISPLAY_DPI); Mockito.verify(surfaceTextureHelper).setTextureSize(height, width); Mockito.when(display.getRotation()).thenReturn(2); - screenCapturerAndroid.onFrame(frame); + screenCapturerAndroid.rotateScreen(90); Mockito.verify(virtualDisplay).resize(width, height, VIRTUAL_DISPLAY_DPI); Mockito.verify(surfaceTextureHelper).setTextureSize(width,height); + VideoFrame frame = mock(VideoFrame.class); + screenCapturerAndroid.onFrame(frame); - + Mockito.verify(capturerObserver).onFrameCaptured(frame); } @Test diff --git a/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/WebRTCClientTest.java b/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/WebRTCClientTest.java index a8ca5325..7cc97762 100644 --- a/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/WebRTCClientTest.java +++ b/webrtc-android-framework/src/test/java/io/antmedia/webrtcandroidframework/WebRTCClientTest.java @@ -12,6 +12,7 @@ import static org.mockito.Matchers.anyLong; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.atLeastOnce; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doThrow; @@ -905,7 +906,7 @@ public void testCreatePeerConnection() { doNothing().when(webRTCClient).reportError(anyString(), anyString()); doThrow(new NullPointerException()).when(webRTCClient).createMediaConstraintsInternal(); webRTCClient.createPeerConnection(streamId); - verify(webRTCClient, timeout(1000)).reportError(eq(streamId), anyString()); + verify(webRTCClient, timeout(10000)).reportError(eq(streamId), anyString()); } diff --git a/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/MultitrackConferenceActivityTest.java b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/MultitrackConferenceActivityTest.java index 03669143..e0ad5c4c 100644 --- a/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/MultitrackConferenceActivityTest.java +++ b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/MultitrackConferenceActivityTest.java @@ -124,6 +124,8 @@ public void perform(MultitrackConferenceActivity activity) { onView(withId(R.id.join_conference_button)).perform(click()); onView(withId(R.id.join_conference_button)).check(matches(withText("Leave"))); + + //TODO remove sleep try { Thread.sleep(5000); } catch (InterruptedException e) { diff --git a/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/ScreenCaptureActivityTest.java b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/ScreenCaptureActivityTest.java index f01b340d..46d626df 100644 --- a/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/ScreenCaptureActivityTest.java +++ b/webrtc-android-sample-app/src/androidTest/java/io/antmedia/webrtc_android_sample_app/ScreenCaptureActivityTest.java @@ -96,7 +96,7 @@ public void perform(ScreenCaptureActivity activity) { UiDevice device = UiDevice.getInstance(getInstrumentation()); onView(withId(R.id.rbScreen)).perform(click()); - UiObject2 button = device.wait(Until.findObject(By.text("Start now")), 10000); + UiObject2 button = device.wait(Until.findObject(By.text("Start now")), 100000); assertNotNull(button); button.click(); @@ -123,7 +123,7 @@ public void perform(ScreenCaptureActivity activity) { //FIXME: without this sleep, it's failing because onFinish event received but resources are not closed yet try { - Thread.sleep(3000); + Thread.sleep(30000); } catch (InterruptedException e) { throw new RuntimeException(e); } diff --git a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/ScreenCaptureActivity.java b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/ScreenCaptureActivity.java index 9fbb17a2..ac7fc9df 100644 --- a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/ScreenCaptureActivity.java +++ b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/ScreenCaptureActivity.java @@ -6,11 +6,15 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.PackageManager; +import android.hardware.SensorManager; +import android.media.projection.MediaProjection; +import android.media.projection.MediaProjectionManager; import android.os.Build; import android.os.Bundle; import android.preference.PreferenceManager; import android.util.DisplayMetrics; import android.util.Log; +import android.view.OrientationEventListener; import android.view.View; import android.view.Window; import android.view.WindowManager; @@ -20,6 +24,7 @@ import android.widget.Toast; import org.webrtc.RendererCommon; +import org.webrtc.ScreenCapturerAndroid; import org.webrtc.SurfaceViewRenderer; import org.webrtc.VideoTrack; @@ -47,6 +52,8 @@ public class ScreenCaptureActivity extends AbstractSampleSDKActivity { private static final String TAG = ScreenCaptureActivity.class.getSimpleName(); private View broadcastingView; + private OrientationEventListener orientationEventListener; + /* ATTENTION: Android refresh rate changes according to the screen changes. @@ -130,6 +137,23 @@ else if(checkedId == R.id.rbRear) { PreferenceManager.getDefaultSharedPreferences(this /* Activity context */); serverUrl = sharedPreferences.getString(getString(R.string.serverAddress), SettingsActivity.DEFAULT_WEBSOCKET_URL); webRTCClient.init(serverUrl, streamIdEditText.getText().toString(), IWebRTCClient.MODE_PUBLISH, tokenId, this.getIntent()); + + orientationEventListener + = new OrientationEventListener(this, SensorManager.SENSOR_DELAY_NORMAL){ + + @Override + public void onOrientationChanged(int rotationDegree) { + if (webRTCClient.getVideoCapturer() instanceof ScreenCapturerAndroid) { + ((ScreenCapturerAndroid) webRTCClient.getVideoCapturer()).rotateScreen(rotationDegree); + } + }}; + + if (orientationEventListener.canDetectOrientation()){ + orientationEventListener.enable(); + } + else{ + orientationEventListener.disable(); + } } @Override From 1f642c7e07f8d2e919a823ad2adffedd60912bcd Mon Sep 17 00:00:00 2001 From: Mustafa BOLEKEN Date: Thu, 23 Nov 2023 06:31:41 +0300 Subject: [PATCH 4/4] Fix Multitrack Conference Audio Toggle Not Working Issue (#42) * Add enableAudio usage * Add unit tests --- .../TrackBasedConferenceActivity.java | 11 +++- .../TrackBasedConferenceActivityUnitTest.java | 57 +++++++++++++++++++ 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 webrtc-android-sample-app/src/test/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivityUnitTest.java diff --git a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivity.java b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivity.java index 567caf6c..2273204f 100644 --- a/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivity.java +++ b/webrtc-android-sample-app/src/main/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivity.java @@ -282,7 +282,7 @@ public void controlAudio(View view) { audioButton.setText("Enable Audio"); sendNotificationEvent(MIC_MUTED, null); } else { - webRTCClient.isAudioOn(); + webRTCClient.enableAudio(); audioButton.setText("Disable Audio"); sendNotificationEvent(MIC_UNMUTED, null); } @@ -396,8 +396,15 @@ else if(eventType.equals(UPDATE_STATUS)) { } } + // This method is added for unit testing purposes + public void setWebRTCClient(WebRTCClient webRTCClient) { + this.webRTCClient = webRTCClient; + } - + // This method is added for unit testing purposes + public void setAudioButton(Button audioButton) { + this.audioButton = audioButton; + } } diff --git a/webrtc-android-sample-app/src/test/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivityUnitTest.java b/webrtc-android-sample-app/src/test/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivityUnitTest.java new file mode 100644 index 00000000..b63c0760 --- /dev/null +++ b/webrtc-android-sample-app/src/test/java/io/antmedia/webrtc_android_sample_app/TrackBasedConferenceActivityUnitTest.java @@ -0,0 +1,57 @@ +package io.antmedia.webrtc_android_sample_app; + +import static org.mockito.Matchers.anyInt; +import static org.mockito.Matchers.anyString; +import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doNothing; +import static org.mockito.Mockito.when; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.preference.PreferenceManager; +import android.view.Window; +import android.view.WindowManager; +import android.widget.Button; +import android.widget.Switch; + +import org.json.JSONObject; +import org.junit.Test; +import org.mockito.Mockito; +import org.webrtc.SurfaceViewRenderer; + +import io.antmedia.webrtcandroidframework.WebRTCClient; + +public class TrackBasedConferenceActivityUnitTest { + + + @Test + public void testControlAudio() { + TrackBasedConferenceActivity trackBasedConferenceActivity = Mockito.spy(new TrackBasedConferenceActivity()); + doNothing().when(trackBasedConferenceActivity).sendNotificationEvent(anyString(), Mockito.any(JSONObject.class)); + + Button audioButton = Mockito.mock(Button.class); + doNothing().when(audioButton).setText(anyString()); + + WebRTCClient webRTCClient = Mockito.mock(WebRTCClient.class); + doNothing().when(webRTCClient).enableAudio(); + doNothing().when(webRTCClient).disableAudio(); + + trackBasedConferenceActivity.setWebRTCClient(webRTCClient); + trackBasedConferenceActivity.setAudioButton(audioButton); + + Mockito.verify(webRTCClient, Mockito.times(0)).disableAudio(); + Mockito.verify(webRTCClient, Mockito.times(0)).enableAudio(); + + when(webRTCClient.isAudioOn()).thenReturn(true); + trackBasedConferenceActivity.controlAudio(null); + Mockito.verify(webRTCClient, Mockito.times(1)).disableAudio(); + Mockito.verify(webRTCClient, Mockito.times(0)).enableAudio(); + + when(webRTCClient.isAudioOn()).thenReturn(false); + trackBasedConferenceActivity.controlAudio(null); + Mockito.verify(webRTCClient, Mockito.times(1)).disableAudio(); + Mockito.verify(webRTCClient, Mockito.times(1)).enableAudio(); + } +} \ No newline at end of file