voip-callkit 0.0.5 → 0.0.6

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.
@@ -7,14 +7,15 @@ import PushKit
7
7
  /**
8
8
  * CallKit Voip Plugin provides native PushKit functionality with apple CallKit to ionic capacitor
9
9
  */
10
+ @available(iOS 13.0, *)
10
11
  @objc(CallKitVoipPlugin)
11
12
  public class CallKitVoipPlugin: CAPPlugin {
12
13
 
13
14
  private var provider: CXProvider?
14
15
  private let voipRegistry = PKPushRegistry(queue: nil)
15
16
  private var connectionIdRegistry : [UUID: CallConfig] = [:]
16
-
17
-
17
+ private var urlString = "wss://demo.piesocket.com/v3/channel_1?api_key=VCXCEuvhGcBDP7XhiJJUDvR1e1D3eiVjgZ9VRiaV&notify_self"
18
+ var webSocket: URLSessionWebSocketTask?
18
19
 
19
20
  @objc func register(_ call: CAPPluginCall) {
20
21
  // config PushKit
@@ -69,11 +70,74 @@ public class CallKitVoipPlugin: CAPPlugin {
69
70
  CXEndCallAction(call: uuid));controller.request(transaction,completion: { error in })
70
71
  }
71
72
 
73
+ private func openWebSocket() {
74
+ if let url = URL(string: urlString) {
75
+ let request = URLRequest(url: url)
76
+ let session = URLSession(configuration: .default, delegate: self, delegateQueue: nil)
77
+ let webSocket = session.webSocketTask(with: request)
78
+ self.webSocket = webSocket
79
+ //self.opened = true
80
+ self.webSocket?.resume()
81
+ } else {
82
+ webSocket = nil
83
+ }
84
+ }
85
+
86
+ func closeSocket() {
87
+ webSocket?.cancel(with: .goingAway, reason: nil)
88
+ // opened = false
89
+ webSocket = nil
90
+ }
91
+ func recieve(){
92
+ webSocket?.receive(completionHandler: { [weak self] result in
93
+ switch result {
94
+
95
+ case .success(let message):
96
+ switch message {
97
+ case .string(let str):
98
+ print("got message str \(str)")
99
+ case .data(let data):
100
+ print("got message data \(data)")
101
+ default:
102
+ break
103
+ }
104
+ case .failure(let error):
105
+ print("failed reason \(error)")
106
+ }
107
+ self?.recieve()
108
+ })
109
+ }
110
+ func send(){
111
+ DispatchQueue.global().asyncAfter(deadline: .now()+10){
112
+ self.webSocket?.send(.string("video closed:\("user declined")"), completionHandler: { error in
113
+ if let error = error {
114
+ print("error sending message \(error)")
115
+ }
116
+ })
117
+ }
118
+
119
+ }
120
+
72
121
  }
73
122
 
74
123
 
75
- // MARK: CallKit events handler
76
124
 
125
+ @available(iOS 13.0, *)
126
+ extension CallKitVoipPlugin: URLSessionWebSocketDelegate {
127
+ public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didOpenWithProtocol protocol: String?) {
128
+ // opened = true
129
+ print("did connect to server")
130
+ }
131
+
132
+
133
+ public func urlSession(_ session: URLSession, webSocketTask: URLSessionWebSocketTask, didCloseWith closeCode: URLSessionWebSocketTask.CloseCode, reason: Data?) {
134
+ self.webSocket = nil
135
+ //self.opened = false
136
+ print(" did close connection")
137
+ }
138
+ }
139
+ // MARK: CallKit events handler
140
+ @available(iOS 13.0, *)
77
141
  extension CallKitVoipPlugin: CXProviderDelegate {
78
142
 
79
143
  public func providerDidReset(_ provider: CXProvider) {
@@ -84,20 +148,25 @@ extension CallKitVoipPlugin: CXProviderDelegate {
84
148
  print("call answered")
85
149
  notifyEvent(eventName: "callAnswered", uuid: action.callUUID)
86
150
  // endCall(uuid: action.callUUID)
151
+ closeSocket()
87
152
  action.fulfill()
88
153
  }
89
154
 
90
155
  public func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
156
+ closeSocket()
91
157
  action.fulfill()
92
158
  }
93
159
 
94
160
  public func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
95
161
  notifyEvent(eventName: "callStarted", uuid: action.callUUID)
162
+ openWebSocket()
163
+ send()
96
164
  action.fulfill()
97
165
  }
98
166
  }
99
167
 
100
168
  // MARK: PushKit events handler
169
+ @available(iOS 13.0, *)
101
170
  extension CallKitVoipPlugin: PKPushRegistryDelegate {
102
171
 
103
172
  public func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
@@ -121,6 +190,7 @@ extension CallKitVoipPlugin: PKPushRegistryDelegate {
121
190
  }
122
191
 
123
192
 
193
+ @available(iOS 13.0, *)
124
194
  extension CallKitVoipPlugin {
125
195
  struct CallConfig {
126
196
  let connectionId: String
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "voip-callkit",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "capacitor plugin for callkit and voip",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",