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

feat: add scaleBehavior for subscriber and publisher view #474

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
android code
  • Loading branch information
deermichel committed Feb 17, 2021
commit 1e96edbcf0363a99e7c3f21056cb57463f1daea3
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.opengl.GLSurfaceView;

import com.facebook.react.uimanager.ThemedReactContext;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.Publisher;

import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -39,8 +38,6 @@ public void createPublisherView(String publisherId) {
if (androidZOrderMap.get(mPublisher.getSession().getSessionId()) != null) {
zOrder = androidZOrderMap.get(mPublisher.getSession().getSessionId());
}
mPublisher.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE,
BaseVideoRenderer.STYLE_VIDEO_FILL);
FrameLayout mPublisherViewContainer = new FrameLayout(getContext());
if (pubOrSub.equals("publisher") && mPublisher.getView() instanceof GLSurfaceView) {
if (zOrder.equals("mediaOverlay")) {
Expand Down
32 changes: 30 additions & 2 deletions android/src/main/java/com/opentokreactnative/OTSessionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.ReadableArray;

import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.Session;
import com.opentok.android.Connection;
import com.opentok.android.Publisher;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void initSession(String apiKey, String sessionId, ReadableMap sessionOpti
final boolean isCamera2Capable = sessionOptions.getBoolean("isCamera2Capable");
final boolean connectionEventsSuppressed = sessionOptions.getBoolean("connectionEventsSuppressed");
final boolean ipWhitelist = sessionOptions.getBoolean("ipWhitelist");
// Note: IceConfig is an additional property not supported at the moment.
// Note: IceConfig is an additional property not supported at the moment.
// final ReadableMap iceConfig = sessionOptions.getMap("iceConfig");
// final List<Session.Builder.IceServer> iceConfigServerList = (List<Session.Builder.IceServer>) iceConfig.getArray("customServers");
// final Session.Builder.IncludeServers iceConfigServerConfig; // = iceConfig.getString("includeServers");
Expand All @@ -102,7 +103,7 @@ public boolean isCamera2Capable() {
}
})
.connectionEventsSuppressed(connectionEventsSuppressed)
// Note: setCustomIceServers is an additional property not supported at the moment.
// Note: setCustomIceServers is an additional property not supported at the moment.
// .setCustomIceServers(serverList, config)
.setIpWhitelist(ipWhitelist)
.setProxyUrl(proxyUrl)
Expand Down Expand Up @@ -145,6 +146,7 @@ public void initPublisher(String publisherId, ReadableMap properties, Callback c
String resolution = properties.getString("resolution");
Boolean publishAudio = properties.getBoolean("publishAudio");
Boolean publishVideo = properties.getBoolean("publishVideo");
String scaleBehavior = properties.getString("scaleBehavior");
String videoSource = properties.getString("videoSource");
Publisher mPublisher = null;
if (videoSource.equals("screen")) {
Expand Down Expand Up @@ -178,6 +180,8 @@ public void initPublisher(String publisherId, ReadableMap properties, Callback c
mPublisher.setAudioFallbackEnabled(audioFallbackEnabled);
mPublisher.setPublishVideo(publishVideo);
mPublisher.setPublishAudio(publishAudio);
mPublisher.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, scaleBehavior.equals("fill") ?
BaseVideoRenderer.STYLE_VIDEO_FILL : BaseVideoRenderer.STYLE_VIDEO_FIT);
ConcurrentHashMap<String, Publisher> mPublishers = sharedState.getPublishers();
mPublishers.put(publisherId, mPublisher);
callback.invoke();
Expand Down Expand Up @@ -220,6 +224,8 @@ public void subscribeToStream(String streamId, String sessionId, ReadableMap pro
mSubscriber.setStreamListener(this);
mSubscriber.setSubscribeToAudio(properties.getBoolean("subscribeToAudio"));
mSubscriber.setSubscribeToVideo(properties.getBoolean("subscribeToVideo"));
mSubscriber.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, properties.getString("scaleBehavior").equals("fill") ?
BaseVideoRenderer.STYLE_VIDEO_FILL : BaseVideoRenderer.STYLE_VIDEO_FIT);
if (properties.hasKey("preferredFrameRate")) {
mSubscriber.setPreferredFrameRate((float) properties.getDouble("preferredFrameRate"));
}
Expand Down Expand Up @@ -299,6 +305,28 @@ public void publishVideo(String publisherId, Boolean publishVideo) {
}
}

@ReactMethod
public void setPublisherScaleBehavior(String publisherId, String scaleBehavior) {

ConcurrentHashMap<String, Publisher> mPublishers = sharedState.getPublishers();
Publisher mPublisher = mPublishers.get(publisherId);
if (mPublisher != null) {
mPublisher.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, scaleBehavior.equals("fill") ?
BaseVideoRenderer.STYLE_VIDEO_FILL : BaseVideoRenderer.STYLE_VIDEO_FIT);
}
}

@ReactMethod
public void setSubscriberScaleBehavior(String streamId, String scaleBehavior) {

ConcurrentHashMap<String, Subscriber> mSubscribers = sharedState.getSubscribers();
Subscriber mSubscriber = mSubscribers.get(streamId);
if (mSubscriber != null) {
mSubscriber.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE, scaleBehavior.equals("fill") ?
BaseVideoRenderer.STYLE_VIDEO_FILL : BaseVideoRenderer.STYLE_VIDEO_FIT);
}
}

@ReactMethod
public void subscribeToAudio(String streamId, Boolean subscribeToAudio) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.widget.FrameLayout;

import com.facebook.react.uimanager.ThemedReactContext;
import com.opentok.android.BaseVideoRenderer;
import com.opentok.android.Subscriber;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -45,8 +44,6 @@ public void createSubscriberView(String streamId) {
if (mSubscriber.getView().getParent() != null) {
((ViewGroup)mSubscriber.getView().getParent()).removeView(mSubscriber.getView());
}
mSubscriber.setStyle(BaseVideoRenderer.STYLE_VIDEO_SCALE,
BaseVideoRenderer.STYLE_VIDEO_FILL);
if (pubOrSub.equals("subscriber") && mSubscriber.getView() instanceof GLSurfaceView) {
if (zOrder.equals("mediaOverlay")) {
((GLSurfaceView) mSubscriber.getView()).setZOrderMediaOverlay(true);
Expand Down