Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package chat.rocket.reactnative.voip
import android.os.Handler
import android.os.Looper
import android.util.Log
import chat.rocket.reactnative.BuildConfig
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.Response
Expand Down Expand Up @@ -55,13 +56,17 @@ class DDPClient {

val wsUrl = buildWebSocketURL(host)

Log.d(TAG, "Connecting to $wsUrl")
if (BuildConfig.DEBUG) {
Log.d(TAG, "Connecting to $wsUrl")
}

val request = Request.Builder().url(wsUrl).build()

webSocket = client.newWebSocket(request, object : WebSocketListener() {
override fun onOpen(webSocket: WebSocket, response: Response) {
Log.d(TAG, "WebSocket opened")
if (BuildConfig.DEBUG) {
Log.d(TAG, "WebSocket opened")
}
val connectMsg = JSONObject().apply {
put("msg", "connect")
put("version", "1")
Expand Down Expand Up @@ -94,7 +99,9 @@ class DDPClient {

override fun onClosed(webSocket: WebSocket, code: Int, reason: String) {
if (webSocket !== this@DDPClient.webSocket) return
Log.d(TAG, "WebSocket closed: $code $reason")
if (BuildConfig.DEBUG) {
Log.d(TAG, "WebSocket closed: $code $reason")
}
isConnected = false
}
})
Expand All @@ -117,7 +124,9 @@ class DDPClient {
if (hasError) {
Log.e(TAG, "Login failed: ${data.opt("error")}")
} else {
Log.d(TAG, "Login succeeded")
if (BuildConfig.DEBUG) {
Log.d(TAG, "Login succeeded")
}
}
mainHandler.post { callback(!hasError) }
}
Expand All @@ -141,7 +150,9 @@ class DDPClient {
synchronized(pendingCallbacks) { pendingCallbacks.remove(msgId) }
val didSubscribe = data.optString("msg") == "ready" && !data.has("error")
if (didSubscribe) {
Log.d(TAG, "Subscribed to $name")
if (BuildConfig.DEBUG) {
Log.d(TAG, "Subscribed to $name")
}
} else {
Log.e(TAG, "Failed to subscribe to $name: ${data.opt("error") ?: "nosub"}")
}
Expand All @@ -156,7 +167,9 @@ class DDPClient {
}

fun disconnect() {
Log.d(TAG, "Disconnecting")
if (BuildConfig.DEBUG) {
Log.d(TAG, "Disconnecting")
}
isConnected = false
cancelConnectTimeout()
synchronized(pendingCallbacks) { pendingCallbacks.clear() }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chat.rocket.reactnative.voip

import android.app.Activity
import chat.rocket.reactnative.BuildConfig
import android.app.KeyguardManager
import android.content.BroadcastReceiver
import android.content.Context
Expand Down Expand Up @@ -94,7 +95,9 @@ class IncomingCallActivity : Activity() {
}
this.voipPayload = voipPayload

Log.d(TAG, "IncomingCallActivity created - callId: ${voipPayload.callId}, caller: ${voipPayload.caller}")
if (BuildConfig.DEBUG) {
Log.d(TAG, "IncomingCallActivity created - callId: ${voipPayload.callId}, caller: ${voipPayload.caller}")
}

updateUI(voipPayload)
setupButtons(voipPayload)
Expand Down Expand Up @@ -255,15 +258,19 @@ class IncomingCallActivity : Activity() {
}

private fun handleAccept(payload: VoipPayload) {
Log.d(TAG, "Call accepted - callId: ${payload.callId}")
if (BuildConfig.DEBUG) {
Log.d(TAG, "Call accepted - callId: ${payload.callId}")
}
clearTimeout()
VoipNotification.cancelTimeout(payload.callId)
VoipNotification.handleAcceptAction(this, payload)
// Activity finishes when ACTION_DISMISS is broadcast from handleAcceptAction (async DDP).
}

private fun handleDecline(payload: VoipPayload) {
Log.d(TAG, "Call declined - callId: ${payload.callId}")
if (BuildConfig.DEBUG) {
Log.d(TAG, "Call declined - callId: ${payload.callId}")
}
clearTimeout()
VoipNotification.cancelTimeout(payload.callId)
VoipNotification.handleDeclineAction(this, payload)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,7 @@ class MediaCallsAnswerRequest(

override fun onResponse(call: Call, response: okhttp3.Response) {
response.use {
val code = it.code
val success = code in 200..299
if (success) {
Log.d(TAG, "MediaCallsAnswerRequest response for callId=$callId: code=$code success=true")
} else {
Log.w(TAG, "MediaCallsAnswerRequest failed callId=$callId code=$code answer=$answer")
}
val success = it.code in 200..299
mainHandler.post { onResult(success) }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chat.rocket.reactnative.voip

import android.app.Notification
import android.app.NotificationChannel
import chat.rocket.reactnative.BuildConfig
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
Expand Down Expand Up @@ -71,7 +72,9 @@ class VoipCallService : Service() {
}
ACTION_START -> {
val callId = intent.getStringExtra(EXTRA_CALL_ID) ?: "unknown"
Log.d(TAG, "Starting VoipCallService for callId: $callId")
if (BuildConfig.DEBUG) {
Log.d(TAG, "Starting VoipCallService for callId: $callId")
}
if (!isRunning) {
isRunning = true
startForegroundWithNotification(callId)
Expand Down Expand Up @@ -101,7 +104,9 @@ class VoipCallService : Service() {
startForeground(NOTIFICATION_ID, notification)
}

Log.d(TAG, "Started foreground with notification for callId: $callId")
if (BuildConfig.DEBUG) {
Log.d(TAG, "Started foreground with notification for callId: $callId")
}
}

private fun buildNotification(callId: String): Notification {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package chat.rocket.reactnative.voip

import android.util.Log
import chat.rocket.reactnative.BuildConfig
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.WritableMap
import com.facebook.react.modules.core.DeviceEventManagerModule
Expand Down Expand Up @@ -108,7 +109,9 @@ class VoipModule(reactContext: ReactApplicationContext) : NativeVoipSpec(reactCo
val data = initialEventsData.get() ?: return null

if (data.isExpired()) {
Log.d(TAG, "Discarding expired VoIP initial event: ${data.callId}")
if (BuildConfig.DEBUG) {
Log.d(TAG, "Discarding expired VoIP initial event: ${data.callId}")
}
if (initialEventsData.compareAndSet(data, null)) {
return null
}
Expand Down Expand Up @@ -152,7 +155,9 @@ class VoipModule(reactContext: ReactApplicationContext) : NativeVoipSpec(reactCo
*/
override fun addListener(eventName: String) {
// Keep track of listeners if needed
Log.d(TAG, "addListener: $eventName")
if (BuildConfig.DEBUG) {
Log.d(TAG, "addListener: $eventName")
}
}

/**
Expand Down
Loading
Loading