Skip to content

Commit

Permalink
feat(CLNP-1920): sdk update, integrate logger (#38)
Browse files Browse the repository at this point in the history
* feat: integrate logger with native

* feat: update native sdk and support onLocalParticipantReconnected and onLocalParticipantDisconnected events

* chore: add NOT_CONNECTED direct call end result

* chore: update sample

* fix: resolve react type issue

* chore: add postbuild.js
  • Loading branch information
bang9 authored Jan 12, 2024
1 parent 8341047 commit 4ce705a
Showing 32 changed files with 305 additions and 92 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
@@ -96,7 +96,7 @@ dependencies {
// noinspection GradleDynamicVersion
implementation "com.facebook.react:react-native:+"
implementation "org.jetbrains.kotlin:kotlin-stdlib:${ReactNative.ext.getVersion("android", "kotlin")}"
implementation("com.sendbird.sdk:sendbird-calls:1.10.0")
implementation("com.sendbird.sdk:sendbird-calls:1.11.10")
}


Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.sendbird.calls.reactnative

import android.util.Log
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.WritableMap
import com.facebook.react.modules.core.DeviceEventManagerModule
import com.sendbird.calls.reactnative.module.CallsModule
import com.sendbird.calls.reactnative.utils.CallsUtils
import com.sendbird.calls.reactnative.utils.RNCallsLogger

fun defaultType(type: String): String {
return "${CallsEvents.EVENT_DEFAULT}.${type}"
@@ -51,6 +50,8 @@ class CallsEvents {
// Group
val TYPE_GROUP_CALL_ON_DELETED = groupCallType("onDeleted")
val TYPE_GROUP_CALL_ON_ERROR = groupCallType("onError")
val TYPE_GROUP_CALL_ON_LOCAL_PARTICIPANT_DISCONNECTED = groupCallType("onLocalParticipantDisconnected")
val TYPE_GROUP_CALL_ON_LOCAL_PARTICIPANT_RECONNECTED = groupCallType("onLocalParticipantReconnected")
val TYPE_GROUP_CALL_ON_REMOTE_PARTICIPANT_ENTERED = groupCallType("onRemoteParticipantEntered")
val TYPE_GROUP_CALL_ON_REMOTE_PARTICIPANT_EXITED = groupCallType("onRemoteParticipantExited")
val TYPE_GROUP_CALL_ON_REMOTE_PARTICIPANT_STREAM_STARTED = groupCallType("onRemoteParticipantStreamStarted")
@@ -61,7 +62,7 @@ class CallsEvents {
val TYPE_GROUP_CALL_ON_CUSTOM_ITEMS_DELETED = groupCallType("onCustomItemsDeleted")

fun sendEvent(reactContext: ReactContext, event: String, eventType: String, data: WritableMap) {
Log.d(CallsModule.NAME, "[CallsEvents] sendEvent() $event++$eventType")
RNCallsLogger.d("[CallsEvents] sendEvent() $event++$eventType")

reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
@@ -72,7 +73,7 @@ class CallsEvents {
}

fun sendEvent(reactContext: ReactContext, event: String, eventType: String, data: WritableMap, additionalData: Any) {
Log.d(CallsModule.NAME, "[CallsEvents] sendEvent() $event++$eventType")
RNCallsLogger.d("[CallsEvents] sendEvent() $event++$eventType")

reactContext
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)
Original file line number Diff line number Diff line change
@@ -14,4 +14,5 @@ fun DirectCallEndResult.asString() = when (this) {
DirectCallEndResult.DIAL_FAILED -> "DIAL_FAILED"
DirectCallEndResult.ACCEPT_FAILED -> "ACCEPT_FAILED"
DirectCallEndResult.OTHER_DEVICE_ACCEPTED -> "OTHER_DEVICE_ACCEPTED"
DirectCallEndResult.NOT_CONNECTED -> "NOT_CONNECTED"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sendbird.calls.reactnative.module

import android.util.Log
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReadableMap
import com.sendbird.calls.*
@@ -9,31 +8,36 @@ import com.sendbird.calls.reactnative.extension.rejectCalls
import com.sendbird.calls.reactnative.module.listener.CallsDirectCallListener
import com.sendbird.calls.reactnative.module.listener.CallsGroupCallListener
import com.sendbird.calls.reactnative.utils.CallsUtils
import com.sendbird.calls.reactnative.utils.RNCallsLogger

class CallsCommonModule(private val root: CallsModule): CommonModule {
override fun setLoggerLevel(level: String) {
RNCallsLogger.setLoggerLevel(level)
}

override fun addDirectCallSound(type: String, fileName: String) {
Log.d(CallsModule.NAME, "[CommonModule] addDirectCallSound($type, $fileName)")
RNCallsLogger.d("[CommonModule] addDirectCallSound($type, $fileName)")
val soundType = SendBirdCall.SoundType.valueOf(type)
val resourceId = root.reactContext.resources.getIdentifier(fileName, "raw", root.reactContext.packageName)
if (resourceId != 0) {
Log.d(CallsModule.NAME, "[CommonModule] addDirectCallSound resource $resourceId")
RNCallsLogger.d("[CommonModule] addDirectCallSound resource $resourceId")
SendBirdCall.Options.addDirectCallSound(soundType, resourceId)
}
}

override fun removeDirectCallSound(type: String) {
Log.d(CallsModule.NAME, "[CommonModule] removeDirectCallSound($type)")
RNCallsLogger.d("[CommonModule] removeDirectCallSound($type)")
val soundType = SendBirdCall.SoundType.valueOf(type)
SendBirdCall.Options.removeDirectCallSound(soundType)
}

override fun setDirectCallDialingSoundOnWhenSilentOrVibrateMode(enabled: Boolean) {
Log.d(CallsModule.NAME, "[CommonModule] setDirectCallDialingSoundOnWhenSilentOrVibrateMode($enabled)")
RNCallsLogger.d("[CommonModule] setDirectCallDialingSoundOnWhenSilentOrVibrateMode($enabled)")
SendBirdCall.Options.setDirectCallDialingSoundOnWhenSilentOrVibrateMode(enabled)
}

override fun getCurrentUser(promise: Promise) {
Log.d(CallsModule.NAME, "[CommonModule] getCurrentUser()")
RNCallsLogger.d("[CommonModule] getCurrentUser()")
SendBirdCall.currentUser
?.let {
promise.resolve(CallsUtils.convertUserToJsMap(it))
@@ -44,13 +48,13 @@ class CallsCommonModule(private val root: CallsModule): CommonModule {
}

override fun getOngoingCalls(promise: Promise) {
Log.d(CallsModule.NAME, "[CommonModule] getOngoingCalls()")
RNCallsLogger.d("[CommonModule] getOngoingCalls()")
val list = SendBirdCall.ongoingCalls.map { CallsUtils.convertDirectCallToJsMap(it) }
promise.resolve(CallsUtils.convertToJsArray(list))
}

override fun getDirectCall(callId: String, promise: Promise) {
Log.d(CallsModule.NAME, "[CommonModule] getDirectCall($callId)")
RNCallsLogger.d("[CommonModule] getDirectCall($callId)")
SendBirdCall.getCall(callId)
?.let {
promise.resolve(CallsUtils.convertDirectCallToJsMap(it))
@@ -61,12 +65,12 @@ class CallsCommonModule(private val root: CallsModule): CommonModule {
}

override fun initialize(appId: String): Boolean {
Log.d(CallsModule.NAME, "[CommonModule] initialize($appId)")
RNCallsLogger.d("[CommonModule] initialize()")
return SendBirdCall.init(root.reactContext, appId)
}

override fun authenticate(authParams: ReadableMap, promise: Promise) {
Log.d(CallsModule.NAME, "[CommonModule] authenticate(${authParams.toHashMap()})")
RNCallsLogger.d("[CommonModule] authenticate()")

val userId = authParams.getString("userId")!!
val accessToken = CallsUtils.safeGet { authParams.getString("accessToken") }
@@ -86,7 +90,7 @@ class CallsCommonModule(private val root: CallsModule): CommonModule {
}

override fun deauthenticate(promise: Promise) {
Log.d(CallsModule.NAME, "[CommonModule] deauthenticate()")
RNCallsLogger.d("[CommonModule] deauthenticate()")
SendBirdCall.deauthenticate { error ->
error
?.let {
@@ -99,7 +103,7 @@ class CallsCommonModule(private val root: CallsModule): CommonModule {
}

override fun registerPushToken(token: String, unique: Boolean, promise: Promise) {
Log.d(CallsModule.NAME, "[CommonModule] registerPushToken($token)")
RNCallsLogger.d("[CommonModule] registerPushToken()")
SendBirdCall.registerPushToken(token, unique) { error ->
error
?.let {
@@ -112,7 +116,7 @@ class CallsCommonModule(private val root: CallsModule): CommonModule {
}

override fun unregisterPushToken(token: String, promise: Promise) {
Log.d(CallsModule.NAME, "[CommonModule] unregisterPushToken($token)")
RNCallsLogger.d("[CommonModule] unregisterPushToken()")
SendBirdCall.unregisterPushToken(token) { error ->
error
?.let {
@@ -125,8 +129,8 @@ class CallsCommonModule(private val root: CallsModule): CommonModule {
}

override fun dial(calleeId: String, isVideoCall: Boolean, options: ReadableMap, promise: Promise) {
Log.d(CallsModule.NAME, "[CommonModule] dial($calleeId)")
Log.d(CallsModule.NAME, "[CommonModule] dial options -> ${options.toHashMap()}")
RNCallsLogger.d("[CommonModule] dial($calleeId)")
RNCallsLogger.d("[CommonModule] dial options -> ${options.toHashMap()}")
val from = "common/dial"

val localVideoViewId = CallsUtils.safeGet { options.getInt("localVideoViewId") }
@@ -178,7 +182,7 @@ class CallsCommonModule(private val root: CallsModule): CommonModule {

override fun createRoom(params: ReadableMap, promise: Promise) {
val roomType = CallsUtils.safeGet { params.getString("roomType") } ?: "SMALL_ROOM_FOR_VIDEO"
Log.d(CallsModule.NAME, "[CommonModule] createRoom($roomType)")
RNCallsLogger.d("[CommonModule] createRoom($roomType)")

val roomParams = RoomParams(RoomType.valueOf(roomType.uppercase()))
SendBirdCall.createRoom(roomParams) { room, error ->
@@ -193,7 +197,7 @@ class CallsCommonModule(private val root: CallsModule): CommonModule {
}

override fun fetchRoomById(roomId: String, promise: Promise) {
Log.d(CallsModule.NAME, "[CommonModule] fetchRoomById($roomId)")
RNCallsLogger.d("[CommonModule] fetchRoomById($roomId)")
SendBirdCall.fetchRoomById(roomId) { room, error ->
error?.let {
promise.rejectCalls(it)
@@ -206,7 +210,7 @@ class CallsCommonModule(private val root: CallsModule): CommonModule {
}

override fun getCachedRoomById(roomId: String , promise: Promise) {
Log.d(CallsModule.NAME, "[CommonModule] getCachedRoomById($roomId)")
RNCallsLogger.d("[CommonModule] getCachedRoomById($roomId)")
SendBirdCall.getCachedRoomById(roomId)
?.let {
promise.resolve(CallsUtils.convertRoomToJsMap(it))
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sendbird.calls.reactnative.module

import android.util.Log
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReadableMap
import com.sendbird.calls.AcceptParams
@@ -9,11 +8,11 @@ import com.sendbird.calls.CallOptions
import com.sendbird.calls.reactnative.RNCallsInternalError
import com.sendbird.calls.reactnative.extension.rejectCalls
import com.sendbird.calls.reactnative.utils.CallsUtils
import com.sendbird.calls.reactnative.utils.RNCallsLogger

class CallsDirectCallModule(private val root: CallsModule): DirectCallModule {
override fun accept(callId: String, options: ReadableMap, holdActiveCall: Boolean, promise: Promise) {
Log.d(CallsModule.NAME, "[DirectCallModule] accept() -> $callId")
Log.d(CallsModule.NAME, "[DirectCallModule] accept options -> ${options.toHashMap()}")
RNCallsLogger.d("[DirectCallModule] accept() -> $callId")

CallsUtils.safeRun(promise) {
val from = "directCall/accept"
@@ -54,7 +53,7 @@ class CallsDirectCallModule(private val root: CallsModule): DirectCallModule {
}

override fun end(callId: String, promise: Promise) {
Log.d(CallsModule.NAME, "[DirectCallModule] end() -> $callId")
RNCallsLogger.d("[DirectCallModule] end() -> $callId")

CallsUtils.safeRun(promise) {
val from = "directCall/end"
@@ -64,7 +63,7 @@ class CallsDirectCallModule(private val root: CallsModule): DirectCallModule {
}

override fun updateLocalVideoView(callId: String, videoViewId: Int) {
Log.d(CallsModule.NAME, "[DirectCallModule] updateLocalVideoView() -> $callId / $videoViewId")
RNCallsLogger.d("[DirectCallModule] updateLocalVideoView() -> $callId / $videoViewId")

CallsUtils.safeRun {
val from = "directCall/updateLocalVideoView"
@@ -75,7 +74,7 @@ class CallsDirectCallModule(private val root: CallsModule): DirectCallModule {
}

override fun updateRemoteVideoView(callId: String, videoViewId: Int) {
Log.d(CallsModule.NAME, "[DirectCallModule] updateRemoteVideoView() -> $callId / $videoViewId")
RNCallsLogger.d("[DirectCallModule] updateRemoteVideoView() -> $callId / $videoViewId")

CallsUtils.safeRun {
val from = "directCall/updateRemoteVideoView"
@@ -114,7 +113,7 @@ class CallsDirectCallModule(private val root: CallsModule): DirectCallModule {

override fun muteMicrophone(type: String, identifier: String) {
val from = "directCall/muteMicrophone"
Log.d(CallsModule.NAME, "[DirectCallModule] $from ($identifier)")
RNCallsLogger.d("[DirectCallModule] $from ($identifier)")

CallsUtils.safeRun {
CallsUtils.findDirectCall(identifier, from).muteMicrophone()
@@ -123,7 +122,7 @@ class CallsDirectCallModule(private val root: CallsModule): DirectCallModule {

override fun unmuteMicrophone(type: String, identifier: String) {
val from = "directCall/unmuteMicrophone"
Log.d(CallsModule.NAME, "[DirectCallModule] $from ($identifier)")
RNCallsLogger.d("[DirectCallModule] $from ($identifier)")

CallsUtils.safeRun {
CallsUtils.findDirectCall(identifier, from).unmuteMicrophone()
@@ -132,7 +131,7 @@ class CallsDirectCallModule(private val root: CallsModule): DirectCallModule {

override fun stopVideo(type: String, identifier: String) {
val from = "directCall/stopVideo"
Log.d(CallsModule.NAME, "[DirectCallModule] $from ($identifier)")
RNCallsLogger.d("[DirectCallModule] $from ($identifier)")

CallsUtils.safeRun {
CallsUtils.findDirectCall(identifier, from).stopVideo()
@@ -141,7 +140,7 @@ class CallsDirectCallModule(private val root: CallsModule): DirectCallModule {

override fun startVideo(type: String, identifier: String) {
val from = "directCall/startVideo"
Log.d(CallsModule.NAME, "[DirectCallModule] $from ($identifier)")
RNCallsLogger.d("[DirectCallModule] $from ($identifier)")

CallsUtils.safeRun {
CallsUtils.findDirectCall(identifier, from).startVideo()
@@ -150,7 +149,7 @@ class CallsDirectCallModule(private val root: CallsModule): DirectCallModule {

override fun switchCamera(type: String, identifier: String, promise: Promise) {
val from = "directCall/switchCamera"
Log.d(CallsModule.NAME, "[DirectCallModule] $from ($identifier)")
RNCallsLogger.d("[DirectCallModule] $from ($identifier)")

CallsUtils.safeRun(promise) {
CallsUtils.findDirectCall(identifier, from).switchCamera { error ->
@@ -167,7 +166,7 @@ class CallsDirectCallModule(private val root: CallsModule): DirectCallModule {

override fun selectAudioDevice(type: String, identifier: String, device: String, promise: Promise) {
val from = "directCall/switchCamera"
Log.d(CallsModule.NAME, "[DirectCallModule] $from ($identifier)")
RNCallsLogger.d("[DirectCallModule] $from ($identifier)")

CallsUtils.safeRun(promise) {
val audioDevice = AudioDevice.valueOf(device)
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.sendbird.calls.reactnative.module

import android.util.Log
import com.facebook.react.bridge.Promise
import com.facebook.react.bridge.ReadableMap
import com.sendbird.calls.*
import com.sendbird.calls.reactnative.RNCallsInternalError
import com.sendbird.calls.reactnative.extension.rejectCalls
import com.sendbird.calls.reactnative.utils.CallsUtils
import com.sendbird.calls.reactnative.utils.RNCallsLogger

class CallsGroupCallModule: GroupCallModule {
override fun enter(roomId: String, options: ReadableMap, promise: Promise) {
val from = "groupCall/enter"
Log.d(CallsModule.NAME, "[GroupCallModule] $from -> roomId($roomId) options(${options.toHashMap()})")
RNCallsLogger.d("[GroupCallModule] $from -> roomId($roomId) options(${options.toHashMap()})")
SendBirdCall.getCachedRoomById(roomId)
?.let {
val audioEnabled = CallsUtils.safeGet { options.getBoolean("audioEnabled") }
@@ -43,15 +43,15 @@ class CallsGroupCallModule: GroupCallModule {

override fun exit(roomId: String) {
val from = "groupCall/exit"
Log.d(CallsModule.NAME, "[GroupCallModule] $from -> roomId($roomId)")
RNCallsLogger.d("[GroupCallModule] $from -> roomId($roomId)")
CallsUtils.safeRun {
CallsUtils.findRoom(roomId, from).exit()
}
}

override fun muteMicrophone(type: String, identifier: String) {
val from = "groupCall/muteMicrophone"
Log.d(CallsModule.NAME, "[GroupCallModule] $from ($identifier)")
RNCallsLogger.d("[GroupCallModule] $from ($identifier)")

CallsUtils.safeRun {
CallsUtils.findRoom(identifier, from).localParticipant?.muteMicrophone()
@@ -60,7 +60,7 @@ class CallsGroupCallModule: GroupCallModule {

override fun unmuteMicrophone(type: String, identifier: String) {
val from = "groupCall/unmuteMicrophone"
Log.d(CallsModule.NAME, "[GroupCallModule] $from ($identifier)")
RNCallsLogger.d("[GroupCallModule] $from ($identifier)")

CallsUtils.safeRun {
CallsUtils.findRoom(identifier, from).localParticipant?.unmuteMicrophone()
@@ -69,7 +69,7 @@ class CallsGroupCallModule: GroupCallModule {

override fun stopVideo(type: String, identifier: String) {
val from = "groupCall/stopVideo"
Log.d(CallsModule.NAME, "[GroupCallModule] $from ($identifier)")
RNCallsLogger.d("[GroupCallModule] $from ($identifier)")

CallsUtils.safeRun {
CallsUtils.findRoom(identifier, from).localParticipant?.stopVideo()
@@ -78,7 +78,7 @@ class CallsGroupCallModule: GroupCallModule {

override fun startVideo(type: String, identifier: String) {
val from = "groupCall/startVideo"
Log.d(CallsModule.NAME, "[GroupCallModule] $from ($identifier)")
RNCallsLogger.d("[GroupCallModule] $from ($identifier)")

CallsUtils.safeRun {
CallsUtils.findRoom(identifier, from).localParticipant?.startVideo()
@@ -87,7 +87,7 @@ class CallsGroupCallModule: GroupCallModule {

override fun switchCamera(type: String, identifier: String, promise: Promise) {
val from = "groupCall/switchCamera"
Log.d(CallsModule.NAME, "[GroupCallModule] $from ($identifier)")
RNCallsLogger.d("[GroupCallModule] $from ($identifier)")

CallsUtils.safeRun(promise) {
CallsUtils.findRoom(identifier, from).localParticipant?.switchCamera { error ->
@@ -104,7 +104,7 @@ class CallsGroupCallModule: GroupCallModule {

override fun selectAudioDevice(type: String, identifier: String, device: String, promise: Promise) {
val from = "groupCall/switchCamera"
Log.d(CallsModule.NAME, "[GroupCallModule] $from ($identifier)")
RNCallsLogger.d("[GroupCallModule] $from ($identifier)")

CallsUtils.safeRun(promise) {
val audioDevice = AudioDevice.valueOf(device)
Loading

0 comments on commit 4ce705a

Please sign in to comment.