Skip to content

Commit

Permalink
connection node
Browse files Browse the repository at this point in the history
  • Loading branch information
YuliaGrigorieva committed May 20, 2024
1 parent 28093d0 commit fe6cf02
Show file tree
Hide file tree
Showing 10 changed files with 113 additions and 12 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ android {
}

dependencies {
api 'com.voximplant:voximplant-sdk:2.38.2'
api 'com.voximplant:voximplant-sdk:2.39.0'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.voximplant.sdk.client.IClientLoginListener;
import com.voximplant.sdk.client.IClientSessionListener;
import com.voximplant.sdk.client.LoginError;
import com.voximplant.sdk.client.Node;
import com.voximplant.sdk.client.RequestAudioFocusMode;

import java.util.HashMap;
Expand Down Expand Up @@ -189,6 +190,11 @@ private void connect(MethodCall call, MethodChannel.Result result) {
return;
}
if (call.arguments != null) {
Node node = null;
if (call.hasArgument("node")) {
String value = call.argument("node");
node = Utils.convertStringToNode(value);
}
boolean connectivityCheck = false;
if (call.hasArgument("connectivityCheck")) {
Boolean value = call.argument("connectivityCheck");
Expand All @@ -200,7 +206,11 @@ private void connect(MethodCall call, MethodChannel.Result result) {
servers = call.argument("servers");
}
try {
mClient.connect(connectivityCheck, servers);
if (node == null) {
mClient.connect(connectivityCheck, servers);
} else {
mClient.connect(node, connectivityCheck, servers);
}
} catch (IllegalStateException e) {
result.error(ERROR_CONNECTION_FAILED, "Invalid state", null);
return;
Expand Down
32 changes: 32 additions & 0 deletions android/src/main/java/com/voximplant/flutter_voximplant/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.voximplant.sdk.call.VideoStreamReceiveStopReason;
import com.voximplant.sdk.call.VideoStreamType;
import com.voximplant.sdk.client.LoginError;
import com.voximplant.sdk.client.Node;
import com.voximplant.sdk.hardware.AudioFileUsage;
import com.voximplant.sdk.messaging.IErrorEvent;

Expand Down Expand Up @@ -313,6 +314,37 @@ static int convertQualityIssueToInt(QualityIssue issue) {
}
}

static Node convertStringToNode(String node) {
if (node == null) {
return null;
}
switch (node) {
case "Node1":
return Node.NODE_1;
case "Node2":
return Node.NODE_2;
case "Node3":
return Node.NODE_3;
case "Node4":
return Node.NODE_4;
case "Node5":
return Node.NODE_5;
case "Node6":
return Node.NODE_6;
case "Node7":
return Node.NODE_7;
case "Node8":
return Node.NODE_8;
case "Node9":
return Node.NODE_9;
case "Node10":
return Node.NODE_10;
default:
return null;

}
}

static Map<Integer, Integer> convertQualityIssuesMapToHashMap(Map<QualityIssue, QualityIssueLevel> issues) {
Map<Integer, Integer> parsedIssues = new HashMap<>();
for(Map.Entry<QualityIssue, QualityIssueLevel> pair : issues.entrySet()) {
Expand Down
9 changes: 8 additions & 1 deletion ios/Classes/VIClientModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,16 @@ - (void)initClient:(NSDictionary *)arguments {
- (void)connectWithArguments:(NSDictionary *)arguments result:(FlutterResult)result {
BOOL connectResult = false;
if (arguments) {
NSString *node = [arguments objectForKey:@"node"] != [NSNull null] ? [arguments objectForKey:@"node"] : nil;
NSNumber *connectivityCheck = [arguments objectForKey:@"connectivityCheck"];
NSArray *servers = [arguments objectForKey:@"servers"] != [NSNull null] ? [arguments objectForKey:@"servers"] : nil;
connectResult = [self.client connectWithConnectivityCheck:[connectivityCheck boolValue] gateways:servers];

if (node) {
VIConnectionNode connectionNode = [VoximplantUtils convertStringToNode:node];
connectResult = [self.client connectTo:connectionNode connectivityCheck:[connectivityCheck boolValue] gateways:servers];
} else {
connectResult = [self.client connectWithConnectivityCheck:[connectivityCheck boolValue] gateways:servers];
}
} else {
connectResult = [self.client connect];
}
Expand Down
1 change: 1 addition & 0 deletions ios/Classes/VoximplantUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
+ (VIVideoCodec)convertCodecFromString:(NSString *)codec;
+ (NSNumber *)convertQualityIssueLevelToInt:(VIQualityIssueLevel)level;
+ (NSNumber *)convertQualityIssueTypeToInt:(VIQualityIssueType)type;
+ (VIConnectionNode)convertStringToNode:(NSString *)node;
@end


Expand Down
26 changes: 26 additions & 0 deletions ios/Classes/VoximplantUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,32 @@ + (NSNumber *)convertQualityIssueTypeToInt:(VIQualityIssueType)type {
}
}

+ (VIConnectionNode)convertStringToNode:(NSString *)node {
if ([node isEqualToString:@"Node1"]) {
return VIConnectionNodeNode1;
} else if ([node isEqualToString:@"Node2"]) {
return VIConnectionNodeNode2;
} else if ([node isEqualToString:@"Node3"]) {
return VIConnectionNodeNode3;
} else if ([node isEqualToString:@"Node4"]) {
return VIConnectionNodeNode4;
} else if ([node isEqualToString:@"Node5"]) {
return VIConnectionNodeNode5;
} else if ([node isEqualToString:@"Node6"]) {
return VIConnectionNodeNode6;
} else if ([node isEqualToString:@"Node7"]) {
return VIConnectionNodeNode7;
} else if ([node isEqualToString:@"Node8"]) {
return VIConnectionNodeNode8;
} else if ([node isEqualToString:@"Node9"]) {
return VIConnectionNodeNode9;
} else if ([node isEqualToString:@"Node10"]) {
return VIConnectionNodeNode10;
} else {
return VIConnectionNodeNode1;
}
}

@end


Expand Down
4 changes: 2 additions & 2 deletions ios/flutter_voximplant.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ Voximplant plugin for embedding voice and video communication into Flutter appli
s.source_files = 'Classes/**/*'
s.public_header_files = 'Classes/**/*.h'
s.dependency 'Flutter'
s.dependency 'VoxImplantSDK', '2.51.0'
s.ios.deployment_target = '11.0'
s.dependency 'VoxImplantSDK', '2.52.0'
s.ios.deployment_target = '12.0'
end
22 changes: 17 additions & 5 deletions lib/src/client/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class VIClient {

/// Returns the current client state
Future<VIClientState> getClientState() async {
String? result = await (_channel.invokeMethod<String>('Client.getClientState'));
String? result =
await (_channel.invokeMethod<String>('Client.getClientState'));
if (result == null) {
_VILog._e(
'VIClient: getClientState: result was null, returning disconnected');
Expand Down Expand Up @@ -116,6 +117,8 @@ class VIClient {
/// the Voximplant Cloud if [connectivityCheck] is enabled (disabled by
/// default).
///
/// Optional `node` - Specifies the node the Voximplant account belongs to.
///
/// Optional `connectivityCheck` - Checks whether UDP traffic will flow correctly
/// between device and Voximplant cloud. This check reduces connection speed.
///
Expand All @@ -128,15 +131,24 @@ class VIClient {
/// * [VIClientError.ERROR_CONNECTION_FAILED] - If the connection is currently
/// establishing or already established, or an error occurred.
Future<void> connect({
VINode? node = null,
bool connectivityCheck = false,
List<String>? servers,
}) async {
_changeClientState(VIClientState.Connecting);
try {
await _channel.invokeMethod<void>('Client.connect', <String, dynamic>{
'connectivityCheck': connectivityCheck,
'servers': servers,
});
if (node != null) {
await _channel.invokeMethod<void>('Client.connect', <String, dynamic>{
'connectivityCheck': connectivityCheck,
'servers': servers,
'node': node.name,
});
} else {
await _channel.invokeMethod<void>('Client.connect', <String, dynamic>{
'connectivityCheck': connectivityCheck,
'servers': servers,
});
}
VIClientState state = await getClientState();
_changeClientState(state);
} on PlatformException catch (e) {
Expand Down
15 changes: 14 additions & 1 deletion lib/src/client/client_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ enum VIClientState {

/// The client is currently connecting.
Connecting,

/// The client is currently reconnecting.
Reconnecting,

Expand All @@ -126,5 +126,18 @@ enum VIClientState {

/// The client is currently logged in.
LoggedIn,
}

/// Describes the nodes the Voximplant account may belong to.
enum VINode {
Node1,
Node2,
Node3,
Node4,
Node5,
Node6,
Node7,
Node8,
Node9,
Node10,
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ homepage: https://voximplant.com
repository: https://github.com/voximplant/flutter_voximplant

environment:
sdk: '>=2.12.0 <4.0.0'
sdk: '>=2.15.0 <4.0.0'
flutter: ">=1.20.0"

dependencies:
Expand Down

0 comments on commit fe6cf02

Please sign in to comment.