Skip to content

Commit

Permalink
added support to set Eu Configuration in Android.
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhijeetRanjan308 committed Apr 19, 2024
1 parent 4f545fa commit 9552704
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.kommunicate.KMServerConfiguration;
import io.kommunicate.KmConversationBuilder;
import io.kommunicate.KmSettings;
import io.kommunicate.Kommunicate;
Expand Down Expand Up @@ -55,7 +56,7 @@ public class KmMethodHandler implements MethodCallHandler {
private static final String ERROR = "Error";
private Activity context;
private MethodChannel methodChannel;

private KMServerConfiguration serverConfig = KMServerConfiguration.DEFAULTCONFIGURATION;
public KmMethodHandler(Activity context) {
this.context = context;
}
Expand All @@ -64,6 +65,25 @@ public KmMethodHandler(Activity context) {
public void onMethodCall(MethodCall call, final Result result) {
if (call.method.equals("getPlatformVersion")) {
result.success("Android " + android.os.Build.VERSION.RELEASE);
} else if (call.method.equals("setServerConfiguration")){
try {
String serverConfigText = (String) call.arguments();
if (!TextUtils.isEmpty(serverConfigText)) {
switch (serverConfigText) {
case "euConfiguration":
this.serverConfig = KMServerConfiguration.EUCONFIGURATION;
Kommunicate.setServerConfiguration(context, KMServerConfiguration.DEFAULTCONFIGURATION);
break;
default:
result.error(ERROR, "It only supports `euConfiguration` for now.", null);
}
} else {
result.error(ERROR, "Invalid Server Config", null);
return;
}
} catch (Exception e) {
result.error(ERROR, e.toString(), null);
}
} else if (call.method.equals("isLoggedIn")) {
result.success(Kommunicate.isLoggedIn(context));
} else if (call.method.equals("login")) {
Expand All @@ -72,6 +92,9 @@ public void onMethodCall(MethodCall call, final Result result) {
KMUser user = (KMUser) GsonUtils.getObjectFromJson(userObject.toString(), KMUser.class);

if (userObject.has("appId") && !TextUtils.isEmpty(userObject.get("appId").toString())) {
if (serverConfig == KMServerConfiguration.EUCONFIGURATION) {
Kommunicate.setServerConfiguration(context, serverConfig);
}
Kommunicate.init(context, userObject.get("appId").toString());
} else {
result.error(ERROR, "appId is missing", null);
Expand Down Expand Up @@ -157,6 +180,9 @@ public void onFailure(RegistrationResponse registrationResponse, Exception excep
try {
String appId = (String) call.arguments();
if (!TextUtils.isEmpty(appId)) {
if (serverConfig == KMServerConfiguration.EUCONFIGURATION) {
Kommunicate.setServerConfiguration(context, serverConfig);
}
Kommunicate.init(context, appId);
} else {
result.error(ERROR, "appId is missing", null);
Expand Down
1 change: 1 addition & 0 deletions ios/Classes/SwiftKommunicateFlutterPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public class SwiftKommunicateFlutterPlugin: NSObject, FlutterPlugin, KMPreChatFo
switch serverConfig {
case "euConfiguration":
self.serverConfig = .euConfiguration
Kommunicate.setServerConfiguration(.euConfiguration)
default:
self.sendErrorResultWithCallback(result: result, message: "It only supports `euConfiguration` for now.")
}
Expand Down

0 comments on commit 9552704

Please sign in to comment.