voip-callkit 0.0.7 → 0.0.8

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.
@@ -3,7 +3,7 @@ import Capacitor
3
3
  import UIKit
4
4
  import CallKit
5
5
  import PushKit
6
-
6
+ import SwiftSignalRClient
7
7
  /**
8
8
  * CallKit Voip Plugin provides native PushKit functionality with apple CallKit to ionic capacitor
9
9
  */
@@ -17,6 +17,9 @@ public class CallKitVoipPlugin: CAPPlugin {
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
+ private let serverUrl = "http://192.168.86.115:5000/chat"
21
+ private var chatHubConnection: HubConnection?
22
+ private var chatHubConnectionDelegate: HubConnectionDelegate?
20
23
  @objc func register(_ call: CAPPluginCall) {
21
24
  // config PushKit
22
25
  voipRegistry.delegate = self
@@ -31,11 +34,11 @@ public class CallKitVoipPlugin: CAPPlugin {
31
34
 
32
35
  call.resolve()
33
36
  }
34
-
37
+
35
38
  @objc func incomingCall(_ call: CAPPluginCall) {
36
39
  // TODO
37
40
  }
38
-
41
+
39
42
  public func notifyEvent(eventName: String, uuid: UUID){
40
43
  if let config = connectionIdRegistry[uuid] {
41
44
  notifyListeners(eventName, data: [
@@ -62,7 +65,7 @@ public class CallKitVoipPlugin: CAPPlugin {
62
65
  }
63
66
 
64
67
 
65
-
68
+
66
69
 
67
70
  public func endCall(uuid: UUID) {
68
71
  let controller = CXCallController()
@@ -70,6 +73,20 @@ public class CallKitVoipPlugin: CAPPlugin {
70
73
  CXEndCallAction(call: uuid));controller.request(transaction,completion: { error in })
71
74
  }
72
75
 
76
+ private func openHubConnection(){
77
+ self.chatHubConnectionDelegate = ChatHubConnectionDelegate(controller: self)
78
+ self.chatHubConnection = HubConnectionBuilder(url: URL(string: self.serverUrl)!)
79
+ .withLogging(minLogLevel: .debug)
80
+ .withAutoReconnect()
81
+ .withHubConnectionDelegate(delegate: self.chatHubConnectionDelegate!)
82
+ .build()
83
+
84
+ self.chatHubConnection!.on(method: "BroadcastMessage", callback: {(type: String, message: String) in
85
+ print("type : \(type) and mes : \(message)")
86
+ })
87
+ self.chatHubConnection!.start()
88
+ }
89
+
73
90
  private func openWebSocket() {
74
91
  if let url = URL(string: urlString) {
75
92
  let request = URLRequest(url: url)
@@ -86,15 +103,15 @@ public class CallKitVoipPlugin: CAPPlugin {
86
103
 
87
104
  func closeSocket() {
88
105
  webSocket?.cancel(with: .goingAway, reason: nil)
89
- // opened = false
106
+ // opened = false
90
107
  webSocket = nil
91
108
  }
92
109
  func recieve(){
93
110
  webSocket?.receive(completionHandler: { [weak self] result in
94
111
  switch result {
95
-
112
+
96
113
  case .success(let message):
97
-
114
+
98
115
  switch message {
99
116
  case .string(let str):
100
117
  if str.contains("video closed") {
@@ -123,7 +140,37 @@ public class CallKitVoipPlugin: CAPPlugin {
123
140
  }
124
141
  })
125
142
  }
126
-
143
+
144
+ }
145
+
146
+ func sendMessageToHub(){
147
+ DispatchQueue.global().asyncAfter(deadline: .now()+2){
148
+ self.chatHubConnection?.invoke(method: "sendMessage", ["type":"message","message":"video ended"]) { error in
149
+ if let e = error {
150
+ print(e)
151
+ }
152
+ }
153
+ }
154
+ }
155
+
156
+ fileprivate func connectionDidOpen() {
157
+
158
+ }
159
+
160
+ fileprivate func connectionDidFailToOpen(error: Error) {
161
+
162
+ }
163
+
164
+ fileprivate func connectionDidClose(error: Error?) {
165
+
166
+ }
167
+
168
+ fileprivate func connectionWillReconnect(error: Error?) {
169
+
170
+ }
171
+
172
+ fileprivate func connectionDidReconnect() {
173
+
127
174
  }
128
175
 
129
176
  }
@@ -133,11 +180,11 @@ public class CallKitVoipPlugin: CAPPlugin {
133
180
  @available(iOS 13.0, *)
134
181
  extension CallKitVoipPlugin: URLSessionWebSocketDelegate {
135
182
  public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol protocol: String?) {
136
- // opened = true
183
+ // opened = true
137
184
  print("did connect to server")
138
- self.recieve()
185
+ //self.recieve()
139
186
  }
140
-
187
+
141
188
 
142
189
  public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didCloseWith closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) {
143
190
  self.webSocket = nil
@@ -156,13 +203,13 @@ extension CallKitVoipPlugin: CXProviderDelegate {
156
203
  public func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
157
204
  print("call answered")
158
205
  notifyEvent(eventName: "callAnswered", uuid: action.callUUID)
159
- // endCall(uuid: action.callUUID)
160
- closeSocket()
206
+ // endCall(uuid: action.callUUID)
207
+ //closeSocket()
161
208
  action.fulfill()
162
209
  }
163
210
 
164
211
  public func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
165
- closeSocket()
212
+ //closeSocket()
166
213
  action.fulfill()
167
214
  }
168
215
 
@@ -186,29 +233,26 @@ extension CallKitVoipPlugin: PKPushRegistryDelegate {
186
233
 
187
234
  public func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
188
235
 
189
- // guard let connectionId = payload.dictionaryPayload["ConnectionId"] as? String else {
190
- // return
191
- // }
236
+ // guard let connectionId = payload.dictionaryPayload["ConnectionId"] as? String else {
237
+ // return
238
+ // }
192
239
 
193
- // let username = (payload.dictionaryPayload["Username"] as? String) ?? "Anonymus"
194
-
195
- let backgroundTaskIdentifier =
196
- UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
240
+ // let username = (payload.dictionaryPayload["Username"] as? String) ?? "Anonymus"
241
+
242
+ let backgroundTaskIdentifier =
243
+ UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
197
244
  let uuid = UUID()
198
245
  self.callUUID = uuid
199
- openWebSocket()
200
-
246
+ // openWebSocket()
247
+ openHubConnection()
201
248
  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
- }
249
+
250
+ DispatchQueue.global().asyncAfter(deadline: .now()+20){
251
+ print("timeout func")
252
+
253
+ self.sendMessageToHub()
254
+ UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
255
+ }
212
256
  }
213
257
 
214
258
  }
@@ -221,3 +265,32 @@ extension CallKitVoipPlugin {
221
265
  let username : String
222
266
  }
223
267
  }
268
+ @available(iOS 13.0, *)
269
+ class ChatHubConnectionDelegate: HubConnectionDelegate {
270
+
271
+ weak var controller: CallKitVoipPlugin?
272
+
273
+ init(controller: CallKitVoipPlugin) {
274
+ self.controller = controller
275
+ }
276
+
277
+ func connectionDidOpen(hubConnection: HubConnection) {
278
+ controller?.connectionDidOpen()
279
+ }
280
+
281
+ func connectionDidFailToOpen(error: Error) {
282
+ controller?.connectionDidFailToOpen(error: error)
283
+ }
284
+
285
+ func connectionDidClose(error: Error?) {
286
+ controller?.connectionDidClose(error: error)
287
+ }
288
+
289
+ func connectionWillReconnect(error: Error) {
290
+ controller?.connectionWillReconnect(error: error)
291
+ }
292
+
293
+ func connectionDidReconnect() {
294
+ controller?.connectionDidReconnect()
295
+ }
296
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "voip-callkit",
3
- "version": "0.0.7",
3
+ "version": "0.0.8",
4
4
  "description": "capacitor plugin for callkit and voip",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",