voip-callkit 0.0.6 → 0.0.9
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.
- package/VoipCallkit.podspec +1 -0
- package/ios/Plugin/CallKitVoipPlugin.swift +120 -23
- package/package.json +1 -1
package/VoipCallkit.podspec
CHANGED
@@ -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
|
*/
|
@@ -16,7 +16,10 @@ 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¬ify_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: [
|
@@ -46,7 +49,7 @@ public class CallKitVoipPlugin: CAPPlugin {
|
|
46
49
|
}
|
47
50
|
}
|
48
51
|
|
49
|
-
public func incommingCall(from: String, connectionId: String) {
|
52
|
+
public func incommingCall(from: String, connectionId: String,uuid:UUID) {
|
50
53
|
let update = CXCallUpdate()
|
51
54
|
update.remoteHandle = CXHandle(type: .generic, value: from)
|
52
55
|
update.hasVideo = true
|
@@ -56,13 +59,13 @@ public class CallKitVoipPlugin: CAPPlugin {
|
|
56
59
|
update.supportsUngrouping = false
|
57
60
|
update.hasVideo = true
|
58
61
|
|
59
|
-
let uuid = UUID()
|
62
|
+
//let uuid = UUID()
|
60
63
|
connectionIdRegistry[uuid] = .init(connectionId: connectionId, username: from)
|
61
64
|
self.provider?.reportNewIncomingCall(with: uuid, update: update, completion: { (_) in })
|
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)
|
@@ -77,6 +94,7 @@ public class CallKitVoipPlugin: CAPPlugin {
|
|
77
94
|
let webSocket = session.webSocketTask(with: request)
|
78
95
|
self.webSocket = webSocket
|
79
96
|
//self.opened = true
|
97
|
+
print("open web socket called")
|
80
98
|
self.webSocket?.resume()
|
81
99
|
} else {
|
82
100
|
webSocket = nil
|
@@ -85,16 +103,23 @@ public class CallKitVoipPlugin: CAPPlugin {
|
|
85
103
|
|
86
104
|
func closeSocket() {
|
87
105
|
webSocket?.cancel(with: .goingAway, reason: nil)
|
88
|
-
|
106
|
+
// opened = false
|
89
107
|
webSocket = nil
|
90
108
|
}
|
91
109
|
func recieve(){
|
92
110
|
webSocket?.receive(completionHandler: { [weak self] result in
|
93
111
|
switch result {
|
94
|
-
|
112
|
+
|
95
113
|
case .success(let message):
|
114
|
+
|
96
115
|
switch message {
|
97
116
|
case .string(let str):
|
117
|
+
if str.contains("video closed") {
|
118
|
+
if let uuid = self?.callUUID{
|
119
|
+
print("timeout func1")
|
120
|
+
self?.endCall(uuid:uuid)
|
121
|
+
}
|
122
|
+
}
|
98
123
|
print("got message str \(str)")
|
99
124
|
case .data(let data):
|
100
125
|
print("got message data \(data)")
|
@@ -108,14 +133,44 @@ public class CallKitVoipPlugin: CAPPlugin {
|
|
108
133
|
})
|
109
134
|
}
|
110
135
|
func send(){
|
111
|
-
DispatchQueue.global().asyncAfter(deadline: .now()+
|
136
|
+
DispatchQueue.global().asyncAfter(deadline: .now()+2){
|
112
137
|
self.webSocket?.send(.string("video closed:\("user declined")"), completionHandler: { error in
|
113
138
|
if let error = error {
|
114
139
|
print("error sending message \(error)")
|
115
140
|
}
|
116
141
|
})
|
117
142
|
}
|
118
|
-
|
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
|
+
|
119
174
|
}
|
120
175
|
|
121
176
|
}
|
@@ -125,10 +180,11 @@ public class CallKitVoipPlugin: CAPPlugin {
|
|
125
180
|
@available(iOS 13.0, *)
|
126
181
|
extension CallKitVoipPlugin: URLSessionWebSocketDelegate {
|
127
182
|
public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol protocol: String?) {
|
128
|
-
|
183
|
+
// opened = true
|
129
184
|
print("did connect to server")
|
185
|
+
//self.recieve()
|
130
186
|
}
|
131
|
-
|
187
|
+
|
132
188
|
|
133
189
|
public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didCloseWith closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) {
|
134
190
|
self.webSocket = nil
|
@@ -147,20 +203,20 @@ extension CallKitVoipPlugin: CXProviderDelegate {
|
|
147
203
|
public func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
|
148
204
|
print("call answered")
|
149
205
|
notifyEvent(eventName: "callAnswered", uuid: action.callUUID)
|
150
|
-
// endCall(uuid: action.callUUID)
|
151
|
-
closeSocket()
|
206
|
+
// endCall(uuid: action.callUUID)
|
207
|
+
//closeSocket()
|
152
208
|
action.fulfill()
|
153
209
|
}
|
154
210
|
|
155
211
|
public func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
|
156
|
-
closeSocket()
|
212
|
+
//closeSocket()
|
157
213
|
action.fulfill()
|
158
214
|
}
|
159
215
|
|
160
216
|
public func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
|
161
217
|
notifyEvent(eventName: "callStarted", uuid: action.callUUID)
|
162
|
-
|
163
|
-
send()
|
218
|
+
callUUID = action.callUUID
|
219
|
+
//send()
|
164
220
|
action.fulfill()
|
165
221
|
}
|
166
222
|
}
|
@@ -177,14 +233,26 @@ extension CallKitVoipPlugin: PKPushRegistryDelegate {
|
|
177
233
|
|
178
234
|
public func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
|
179
235
|
|
180
|
-
// guard let connectionId = payload.dictionaryPayload["ConnectionId"] as? String else {
|
181
|
-
// return
|
182
|
-
// }
|
236
|
+
// guard let connectionId = payload.dictionaryPayload["ConnectionId"] as? String else {
|
237
|
+
// return
|
238
|
+
// }
|
183
239
|
|
184
|
-
|
240
|
+
// let username = (payload.dictionaryPayload["Username"] as? String) ?? "Anonymus"
|
185
241
|
|
242
|
+
let backgroundTaskIdentifier =
|
243
|
+
UIApplication.shared.beginBackgroundTask(expirationHandler: nil)
|
244
|
+
let uuid = UUID()
|
245
|
+
self.callUUID = uuid
|
246
|
+
// openWebSocket()
|
247
|
+
openHubConnection()
|
248
|
+
self.incommingCall(from: "username", connectionId: "123",uuid:uuid)
|
186
249
|
|
187
|
-
|
250
|
+
DispatchQueue.global().asyncAfter(deadline: .now()+20){
|
251
|
+
print("timeout func")
|
252
|
+
|
253
|
+
self.sendMessageToHub()
|
254
|
+
UIApplication.shared.endBackgroundTask(backgroundTaskIdentifier)
|
255
|
+
}
|
188
256
|
}
|
189
257
|
|
190
258
|
}
|
@@ -197,3 +265,32 @@ extension CallKitVoipPlugin {
|
|
197
265
|
let username : String
|
198
266
|
}
|
199
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
|
+
}
|