voip-callkit 0.0.6 → 0.0.7

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.
@@ -16,7 +16,7 @@ public class CallKitVoipPlugin: CAPPlugin {
16
16
  private var connectionIdRegistry : [UUID: CallConfig] = [:]
17
17
  private var urlString = "wss://demo.piesocket.com/v3/channel_1?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV&notify_self"
18
18
  var webSocket: URLSessionWebSocketTask?
19
-
19
+ var callUUID:UUID?
20
20
  @objc func register(_ call: CAPPluginCall) {
21
21
  // config PushKit
22
22
  voipRegistry.delegate = self
@@ -46,7 +46,7 @@ public class CallKitVoipPlugin: CAPPlugin {
46
46
  }
47
47
  }
48
48
 
49
- public func incommingCall(from: String, connectionId: String) {
49
+ public func incommingCall(from: String, connectionId: String,uuid:UUID) {
50
50
  let update = CXCallUpdate()
51
51
  update.remoteHandle = CXHandle(type: .generic, value: from)
52
52
  update.hasVideo = true
@@ -56,7 +56,7 @@ public class CallKitVoipPlugin: CAPPlugin {
56
56
  update.supportsUngrouping = false
57
57
  update.hasVideo = true
58
58
 
59
- let uuid = UUID()
59
+ //let uuid = UUID()
60
60
  connectionIdRegistry[uuid] = .init(connectionId: connectionId, username: from)
61
61
  self.provider?.reportNewIncomingCall(with: uuid, update: update, completion: { (_) in })
62
62
  }
@@ -77,6 +77,7 @@ public class CallKitVoipPlugin: CAPPlugin {
77
77
  let webSocket = session.webSocketTask(with: request)
78
78
  self.webSocket = webSocket
79
79
  //self.opened = true
80
+ print("open web socket called")
80
81
  self.webSocket?.resume()
81
82
  } else {
82
83
  webSocket = nil
@@ -93,8 +94,15 @@ public class CallKitVoipPlugin: CAPPlugin {
93
94
  switch result {
94
95
 
95
96
  case .success(let message):
97
+
96
98
  switch message {
97
99
  case .string(let str):
100
+ if str.contains("video closed") {
101
+ if let uuid = self?.callUUID{
102
+ print("timeout func1")
103
+ self?.endCall(uuid:uuid)
104
+ }
105
+ }
98
106
  print("got message str \(str)")
99
107
  case .data(let data):
100
108
  print("got message data \(data)")
@@ -108,7 +116,7 @@ public class CallKitVoipPlugin: CAPPlugin {
108
116
  })
109
117
  }
110
118
  func send(){
111
- DispatchQueue.global().asyncAfter(deadline: .now()+10){
119
+ DispatchQueue.global().asyncAfter(deadline: .now()+2){
112
120
  self.webSocket?.send(.string("video closed:\("user declined")"), completionHandler: { error in
113
121
  if let error = error {
114
122
  print("error sending message \(error)")
@@ -127,6 +135,7 @@ extension CallKitVoipPlugin: URLSessionWebSocketDelegate {
127
135
  public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol protocol: String?) {
128
136
  // opened = true
129
137
  print("did connect to server")
138
+ self.recieve()
130
139
  }
131
140
 
132
141
 
@@ -159,8 +168,8 @@ extension CallKitVoipPlugin: CXProviderDelegate {
159
168
 
160
169
  public func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
161
170
  notifyEvent(eventName: "callStarted", uuid: action.callUUID)
162
- openWebSocket()
163
- send()
171
+ callUUID = action.callUUID
172
+ //send()
164
173
  action.fulfill()
165
174
  }
166
175
  }
@@ -182,9 +191,24 @@ extension CallKitVoipPlugin: PKPushRegistryDelegate {
182
191
  // }
183
192
 
184
193
  // let username = (payload.dictionaryPayload["Username"] as? String) ?? "Anonymus"
194
+
195
+ let backgroundTaskIdentifier =
196
+ UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
197
+ let uuid = UUID()
198
+ self.callUUID = uuid
199
+ openWebSocket()
185
200
 
186
-
187
- self.incommingCall(from: "username", connectionId: "123")
201
+ self.incommingCall(from: "username", connectionId: "123",uuid:uuid)
202
+
203
+ DispatchQueue.global().asyncAfter(deadline: .now()+20){
204
+ print("timeout func")
205
+ // if let uuid = self.callUUID{
206
+ // print("timeout func1")
207
+ // self.endCall(uuid:uuid)
208
+ // }
209
+ self.send()
210
+ UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
211
+ }
188
212
  }
189
213
 
190
214
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "voip-callkit",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "capacitor plugin for callkit and voip",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",