From 3abab97d1b0684f97585ceec35ea19085c4fa8e6 Mon Sep 17 00:00:00 2001 From: Nagy Szilard Date: Fri, 13 May 2022 17:28:37 +0300 Subject: [PATCH] add sinch service --- android/app/src/main/AndroidManifest.xml | 131 ++++++++++++------ .../sinch/SinchService.java | 110 +++++++++++++++ 2 files changed, 198 insertions(+), 43 deletions(-) create mode 100644 android/app/src/main/java/com/kadeno/reactnativecallpoc/sinch/SinchService.java diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index afdf656..2b08628 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,9 +1,12 @@ - - - - - - + + + + + + + + @@ -11,41 +14,83 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/java/com/kadeno/reactnativecallpoc/sinch/SinchService.java b/android/app/src/main/java/com/kadeno/reactnativecallpoc/sinch/SinchService.java new file mode 100644 index 0000000..0257f69 --- /dev/null +++ b/android/app/src/main/java/com/kadeno/reactnativecallpoc/sinch/SinchService.java @@ -0,0 +1,110 @@ +package com.kadeno.reactnativecallpoc.sinch; + +import android.app.Service; +import android.content.Intent; +import android.os.IBinder; + +import com.sinch.android.rtc.ClientRegistration; +import com.sinch.android.rtc.Sinch; +import com.sinch.android.rtc.SinchClient; +import com.sinch.android.rtc.SinchClientListener; +import com.sinch.android.rtc.SinchError; +import com.sinch.android.rtc.calling.Call; +import com.sinch.android.rtc.calling.CallClient; +import com.sinch.android.rtc.calling.CallClientListener; +import com.sinch.android.rtc.internal.client.DefaultSinchClient; + +public class SinchService extends Service implements SinchClientListener, CallClientListener { + + private static final String APP_KEY = ""; + private static final String ENVIRONMENT = "application-secret"; + private static final String APP_SECRET = "ocra.api.sinch.com"; + + + private SinchClient sinchClient = null; + private String userId = ""; + + public SinchService() { + if (this.sinchClient == null) { + createClient("username"); + } + sinchClient.start(); + } + + private void createClient(String userName) { + this.userId = userName; + sinchClient = Sinch.getSinchClientBuilder() + .context(this) + .applicationKey(APP_KEY) + .environmentHost(ENVIRONMENT) + .userId(userName) + .build(); + + + ((DefaultSinchClient)sinchClient).setSupportActiveConnection(true); + sinchClient.startListeningOnActiveConnection(); + + SinchService sinchService = new SinchService(); + sinchClient.addSinchClientListener(sinchService); + sinchClient.getCallClient().addCallClientListener(sinchService); + + } + + + + + @Override + public IBinder onBind(Intent intent) { + // TODO: Return the communication channel to the service. + throw new UnsupportedOperationException("Not yet implemented"); + } + + @Override + public void onClientStarted(SinchClient sinchClient) { + + } + + @Override + public void onClientFailed(SinchClient sinchClient, SinchError sinchError) { + + } + + @Override + public void onLogMessage(int i, String s, String s1) { + + } + + @Override + public void onPushTokenRegistered() { + + } + + @Override + public void onPushTokenRegistrationFailed(SinchError sinchError) { + + } + + @Override + public void onCredentialsRequired(ClientRegistration clientRegistration) { + if(clientRegistration != null) { + clientRegistration.register("JWT.create(APP_KEY, APP_SECRET, userId)"); + + } + } + + @Override + public void onUserRegistered() { + + } + + @Override + public void onUserRegistrationFailed(SinchError sinchError) { + + } + + @Override + public void onIncomingCall(CallClient callClient, Call call) { + + } + +} \ No newline at end of file