@capgo/capacitor-stream-call 0.0.26 → 0.0.27

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.
@@ -34,8 +34,6 @@ public class StreamCallPlugin: CAPPlugin, CAPBridgedPlugin {
34
34
  }
35
35
  private var apiKey: String?
36
36
  private var state: State = .notInitialized
37
- private static let tokenRefreshQueue = DispatchQueue(label: "stream.call.token.refresh")
38
- private static let tokenRefreshSemaphore = DispatchSemaphore(value: 1)
39
37
  private var currentToken: String?
40
38
  private var tokenWaitSemaphore: DispatchSemaphore?
41
39
 
@@ -56,9 +54,6 @@ public class StreamCallPlugin: CAPPlugin, CAPBridgedPlugin {
56
54
  @Injected(\.callKitPushNotificationAdapter) var callKitPushNotificationAdapter
57
55
  private var webviewDelegate: WebviewNavigationDelegate?
58
56
 
59
- // Add class property to store call states
60
- private var callStates: [String: (members: [MemberResponse], participantResponses: [String: String], createdAt: Date, timer: Timer?)] = [:]
61
-
62
57
  // Declare as optional and initialize in load() method
63
58
  private var callViewModel: CallViewModel?
64
59
 
@@ -246,17 +241,6 @@ public class StreamCallPlugin: CAPPlugin, CAPBridgedPlugin {
246
241
  // Reset notification flag when call ends
247
242
  self.hasNotifiedCallJoined = false
248
243
 
249
- // Clean up any resources for this call
250
- if let callCid = endingCallId {
251
- // Invalidate and remove the timer
252
- self.callStates[callCid]?.timer?.invalidate()
253
-
254
- // Remove call from callStates
255
- self.callStates.removeValue(forKey: callCid)
256
-
257
- print("Cleaned up resources for ended call: \(callCid)")
258
- }
259
-
260
244
  // Remove the call overlay view when not in a call
261
245
  self.ensureViewRemoved()
262
246
  }
@@ -295,134 +279,6 @@ public class StreamCallPlugin: CAPPlugin, CAPBridgedPlugin {
295
279
  }
296
280
  }
297
281
 
298
- @objc private func checkCallTimeoutTimer(_ timer: Timer) {
299
- guard let callCid = timer.userInfo as? String else { return }
300
-
301
- Task { [weak self] in
302
- guard let self = self else { return }
303
- await self.checkCallTimeout(callCid: callCid)
304
- }
305
- }
306
-
307
- private func checkCallTimeout(callCid: String) async {
308
- // Get a local copy of the call state from the main thread
309
- let callState: (members: [MemberResponse], participantResponses: [String: String], createdAt: Date, timer: Timer?)? = await MainActor.run {
310
- return self.callStates[callCid]
311
- }
312
-
313
- guard let callState = callState else { return }
314
-
315
- // Calculate time elapsed since call creation
316
- let now = Date()
317
- let elapsedSeconds = now.timeIntervalSince(callState.createdAt)
318
-
319
- // Check if 30 seconds have passed
320
- if elapsedSeconds >= 30.0 {
321
-
322
- // Check if anyone has accepted
323
- let hasAccepted = callState.participantResponses.values.contains { $0 == "accepted" }
324
-
325
- if !hasAccepted {
326
- print("Call \(callCid) has timed out after \(elapsedSeconds) seconds")
327
- print("No one accepted call \(callCid), marking all non-responders as missed")
328
-
329
- // Mark all members who haven't responded as "missed"
330
- for member in callState.members {
331
- let memberId = member.userId
332
- let needsToBeMarkedAsMissed = await MainActor.run {
333
- return self.callStates[callCid]?.participantResponses[memberId] == nil
334
- }
335
-
336
- if needsToBeMarkedAsMissed {
337
- // Update callStates map on main thread
338
- await MainActor.run {
339
- var updatedCallState = self.callStates[callCid]
340
- updatedCallState?.participantResponses[memberId] = "missed"
341
- if let updatedCallState = updatedCallState {
342
- self.callStates[callCid] = updatedCallState
343
- }
344
- }
345
-
346
- // Notify listeners
347
- await MainActor.run {
348
- self.updateCallStatusAndNotify(callId: callCid, state: "missed", userId: memberId)
349
- }
350
- }
351
- }
352
-
353
- // End the call
354
- if let call = streamVideo?.state.activeCall, call.cId == callCid {
355
- call.leave()
356
- }
357
-
358
- // Clean up timer on main thread
359
- await MainActor.run {
360
- self.callStates[callCid]?.timer?.invalidate()
361
- var updatedCallState = self.callStates[callCid]
362
- updatedCallState?.timer = nil
363
- if let updatedCallState = updatedCallState {
364
- self.callStates[callCid] = updatedCallState
365
- }
366
-
367
- // Remove from callStates
368
- self.callStates.removeValue(forKey: callCid)
369
- }
370
-
371
- // Update UI
372
- await MainActor.run {
373
- // self.overlayViewModel?.updateCall(nil)
374
- self.overlayView?.isHidden = true
375
- self.webView?.isOpaque = true
376
- self.updateCallStatusAndNotify(callId: callCid, state: "ended", reason: "timeout")
377
- }
378
- }
379
- }
380
- }
381
-
382
- private func checkAllParticipantsResponded(callCid: String) async {
383
- // Get a local copy of the call state from the main thread
384
- let callState: (members: [MemberResponse], participantResponses: [String: String], createdAt: Date, timer: Timer?)? = await MainActor.run {
385
- return self.callStates[callCid]
386
- }
387
-
388
- guard let callState = callState else {
389
- print("Call state not found for cId: \(callCid)")
390
- return
391
- }
392
-
393
- let totalParticipants = callState.members.count
394
- let responseCount = callState.participantResponses.count
395
-
396
- print("Total participants: \(totalParticipants), Responses: \(responseCount)")
397
-
398
- let allResponded = responseCount >= totalParticipants
399
- let allRejectedOrMissed = allResponded &&
400
- callState.participantResponses.values.allSatisfy { $0 == "rejected" || $0 == "missed" }
401
-
402
- if allResponded && allRejectedOrMissed {
403
- print("All participants have rejected or missed the call")
404
-
405
- // End the call
406
- if let call = streamVideo?.state.activeCall, call.cId == callCid {
407
- call.leave()
408
- }
409
-
410
- // Clean up timer and remove from callStates on main thread
411
- await MainActor.run {
412
- // Clean up timer
413
- self.callStates[callCid]?.timer?.invalidate()
414
-
415
- // Remove from callStates
416
- self.callStates.removeValue(forKey: callCid)
417
-
418
- // self.overlayViewModel?.updateCall(nil)
419
- self.overlayView?.isHidden = true
420
- self.webView?.isOpaque = true
421
- self.updateCallStatusAndNotify(callId: callCid, state: "ended", reason: "all_rejected_or_missed")
422
- }
423
- }
424
- }
425
-
426
282
  @objc func login(_ call: CAPPluginCall) {
427
283
  guard let token = call.getString("token"),
428
284
  let userId = call.getString("userId"),
@@ -551,23 +407,19 @@ public class StreamCallPlugin: CAPPlugin, CAPBridgedPlugin {
551
407
  print("- Should Ring: \(shouldRing)")
552
408
  print("- Team: \(team)")
553
409
 
554
- // Create the call object
555
- let streamCall = streamVideo?.call(callType: callType, callId: callId)
556
-
557
- // Start the call with the members
558
- print("Creating call with members...")
559
- try await streamCall?.create(
560
- memberIds: members,
561
- custom: [:],
562
- team: team, ring: shouldRing
563
- )
564
410
 
565
- // Join the call
566
- print("Joining call...")
567
- try await streamCall?.join(create: false)
568
- print("Successfully joined call")
569
411
 
570
412
  // Update the CallOverlayView with the active call
413
+ // Create the call object
414
+ await self.callViewModel?.startCall(
415
+ callType: callType,
416
+ callId: callId,
417
+ members: members.map { Member(userId: $0, role: nil, customData: [:], updatedAt: nil) },
418
+ ring: shouldRing
419
+ )
420
+
421
+
422
+ // Update UI on main thread
571
423
  await MainActor.run {
572
424
  // self.overlayViewModel?.updateCall(streamCall)
573
425
  self.overlayView?.isHidden = false
@@ -576,7 +428,8 @@ public class StreamCallPlugin: CAPPlugin, CAPBridgedPlugin {
576
428
 
577
429
  call.resolve([
578
430
  "success": true
579
- ])
431
+ ])
432
+
580
433
  } catch {
581
434
  log.error("Error making call: \(String(describing: error))")
582
435
  call.reject("Failed to make call: \(error.localizedDescription)")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-stream-call",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
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",