Skip to content

Commit

Permalink
Merge pull request #147 from voximplant/change_logic_manage_streams
Browse files Browse the repository at this point in the history
Change start/stop receiving methods on native side iOS/Android
  • Loading branch information
pe1ros authored Mar 14, 2022
2 parents 3bea13c + 42f4704 commit 1c98b98
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 45 deletions.
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

### 1.29.0
- Update native Android and iOS modules to use Voximplant Android SDK 2.31.0 and Voximplant iOS SDK 2.46.3
- Introduce new API to get a call duration - [Call.getDuration]
- Introduce simulcast feature support for video conference. Simulcast is currently disabled by default, but can be enabled via [CallSettings.enableSimulcast] parameter.
- Introduce new API to get a call duration - [Call.getDuration](https://voximplant.com/docs/references/reactnative/voximplant/call#getduration)
- Introduce simulcast feature support for video conference. Simulcast is currently disabled by default, but can be enabled via [CallSettings.enableSimulcast](https://voximplant.com/docs/references/reactnative/voximplant/callsettings#enablesimulcast) parameter.
- Introduce new APIs to control remote video streams in a video conference call:
- [Endpoint.startReceiving](link) - Starts receiving video on the video stream.
- [Endpoint.stopReceiving](link) - Stops receiving video on the video stream.
- [Endpoint.requestVideoSize](link) - Requests the specified video size for the video stream.
    The stream resolution may be changed to the closest to the specified width and height.
- Introduced [Endpoint.VoiceActivityStarted](link) and [Endpoint.VoiceActivityStopped](link) API to handle voice activity of an endpoint in a conference call.
- [Endpoint.startReceiving](https://voximplant.com/docs/references/reactnative/voximplant/endpoint#startreceiving) - Starts receiving video on the video stream.
- [Endpoint.stopReceiving](https://voximplant.com/docs/references/reactnative/voximplant/endpoint#stopreceiving) - Stops receiving video on the video stream.
- [Endpoint.requestVideoSize](https://voximplant.com/docs/references/reactnative/voximplant/endpoint#requestvideosize) - Requests the specified video size for the video stream.
The stream resolution may be changed to the closest to the specified width and height.
- Introduced [Endpoint.VoiceActivityStarted](https://voximplant.com/docs/references/reactnative/voximplant/endpointeventtypes#voiceactivitystarted) and [Endpoint.VoiceActivityStopped](https://voximplant.com/docs/references/reactnative/voximplant/endpointeventtypes#voiceactivitystopped) API to handle voice activity of an endpoint in a conference call.


### 1.28.0
- Update native Android and iOS modules to use Voximplant Android SDK 2.29.1 and Voximplant iOS SDK 2.46.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ class Constants {
static final String EVENT_ENDPOINT_VOICE_ACTIVITY_STARTED = "VIVoiceActivityStarted";
static final String EVENT_ENDPOINT_VOICE_ACTIVITY_STOPPED = "VIVoiceActivityStopped";

static final String EVENT_ENDPOINT_STOP_RECEIVING_VIDEO_STREAM_SUCCESS = "VIStopReceivingVideoStreamSuccess";
static final String EVENT_ENDPOINT_STOP_RECEIVING_VIDEO_STREAM_FAILURE = "VIStopReceivingVideoStreamFailure";
static final String EVENT_ENDPOINT_START_RECEIVING_VIDEO_STREAM_SUCCESS = "VIStartReceivingVideoStreamSuccess";
static final String EVENT_ENDPOINT_START_RECEIVING_VIDEO_STREAM_FAILURE = "VIStartReceivingVideoStreamFailure";
static final String EVENT_ENDPOINT_REQUEST_VIDEO_SIZE_FOR_VIDEO_STREAM_SUCCESS = "VIRequestVideoSizeForVideoStreamSuccess";
static final String EVENT_ENDPOINT_REQUEST_VIDEO_SIZE_FOR_VIDEO_STREAM_FAILURE = "VIRequestVideoSizeForVideoStreamFailure";

static final String EVENT_AUDIO_DEVICE_CHANGED = "VIAudioDeviceChanged";
static final String EVENT_AUDIO_DEVICE_LIST_CHANGED = "VIAudioDeviceListChanged";

Expand Down
39 changes: 29 additions & 10 deletions android/src/main/java/com/voximplant/reactnative/VICallModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,58 +197,77 @@ public void hangup(String callId, ReadableMap headers) {
}

@ReactMethod
public void startReceiving(String streamId, final Promise promise) {
public void startReceiving(String streamId) {
IRemoteVideoStream remoteVideoStream = CallManager.getInstance().getRemoteVideoStreamById(streamId);
if (remoteVideoStream != null) {
remoteVideoStream.startReceiving(new ICallCompletionHandler() {
@Override
public void onComplete() {
promise.resolve(null);
WritableMap params = Arguments.createMap();
params.putString(EVENT_PARAM_NAME, EVENT_ENDPOINT_START_RECEIVING_VIDEO_STREAM_SUCCESS);
sendEvent(EVENT_ENDPOINT_START_RECEIVING_VIDEO_STREAM_SUCCESS, params);
}

@Override
public void onFailure(CallException exception) {
promise.reject(exception.getErrorCode().toString(), exception.getMessage());
WritableMap params = Arguments.createMap();
params.putString(EVENT_PARAM_NAME, EVENT_ENDPOINT_START_RECEIVING_VIDEO_STREAM_FAILURE);
params.putString(EVENT_PARAM_CODE, exception.getErrorCode().toString());
params.putString(EVENT_PARAM_REASON, exception.getMessage());
sendEvent(EVENT_ENDPOINT_START_RECEIVING_VIDEO_STREAM_FAILURE, params);
}
});
}
}

@ReactMethod
public void stopReceiving(String streamId, final Promise promise) {
public void stopReceiving(String streamId) {
IRemoteVideoStream remoteVideoStream = CallManager.getInstance().getRemoteVideoStreamById(streamId);
if (remoteVideoStream != null) {
remoteVideoStream.stopReceiving(new ICallCompletionHandler() {
@Override
public void onComplete() {
promise.resolve(null);
WritableMap params = Arguments.createMap();
params.putString(EVENT_PARAM_NAME, EVENT_ENDPOINT_STOP_RECEIVING_VIDEO_STREAM_SUCCESS);
sendEvent(EVENT_ENDPOINT_STOP_RECEIVING_VIDEO_STREAM_SUCCESS, params);
}

@Override
public void onFailure(CallException exception) {
promise.reject(exception.getErrorCode().toString(), exception.getMessage());
WritableMap params = Arguments.createMap();
params.putString(EVENT_PARAM_NAME, EVENT_ENDPOINT_STOP_RECEIVING_VIDEO_STREAM_FAILURE);
params.putString(EVENT_PARAM_CODE, exception.getErrorCode().toString());
params.putString(EVENT_PARAM_REASON, exception.getMessage());
sendEvent(EVENT_ENDPOINT_STOP_RECEIVING_VIDEO_STREAM_FAILURE, params);
}
});
}
}

@ReactMethod
public void requestVideoSize(String streamId, int width, int height, final Promise promise) {
public void requestVideoSize(String streamId, int width, int height) {
IRemoteVideoStream remoteVideoStream = CallManager.getInstance().getRemoteVideoStreamById(streamId);
if (remoteVideoStream != null) {
remoteVideoStream.requestVideoSize(width, height);
promise.resolve(null);
WritableMap params = Arguments.createMap();
params.putString(EVENT_PARAM_NAME, EVENT_ENDPOINT_REQUEST_VIDEO_SIZE_FOR_VIDEO_STREAM_SUCCESS);
sendEvent(EVENT_ENDPOINT_REQUEST_VIDEO_SIZE_FOR_VIDEO_STREAM_SUCCESS, params);
} else {
promise.reject(CallError.INTERNAL_ERROR.toString(), "Failed to find remote video stream by provided video stream id");
WritableMap params = Arguments.createMap();
params.putString(EVENT_PARAM_NAME, EVENT_ENDPOINT_REQUEST_VIDEO_SIZE_FOR_VIDEO_STREAM_FAILURE);
params.putString(EVENT_PARAM_CODE, CallError.INTERNAL_ERROR.toString());
params.putString(EVENT_PARAM_REASON, "Failed to find remote video stream by provided video stream id");
sendEvent(EVENT_ENDPOINT_REQUEST_VIDEO_SIZE_FOR_VIDEO_STREAM_FAILURE, params);
}
}

@ReactMethod
public void getCallDuration(String callId, final Promise promise) {
ICall call = CallManager.getInstance().getCallById(callId);
if (call != null) {
long duration = call.getCallDuration();
DecimalFormat df = new DecimalFormat("0");
promise.resolve(df.format(duration / 1000));
promise.resolve(Integer.parseInt(df.format(duration / 1000)));
} else {
promise.reject(CallError.INTERNAL_ERROR.toString(), "Call.getDuration(): call is no more unavailable, already ended or failed");
}
Expand Down
52 changes: 34 additions & 18 deletions ios/RNVICallModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ @implementation RNVICallModule
kEventEndpointVoiceActivityStarted,
kEventEndpointVoiceActivityStopped,
kEventCallReconnecting,
kEventCallReconnected];
kEventCallReconnected,
kEventEndpointStopReceivingVideoStreamSuccess,
kEventEndpointStopReceivingVideoStreamFailure,
kEventEndpointStartReceivingVideoStreamSuccess,
kEventEndpointStartReceivingVideoStreamFailure,
kEventEndpointRequestVideoSizeForVideoStreamSuccess,
kEventEndpointRequestVideoSizeForVideoStreamFailure];
}

RCT_EXPORT_METHOD(internalSetup:(NSString *)callId) {
Expand Down Expand Up @@ -152,49 +158,59 @@ @implementation RNVICallModule
}
}

RCT_EXPORT_METHOD(startReceiving:(NSString *)streamId
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
RCT_EXPORT_METHOD(startReceiving:(NSString *)streamId) {
VIRemoteVideoStream *remoteVideoStream = [RNVICallManager getRemoteVideoStreamById:streamId];
if (remoteVideoStream) {
[remoteVideoStream startReceivingWithCompletion:^(NSError * _Nullable error) {
if (error) {
reject([RNVIUtils convertIntToCallError:error.code], [error.userInfo objectForKey:@"reason"], error);
[self sendEventWithName:kEventEndpointStartReceivingVideoStreamFailure body:@{
kEventParamName : kEventEndpointStartReceivingVideoStreamFailure,
kEventParamCode : [RNVIUtils convertIntToCallError:error.code],
kEventParamReason : [NSArray arrayWithObject:[error.userInfo objectForKey:@"reason"]]
}];
} else {
resolve([NSNull null]);
[self sendEventWithName:kEventEndpointStartReceivingVideoStreamSuccess body:@{
kEventParamName : kEventEndpointStartReceivingVideoStreamSuccess,
}];
}
}];
}
}

RCT_EXPORT_METHOD(stopReceiving:(NSString *)streamId
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
RCT_EXPORT_METHOD(stopReceiving:(NSString *)streamId) {
VIRemoteVideoStream *remoteVideoStream = [RNVICallManager getRemoteVideoStreamById:streamId];
if (remoteVideoStream) {
[remoteVideoStream stopReceivingWithCompletion:^(NSError * _Nullable error) {
if (error) {
reject([RNVIUtils convertIntToCallError:error.code], [error.userInfo objectForKey:@"reason"], error);
[self sendEventWithName:kEventEndpointStopReceivingVideoStreamFailure body:@{
kEventParamName : kEventEndpointStopReceivingVideoStreamFailure,
kEventParamCode : [RNVIUtils convertIntToCallError:error.code],
kEventParamReason : [NSArray arrayWithObject:[error.userInfo objectForKey:@"reason"]]
}];
} else {
resolve([NSNull null]);
[self sendEventWithName:kEventEndpointStopReceivingVideoStreamSuccess body:@{
kEventParamName : kEventEndpointStopReceivingVideoStreamSuccess,
}];
}
}];
}
}

RCT_EXPORT_METHOD(requestVideoSize:(NSString *)streamId
withWidth:(NSNumber * _Nonnull)width
withHeight:(NSNumber * _Nonnull)height
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject) {
RCT_EXPORT_METHOD(requestVideoSize:(NSString *)streamId width:(NSNumber * _Nonnull)width height:(NSNumber * _Nonnull)height) {
VIRemoteVideoStream *remoteVideoStream = [RNVICallManager getRemoteVideoStreamById:streamId];
if (remoteVideoStream) {
NSUInteger integerWidth = [width unsignedIntegerValue];
NSUInteger integerHeight = [height unsignedIntegerValue];
[remoteVideoStream requestVideoSizeWithWidth:integerWidth height:integerHeight];
resolve([NSNull null]);
[self sendEventWithName:kEventEndpointRequestVideoSizeForVideoStreamSuccess body:@{
kEventParamName : kEventEndpointRequestVideoSizeForVideoStreamSuccess,
}];
} else {
reject(kCallErrorInternal, @"Failed to find remote video stream by provided video stream id", nil);
[self sendEventWithName:kEventEndpointRequestVideoSizeForVideoStreamFailure body:@{
kEventParamName : kEventEndpointRequestVideoSizeForVideoStreamFailure,
kEventParamCode : kCallErrorInternal,
kEventParamReason : @"Failed to find remote video stream by provided video stream id"
}];
}
}

Expand Down
7 changes: 7 additions & 0 deletions ios/RNVIConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ FOUNDATION_EXPORT NSString *const kEventNameEndpointRemoved;
FOUNDATION_EXPORT NSString *const kEventNameVoiceActivityStarted;
FOUNDATION_EXPORT NSString *const kEventNameVoiceActivityStopped;

FOUNDATION_EXPORT NSString *const kEventEndpointStopReceivingVideoStreamSuccess;
FOUNDATION_EXPORT NSString *const kEventEndpointStopReceivingVideoStreamFailure;
FOUNDATION_EXPORT NSString *const kEventEndpointStartReceivingVideoStreamSuccess;
FOUNDATION_EXPORT NSString *const kEventEndpointStartReceivingVideoStreamFailure;
FOUNDATION_EXPORT NSString *const kEventEndpointRequestVideoSizeForVideoStreamSuccess;
FOUNDATION_EXPORT NSString *const kEventEndpointRequestVideoSizeForVideoStreamFailure;

FOUNDATION_EXPORT NSString *const kEventNameAudioDeviceChanged;
FOUNDATION_EXPORT NSString *const kEventNameAudioDeviceListChanged;

Expand Down
7 changes: 7 additions & 0 deletions ios/RNVIConstants.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
NSString *const kEventEndpointVoiceActivityStarted = @"VIVoiceActivityStarted";
NSString *const kEventEndpointVoiceActivityStopped = @"VIVoiceActivityStopped";

NSString *const kEventEndpointStopReceivingVideoStreamSuccess = @"VIStopReceivingVideoStreamSuccess";
NSString *const kEventEndpointStopReceivingVideoStreamFailure = @"VIStopReceivingVideoStreamFailure";
NSString *const kEventEndpointStartReceivingVideoStreamSuccess = @"VIStartReceivingVideoStreamSuccess";
NSString *const kEventEndpointStartReceivingVideoStreamFailure = @"VIStartReceivingVideoStreamFailure";
NSString *const kEventEndpointRequestVideoSizeForVideoStreamSuccess = @"VIRequestVideoSizeForVideoStreamSuccess";
NSString *const kEventEndpointRequestVideoSizeForVideoStreamFailure = @"VIRequestVideoSizeForVideoStreamFailure";

NSString *const kEventAudioDeviceChanged = @"VIAudioDeviceChanged";
NSString *const kEventAudioDeviceListChanged = @"VIAudioDeviceListChanged";

Expand Down
Loading

0 comments on commit 1c98b98

Please sign in to comment.