@capgo/capacitor-stream-call 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -206,22 +206,11 @@ fun CallOverlayView(
206
206
  floatingVideoRenderer = floatingVideoRender
207
207
  )
208
208
  } else {
209
- if (connection != RealtimeConnection.Connected) {
210
- android.util.Log.d("CallOverlayView", "Showing waiting message - not connected")
211
- Text(
212
- text = "waiting for a remote participant...",
213
- fontSize = 30.sp,
214
- color = VideoTheme.colors.basePrimary
215
- )
216
- } else {
217
- Text(
218
- modifier = Modifier.padding(30.dp),
219
- text = "Join call ${call.id} in your browser to see the video here",
220
- fontSize = 30.sp,
221
- color = VideoTheme.colors.basePrimary,
222
- textAlign = TextAlign.Center
223
- )
224
- }
209
+ Box(
210
+ modifier = Modifier
211
+ .fillMaxSize()
212
+ .background(VideoTheme.colors.baseSenary)
213
+ )
225
214
  }
226
215
  }
227
216
  }
@@ -35,6 +35,7 @@ import io.getstream.video.android.model.StreamCallId
35
35
  import io.getstream.video.android.model.User
36
36
  import io.getstream.video.android.model.streamCallId
37
37
  import kotlinx.coroutines.DelicateCoroutinesApi
38
+ import kotlinx.coroutines.flow.Flow
38
39
  import kotlinx.coroutines.launch
39
40
  import org.openapitools.client.models.CallAcceptedEvent
40
41
  import org.openapitools.client.models.CallEndedEvent
@@ -42,6 +43,8 @@ import org.openapitools.client.models.CallMissedEvent
42
43
  import org.openapitools.client.models.CallRejectedEvent
43
44
  import org.openapitools.client.models.CallSessionEndedEvent
44
45
  import org.openapitools.client.models.VideoEvent
46
+ import io.getstream.video.android.model.Device
47
+ import kotlinx.coroutines.flow.first
45
48
 
46
49
  // I am not a religious pearson, but at this point, I am not sure even god himself would understand this code
47
50
  // It's a spaghetti-like, tangled, unreadable mess and frankly, I am deeply sorry for the code crimes commited in the Android impl
@@ -339,7 +342,7 @@ public class StreamCallPlugin : Plugin() {
339
342
  SecureUserRepository.getInstance(context).save(credentials)
340
343
 
341
344
  // Initialize Stream Video with new credentials
342
- if (!hadSavedCredentials) {
345
+ if (!hadSavedCredentials || (savedCredentials!!.user.id !== userId)) {
343
346
  initializeStreamVideo()
344
347
  }
345
348
 
@@ -358,15 +361,20 @@ public class StreamCallPlugin : Plugin() {
358
361
  SecureUserRepository.getInstance(context).removeCurrentUser()
359
362
 
360
363
  // Properly cleanup the client
361
- streamVideoClient?.let {
362
- StreamVideo.removeClient()
363
- }
364
- streamVideoClient = null
365
- state = State.NOT_INITIALIZED
364
+ kotlinx.coroutines.GlobalScope.launch {
365
+ streamVideoClient?.let {
366
+ magicDeviceDelete(it)
367
+ it.logOut()
368
+ StreamVideo.removeClient()
369
+ }
366
370
 
367
- val ret = JSObject()
368
- ret.put("success", true)
369
- call.resolve(ret)
371
+ streamVideoClient = null
372
+ state = State.NOT_INITIALIZED
373
+
374
+ val ret = JSObject()
375
+ ret.put("success", true)
376
+ call.resolve(ret)
377
+ }
370
378
  } catch (e: Exception) {
371
379
  call.reject("Failed to logout", e)
372
380
  }
@@ -1144,4 +1152,67 @@ public class StreamCallPlugin : Plugin() {
1144
1152
  }
1145
1153
  }
1146
1154
  }
1155
+
1156
+ private suspend fun magicDeviceDelete(streamVideoClient: StreamVideo) {
1157
+ try {
1158
+ android.util.Log.d("StreamCallPlugin", "Starting magicDeviceDelete reflection operation")
1159
+
1160
+ // Get the streamNotificationManager field from StreamVideo
1161
+ val streamVideoClass = streamVideoClient.javaClass
1162
+ val notificationManagerField = streamVideoClass.getDeclaredField("streamNotificationManager")
1163
+ notificationManagerField.isAccessible = true
1164
+ val notificationManager = notificationManagerField.get(streamVideoClient)
1165
+
1166
+ if (notificationManager == null) {
1167
+ android.util.Log.e("StreamCallPlugin", "streamNotificationManager is null")
1168
+ return
1169
+ }
1170
+
1171
+ android.util.Log.d("StreamCallPlugin", "Successfully accessed streamNotificationManager")
1172
+
1173
+ // Get deviceTokenStorage from notification manager
1174
+ val notificationManagerClass = notificationManager.javaClass
1175
+ val deviceTokenStorageField = notificationManagerClass.getDeclaredField("deviceTokenStorage")
1176
+ deviceTokenStorageField.isAccessible = true
1177
+ val deviceTokenStorage = deviceTokenStorageField.get(notificationManager)
1178
+
1179
+ if (deviceTokenStorage == null) {
1180
+ android.util.Log.e("StreamCallPlugin", "deviceTokenStorage is null")
1181
+ return
1182
+ }
1183
+
1184
+ android.util.Log.d("StreamCallPlugin", "Successfully accessed deviceTokenStorage")
1185
+
1186
+ // Access the DeviceTokenStorage object dynamically without hardcoding class
1187
+ val deviceTokenStorageClass = deviceTokenStorage.javaClass
1188
+
1189
+ // Get the userDevice Flow from deviceTokenStorage
1190
+ val userDeviceField = deviceTokenStorageClass.getDeclaredField("userDevice")
1191
+ userDeviceField.isAccessible = true
1192
+ val userDeviceFlow = userDeviceField.get(deviceTokenStorage)
1193
+
1194
+ if (userDeviceFlow == null) {
1195
+ android.util.Log.e("StreamCallPlugin", "userDevice Flow is null")
1196
+ return
1197
+ }
1198
+
1199
+ android.util.Log.d("StreamCallPlugin", "Successfully accessed userDevice Flow: $userDeviceFlow")
1200
+
1201
+ val castedUserDeviceFlow = userDeviceFlow as Flow<Device?>
1202
+ try {
1203
+ castedUserDeviceFlow.first {
1204
+ if (it == null) {
1205
+ android.util.Log.d("StreamCallPlugin", "Device is null. Nothing to remove")
1206
+ return@first true;
1207
+ }
1208
+ streamVideoClient.deleteDevice(it)
1209
+ return@first true;
1210
+ }
1211
+ } catch (e: Throwable) {
1212
+ android.util.Log.e("StreamCallPlugin", "Cannot collect flow in magicDeviceDelete", e)
1213
+ }
1214
+ } catch (e: Exception) {
1215
+ android.util.Log.e("StreamCallPlugin", "Error in magicDeviceDelete", e)
1216
+ }
1217
+ }
1147
1218
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-stream-call",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "Uses the https://getstream.io/ SDK to implement calling in Capacitor",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",