-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
6,950 additions
and
6,446 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
android/app/src/main/java/com/kadeno/reactnativecallpoc/BaseActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
package com.kadeno.reactnativecallpoc; | ||
|
||
import android.app.Activity; | ||
import android.content.ComponentName; | ||
import android.content.Intent; | ||
import android.content.ServiceConnection; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.IBinder; | ||
import android.os.Message; | ||
import android.os.Messenger; | ||
import android.view.Window; | ||
import android.view.WindowManager; | ||
import android.widget.Toast; | ||
|
||
import androidx.core.app.ActivityCompat; | ||
|
||
import com.kadeno.reactnativecallpoc.sinch.SinchService; | ||
|
||
public abstract class BaseActivity extends Activity implements ServiceConnection { | ||
|
||
private SinchService.SinchServiceInterface mSinchServiceInterface; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
bindService(); | ||
requestWindowFeature(Window.FEATURE_NO_TITLE); | ||
getWindow().addFlags( | ||
WindowManager.LayoutParams.FLAG_FULLSCREEN | ||
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | ||
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | ||
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | ||
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); | ||
} | ||
|
||
@Override | ||
public void onServiceConnected(ComponentName componentName, IBinder iBinder) { | ||
if (SinchService.class.getName().equals(componentName.getClassName())) { | ||
mSinchServiceInterface = (SinchService.SinchServiceInterface) iBinder; | ||
onServiceConnected(); | ||
} | ||
} | ||
|
||
@Override | ||
public void onServiceDisconnected(ComponentName componentName) { | ||
if (SinchService.class.getName().equals(componentName.getClassName())) { | ||
mSinchServiceInterface = null; | ||
onServiceDisconnected(); | ||
} | ||
} | ||
|
||
protected void onServiceConnected() { | ||
// for subclasses | ||
} | ||
|
||
protected void onServiceDisconnected() { | ||
// for subclasses | ||
} | ||
|
||
protected SinchService.SinchServiceInterface getSinchServiceInterface() { | ||
return mSinchServiceInterface; | ||
} | ||
|
||
private Messenger messenger = new Messenger(new Handler() { | ||
@Override | ||
public void handleMessage(Message msg) { | ||
switch (msg.what) { | ||
case SinchService.MESSAGE_PERMISSIONS_NEEDED: | ||
Bundle bundle = msg.getData(); | ||
String requiredPermission = bundle.getString(SinchService.REQUIRED_PERMISSION); | ||
ActivityCompat.requestPermissions(BaseActivity.this, new String[]{requiredPermission}, 0); | ||
break; | ||
} | ||
} | ||
}); | ||
|
||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { | ||
boolean granted = grantResults.length > 0; | ||
for (int grantResult : grantResults) { | ||
granted &= grantResult == PackageManager.PERMISSION_GRANTED; | ||
} | ||
if (granted) { | ||
Toast.makeText(this, "You may now place a call", Toast.LENGTH_LONG).show(); | ||
} else { | ||
Toast.makeText(this, "This application needs permission to use your microphone and camera to function properly.", Toast.LENGTH_LONG).show(); | ||
} | ||
mSinchServiceInterface.retryStartAfterPermissionGranted(); | ||
} | ||
|
||
private void bindService() { | ||
Intent serviceIntent = new Intent(this, SinchService.class); | ||
serviceIntent.putExtra(SinchService.MESSENGER, messenger); | ||
getApplicationContext().bindService(serviceIntent, this, BIND_AUTO_CREATE); | ||
} | ||
|
||
} |
105 changes: 105 additions & 0 deletions
105
android/app/src/main/java/com/kadeno/reactnativecallpoc/CallManager/CallManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.kadeno.reactnativecallpoc.CallManager; | ||
|
||
import android.content.ComponentName; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.ServiceConnection; | ||
import android.content.pm.PackageManager; | ||
import android.os.Bundle; | ||
import android.os.Handler; | ||
import android.os.IBinder; | ||
import android.os.Message; | ||
import android.os.Messenger; | ||
import android.util.Log; | ||
import android.widget.Toast; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.core.app.ActivityCompat; | ||
|
||
import com.facebook.react.bridge.LifecycleEventListener; | ||
import com.facebook.react.bridge.Promise; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.kadeno.reactnativecallpoc.MainActivity; | ||
import com.kadeno.reactnativecallpoc.sinch.SinchService; | ||
import com.sinch.android.rtc.MissingPermissionException; | ||
import com.sinch.android.rtc.SinchClient; | ||
import com.sinch.android.rtc.calling.Call; | ||
|
||
public class CallManager extends ReactContextBaseJavaModule implements LifecycleEventListener { | ||
|
||
private static final String TAG = "CallManager"; | ||
|
||
private static ReactContext reactContext; | ||
private static Context context; | ||
|
||
// private SinchService sinchService= new SinchService(); | ||
// private SinchService.SinchServiceInterface mSinchServiceInterface; | ||
|
||
|
||
public CallManager(@NonNull ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
this.reactContext = reactContext; | ||
this.context = reactContext.getApplicationContext(); | ||
|
||
reactContext.addLifecycleEventListener(this); | ||
|
||
|
||
|
||
} | ||
|
||
|
||
/** | ||
* Called either when the host activity receives a resume event (e.g. | ||
* if the native module that implements this is initialized while the host activity is already | ||
* resumed. Always called for the most current activity. | ||
*/ | ||
@Override | ||
public void onHostResume() { | ||
Log.d(TAG, "onHostResume"); | ||
} | ||
|
||
/** | ||
* Called when host activity receives pause event (e.g.Always called | ||
* for the most current activity. | ||
*/ | ||
@Override | ||
public void onHostPause() { | ||
Log.d(TAG, "onHostPause"); | ||
} | ||
|
||
/** | ||
* Called when host activity receives destroy event (e.g. Only called | ||
* for the last React activity to be destroyed. | ||
*/ | ||
@Override | ||
public void onHostDestroy() { | ||
Log.d(TAG, "onHostDestroy"); | ||
} | ||
|
||
/** | ||
* @return the name of this module. This will be the name used to {@code require()} this module | ||
* from javascript. | ||
*/ | ||
@NonNull | ||
@Override | ||
public String getName() { | ||
return "CallManager"; | ||
} | ||
|
||
|
||
@ReactMethod | ||
public void setup(String userName) { | ||
Log.d(TAG, "setup username:" + userName); | ||
// this.sinchService.start(userName); | ||
} | ||
|
||
@ReactMethod | ||
public void callUser(String userName) { | ||
Log.d(TAG, "callUser username:" + userName); | ||
|
||
} | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
android/app/src/main/java/com/kadeno/reactnativecallpoc/CallManager/CallManagerPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.kadeno.reactnativecallpoc.CallManager; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import com.facebook.react.ReactPackage; | ||
import com.facebook.react.bridge.NativeModule; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.uimanager.ViewManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class CallManagerPackage implements ReactPackage { | ||
/** | ||
* @param reactContext react application context that can be used to create modules | ||
* @return list of native modules to register with the newly created catalyst instance | ||
*/ | ||
@NonNull | ||
@Override | ||
public List<NativeModule> createNativeModules(@NonNull ReactApplicationContext reactContext) { | ||
List<NativeModule> modules = new ArrayList<>(); | ||
|
||
modules.add(new CallManager(reactContext)); | ||
|
||
return modules; | ||
} | ||
|
||
/** | ||
* @param reactContext | ||
* @return a list of view managers that should be registered with {@link com.facebook.react.uimanager.UIManagerModule} | ||
*/ | ||
@NonNull | ||
@Override | ||
public List<ViewManager> createViewManagers(@NonNull ReactApplicationContext reactContext) { | ||
return Collections.emptyList(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
android/app/src/main/java/com/kadeno/reactnativecallpoc/Hmac.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.kadeno.reactnativecallpoc; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
import javax.crypto.Mac; | ||
import javax.crypto.spec.SecretKeySpec; | ||
|
||
final class Hmac { | ||
|
||
private Hmac() {} | ||
|
||
public static byte[] hmacSha256(byte[] key, String message) { | ||
if (null == key || key.length == 0) | ||
throw new IllegalArgumentException("Invaid input key to HMAC-256"); | ||
|
||
if (null == message) | ||
throw new IllegalArgumentException("Input message to HMAC-256 must not be null"); | ||
|
||
try { | ||
Mac mac = Mac.getInstance("HmacSHA256"); | ||
SecretKeySpec keySpec = new SecretKeySpec(key, "HmacSHA256"); | ||
mac.init(keySpec); | ||
return mac.doFinal(message.getBytes("UTF-8")); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new RuntimeException(e); | ||
} catch (InvalidKeyException e) { | ||
throw new RuntimeException(e); | ||
} catch (UnsupportedEncodingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
Oops, something went wrong.