Skip to content

Commit

Permalink
Merge pull request #4 from blackuy/master
Browse files Browse the repository at this point in the history
2.2
  • Loading branch information
enriqueviard authored May 31, 2021
2 parents 893961b + fc13008 commit a490ee7
Show file tree
Hide file tree
Showing 13 changed files with 295 additions and 169 deletions.
2 changes: 1 addition & 1 deletion Example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath 'com.android.tools.build:gradle:4.0.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dependencies {

implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "com.android.support:appcompat-v7:$androidSupportVersion"
implementation "com.twilio:video-android:5.10.1"
implementation "com.twilio:video-android:6.2.1"
implementation 'org.webrtc:google-webrtc:1.0.30039'
implementation "com.facebook.react:react-native:+" // From node_modules
}
186 changes: 127 additions & 59 deletions android/src/main/java/com/twiliorn/library/CustomTwilioVideoView.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,19 @@ public void receiveCommand(CustomTwilioVideoView view, int commandId, @Nullable
boolean enableRemoteAudio = args.getBoolean(4);
boolean enableNetworkQualityReporting = args.getBoolean(5);
boolean dominantSpeakerEnabled = args.getBoolean(6);
view.connectToRoomWrapper(roomName, accessToken, enableAudio, enableVideo, enableRemoteAudio, enableNetworkQualityReporting, dominantSpeakerEnabled);
boolean maintainVideoTrackInBackground = args.getBoolean(7);
String cameraType = args.getString(8);
view.connectToRoomWrapper(
roomName,
accessToken,
enableAudio,
enableVideo,
enableRemoteAudio,
enableNetworkQualityReporting,
dominantSpeakerEnabled,
maintainVideoTrackInBackground,
cameraType
);
break;
case DISCONNECT:
view.disconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
import android.os.Looper;
import android.util.AttributeSet;

import com.twilio.video.I420Frame;
import com.twilio.video.VideoView;

import tvi.webrtc.VideoFrame;

/*
* VideoView that notifies Listener of the first frame rendered and the first frame after a reset
* request.
Expand All @@ -33,7 +34,7 @@ public PatchedVideoView(Context context, AttributeSet attrs) {
}

@Override
public void renderFrame(I420Frame frame) {
public void onFrame(VideoFrame frame) {
if (notifyFrameRendered) {
notifyFrameRendered = false;
mainThreadHandler.post(new Runnable() {
Expand All @@ -43,7 +44,7 @@ public void run() {
}
});
}
super.renderFrame(frame);
super.onFrame(frame);
}

/*
Expand Down
14 changes: 6 additions & 8 deletions android/src/main/java/com/twiliorn/library/RNVideoViewGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.events.RCTEventEmitter;
import com.twilio.video.VideoFrame;
import com.twilio.video.VideoRenderer;
import com.twilio.video.VideoScaleType;

import org.webrtc.RendererCommon;
import tvi.webrtc.RendererCommon;
import tvi.webrtc.VideoFrame;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -52,17 +51,16 @@ public RNVideoViewGroup(ThemedReactContext themedReactContext) {
surfaceViewRenderer.setVideoScaleType(VideoScaleType.ASPECT_FILL);
addView(surfaceViewRenderer);
surfaceViewRenderer.setListener(
new VideoRenderer.Listener() {
new RendererCommon.RendererEvents() {
@Override
public void onFirstFrame() {
public void onFirstFrameRendered() {

}

@Override
public void onFrameDimensionsChanged(int vw, int vh, int rotation) {
public void onFrameResolutionChanged(int vw, int vh, int rotation) {
synchronized (layoutSync) {
if (rotation == VideoFrame.RotationAngle.ROTATION_90.getValue() ||
rotation == VideoFrame.RotationAngle.ROTATION_270.getValue()) {
if (rotation == 90 || rotation == 270) {
videoHeight = vw;
videoWidth = vh;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.annotations.ReactProp;

import org.webrtc.RendererCommon;
import tvi.webrtc.RendererCommon;

import java.util.Map;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

import java.util.Map;

import org.webrtc.RendererCommon;
import tvi.webrtc.RendererCommon;

import static com.twiliorn.library.RNVideoViewGroup.Events.ON_FRAME_DIMENSIONS_CHANGED;

Expand Down
8 changes: 4 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Property | Type | Required | Default value | Description
onCameraSwitched | func | no | | Callback that is called when camera source changes
onVideoChanged | func | no | | Callback that is called when video is toggled.
onAudioChanged | func | no | | Callback that is called when a audio is toggled.
onRoomDidConnect | func | no | | Callback that is called when user is connected to a room.
onRoomDidConnect | func | no | | Called when the room has connected @param {{roomName, participants, localParticipant}}
onRoomDidFailToConnect | func | no | | Callback that is called when connecting to room fails.
onRoomDidDisconnect | func | no | | Callback that is called when user is disconnected from room.
onParticipantAddedDataTrack | func | no | | Called when a new data track has been added @param {{participant, track}}
onParticipantRemovedDataTrack | func | no | | Called when a data track has been removed @param {{participant, track}}
onDataTrackMessageReceived | func | no | | Called when an dataTrack receives a message @param {{message}}
onDataTrackMessageReceived | func | no | | Called when an dataTrack receives a message @param {{message, trackSid}}
onParticipantAddedVideoTrack | func | no | | Called when a new video track has been added @param {{participant, track, enabled}}
onParticipantRemovedVideoTrack | func | no | | Called when a video track has been removed @param {{participant, track}}
onParticipantAddedAudioTrack | func | no | | Called when a new audio track has been added @param {{participant, track}}
Expand All @@ -47,7 +47,7 @@ onDominantSpeakerDidChange | func | no | | Called when dominant speaker changes
Property | Type | Required | Default value | Description
:--- | :--- | :--- | :--- | :---
screenShare | bool | no | | Flag that enables screen sharing RCTRootView instead of camera capture
onRoomDidConnect | func | no | | Called when the room has connected @param {{roomName, participants}}
onRoomDidConnect | func | no | | Called when the room has connected @param {{roomName, participants, localParticipant}}
onRoomDidDisconnect | func | no | | Called when the room has disconnected @param {{roomName, error}}
onRoomDidFailToConnect | func | no | | Called when connection with room failed @param {{roomName, error}}
onRoomParticipantDidConnect | func | no | | Called when a new participant has connected @param {{roomName, participant}}
Expand All @@ -62,7 +62,7 @@ onParticipantEnabledVideoTrack | func | no | | Called when a video track has be
onParticipantDisabledVideoTrack | func | no | | Called when a video track has been disabled. @param {{participant, track}}
onParticipantEnabledAudioTrack | func | no | | Called when an audio track has been enabled. @param {{participant, track}}
onParticipantDisabledAudioTrack | func | no | | Called when an audio track has been disabled. @param {{participant, track}}
onDataTrackMessageReceived | func | no | | Called when an dataTrack receives a message @param {{message}}
onDataTrackMessageReceived | func | no | | Called when an dataTrack receives a message @param {{message, trackSid}}
onCameraDidStart | func | no | | Called when the camera has started
onCameraWasInterrupted | func | no | | Called when the camera has been interrupted
onCameraInterruptionEnded | func | no | | Called when the camera interruption has ended
Expand Down
17 changes: 15 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ declare module "react-native-twilio-video-webrtc" {
}

type scaleType = "fit" | "fill";
type cameraType = "front" | "back";

interface TwilioVideoParticipantViewProps extends ViewProps {
trackIdentifier: TrackIdentifier;
ref?: React.Ref<any>;
Expand Down Expand Up @@ -38,6 +40,13 @@ declare module "react-native-twilio-video-webrtc" {

export type TrackEventCb = (t: TrackEventCbArgs) => void;

export interface DataTrackEventCbArgs {
message: string;
trackSid: string;
}

export type DataTrackEventCb = (t: DataTrackEventCbArgs) => void;

interface RoomEventCommonArgs {
roomName: string;
roomSid: string;
Expand All @@ -49,6 +58,7 @@ declare module "react-native-twilio-video-webrtc" {

type RoomEventArgs = RoomEventCommonArgs & {
participants: Participant[];
localParticipant: Participant;
};

type ParticipantEventArgs = RoomEventCommonArgs & {
Expand Down Expand Up @@ -90,13 +100,14 @@ declare module "react-native-twilio-video-webrtc" {
onNetworkQualityLevelsChanged?: NetworkLevelChangeEventCb;

onStatsReceived?: (data: any) => void;
onDataTrackMessageReceived?: (data: { message: string }) => void;
onDataTrackMessageReceived?: DataTrackEventCb;
ref?: React.Ref<any>;
};

type iOSConnectParams = {
accessToken: string;
roomName?: string;
accessToken: string;
cameraType?: cameraType;
enableAudio?: boolean;
enableVideo?: boolean;
encodingParameters?: {
Expand All @@ -111,10 +122,12 @@ declare module "react-native-twilio-video-webrtc" {
type androidConnectParams = {
roomName?: string;
accessToken: string;
cameraType?: cameraType;
enableAudio?: boolean;
enableVideo?: boolean;
enableRemoteAudio?: boolean;
enableNetworkQualityReporting?: boolean;
maintainVideoTrackInBackground?: boolean;
};

class TwilioVideo extends React.Component<TwilioVideoProps> {
Expand Down
30 changes: 23 additions & 7 deletions ios/RCTTWVideoModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,17 @@ - (void)addParticipantView:(TVIVideoView *)view sid:(NSString *)sid trackSid:(NS
self.localVideoTrack = [TVILocalVideoTrack trackWithSource:self.camera enabled:NO name:@"camera"];
}

- (void)startCameraCapture {
- (void)startCameraCapture:(NSString *)cameraType {
if (self.camera == nil) {
return;
}
AVCaptureDevice *camera = [TVICameraSource captureDeviceForPosition:AVCaptureDevicePositionFront];
AVCaptureDevice *camera;
if ([cameraType isEqualToString:@"back"]) {
camera = [TVICameraSource captureDeviceForPosition:AVCaptureDevicePositionBack];
} else {
camera = [TVICameraSource captureDeviceForPosition:AVCaptureDevicePositionFront];
}

[self.camera startCaptureWithDevice:camera completion:^(AVCaptureDevice *device,
TVIVideoFormat *startFormat,
NSError *error) {
Expand Down Expand Up @@ -235,12 +241,18 @@ - (void)startCameraCapture {
resolve(@(enabled));
}


// set a default for setting local video enabled
- (bool)_setLocalVideoEnabled:(bool)enabled {
return [self _setLocalVideoEnabled:enabled cameraType:@"front"];
}

- (bool)_setLocalVideoEnabled:(bool)enabled cameraType:(NSString *)cameraType {
if (self.localVideoTrack != nil) {
[self.localVideoTrack setEnabled:enabled];
if (self.camera) {
if (enabled) {
[self startCameraCapture];
[self startCameraCapture:cameraType];
} else {
[self clearCameraInstance];
}
Expand Down Expand Up @@ -385,8 +397,11 @@ -(NSMutableDictionary*)convertLocalVideoTrackStats:(TVILocalVideoTrackStats *)st
}
}

RCT_EXPORT_METHOD(connect:(NSString *)accessToken roomName:(NSString *)roomName enableVideo:(BOOL *)enableVideo encodingParameters:(NSDictionary *)encodingParameters enableNetworkQualityReporting:(BOOL *)enableNetworkQualityReporting dominantSpeakerEnabled:(BOOL *)dominantSpeakerEnabled) {
[self _setLocalVideoEnabled:enableVideo];
RCT_EXPORT_METHOD(connect:(NSString *)accessToken roomName:(NSString *)roomName enableAudio:(BOOL *)enableAudio enableVideo:(BOOL *)enableVideo encodingParameters:(NSDictionary *)encodingParameters enableNetworkQualityReporting:(BOOL *)enableNetworkQualityReporting dominantSpeakerEnabled:(BOOL *)dominantSpeakerEnabled cameraType:(NSString *)cameraType) {
[self _setLocalVideoEnabled:enableVideo cameraType:cameraType];
if (self.localAudioTrack) {
[self.localAudioTrack setEnabled:enableAudio];
}

TVIConnectOptions *connectOptions = [TVIConnectOptions optionsWithToken:accessToken block:^(TVIConnectOptionsBuilder * _Nonnull builder) {
if (self.localVideoTrack) {
Expand Down Expand Up @@ -507,7 +522,7 @@ - (void)didConnectToRoom:(TVIRoom *)room {
self.localParticipant.delegate = self;

[participants addObject:[self.localParticipant toJSON]];
[self sendEventCheckingListenerWithName:roomDidConnect body:@{ @"roomName" : room.name , @"roomSid": room.sid, @"participants" : participants }];
[self sendEventCheckingListenerWithName:roomDidConnect body:@{ @"roomName" : room.name , @"roomSid": room.sid, @"participants" : participants, @"localParticipant" : [self.localParticipant toJSON] }];

}

Expand Down Expand Up @@ -597,7 +612,7 @@ - (void)remoteParticipant:(nonnull TVIRemoteParticipant *)participant networkQua
# pragma mark - TVIRemoteDataTrackDelegate

- (void)remoteDataTrack:(nonnull TVIRemoteDataTrack *)remoteDataTrack didReceiveString:(nonnull NSString *)message {
[self sendEventCheckingListenerWithName:dataTrackMessageReceived body:@{ @"message": message }];
[self sendEventCheckingListenerWithName:dataTrackMessageReceived body:@{ @"message": message, @"trackSid": remoteDataTrack.sid }];
}

- (void)remoteDataTrack:(nonnull TVIRemoteDataTrack *)remoteDataTrack didReceiveData:(nonnull NSData *)message {
Expand All @@ -612,3 +627,4 @@ - (void)localParticipant:(nonnull TVILocalParticipant *)participant networkQuali
}

@end

Loading

0 comments on commit a490ee7

Please sign in to comment.