omikit-plugin 0.3.1 → 1.0.1
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/README.md +204 -58
- package/android/build.gradle +9 -14
- package/android/src/main/java/com/omikitplugin/OmikitPluginModule.kt +143 -96
- package/android/src/main/java/com/omikitplugin/constants/constant.kt +7 -18
- package/ios/CallProcess/CallManager.swift +81 -138
- package/ios/Constant/Constant.swift +7 -18
- package/ios/OmikitPlugin.m +10 -4
- package/ios/OmikitPlugin.swift +51 -18
- package/lib/commonjs/index.js +19 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/index.js +15 -2
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/index.d.ts +10 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.tsx +18 -2
- package/ios/CallProcess/NSUserActivity.swift +0 -58
- package/ios/CallProcess/StringUtils.swift +0 -18
|
@@ -1,46 +1,160 @@
|
|
|
1
1
|
package com.omikitplugin
|
|
2
2
|
|
|
3
3
|
import android.Manifest
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.hardware.camera2.CameraManager
|
|
6
|
+
import android.os.Build
|
|
7
|
+
import android.util.Log
|
|
4
8
|
import androidx.core.app.ActivityCompat
|
|
5
9
|
import com.facebook.react.ReactActivity
|
|
6
10
|
import com.facebook.react.bridge.*
|
|
7
11
|
import com.facebook.react.modules.core.RCTNativeAppEventEmitter
|
|
12
|
+
import com.omikitplugin.constants.*
|
|
8
13
|
import vn.vihat.omicall.omisdk.OmiClient
|
|
9
14
|
import vn.vihat.omicall.omisdk.OmiListener
|
|
10
|
-
import vn.vihat.omicall.omisdk.OmiSDKUtils
|
|
15
|
+
import vn.vihat.omicall.omisdk.utils.OmiSDKUtils
|
|
11
16
|
|
|
12
17
|
|
|
13
18
|
class OmikitPluginModule(reactContext: ReactApplicationContext?) :
|
|
14
|
-
ReactContextBaseJavaModule(reactContext)
|
|
19
|
+
ReactContextBaseJavaModule(reactContext) {
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
private var icSpeaker = false
|
|
23
|
+
private var isMute = false
|
|
24
|
+
|
|
25
|
+
private val callListener = object : OmiListener {
|
|
26
|
+
|
|
27
|
+
override fun incomingReceived(callerId: Int, phoneNumber: String?, isVideo: Boolean?) {
|
|
28
|
+
val map: WritableMap = WritableNativeMap()
|
|
29
|
+
map.putBoolean("isVideo", isVideo ?: true)
|
|
30
|
+
map.putString("callerNumber", phoneNumber)
|
|
31
|
+
sendEvent(INCOMING_RECEIVED, map)
|
|
32
|
+
Log.d("omikit", "incomingReceived: ")
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun onCallEnd() {
|
|
36
|
+
sendEvent(CALL_END, null)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override fun onCallEstablished(
|
|
40
|
+
callerId: Int,
|
|
41
|
+
phoneNumber: String?,
|
|
42
|
+
isVideo: Boolean?,
|
|
43
|
+
startTime: Long,
|
|
44
|
+
) {
|
|
45
|
+
val map: WritableMap = WritableNativeMap()
|
|
46
|
+
val sipNumber = OmiClient.instance.callUUID
|
|
47
|
+
map.putString("callerNumber", sipNumber)
|
|
48
|
+
map.putBoolean("isVideo", isVideo ?: true)
|
|
49
|
+
sendEvent(CALL_ESTABLISHED, map)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
override fun onConnectionTimeout() {
|
|
53
|
+
// sendEvent("onConnectionTimeout", null)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
override fun onHold(isHold: Boolean) {
|
|
57
|
+
val map: WritableMap = WritableNativeMap()
|
|
58
|
+
map.putBoolean("isHold", isHold)
|
|
59
|
+
sendEvent(HOLD, map)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
override fun onMuted(isMuted: Boolean) {
|
|
63
|
+
// val map: WritableMap = WritableNativeMap()
|
|
64
|
+
// map.putBoolean("isMuted", isMuted)
|
|
65
|
+
// sendEvent(MUTED, map)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
override fun onOutgoingStarted(callerId: Int, phoneNumber: String?, isVideo: Boolean?) {
|
|
69
|
+
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
override fun onRinging() {
|
|
73
|
+
// sendEvent("onRinging", null)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
override fun onVideoSize(width: Int, height: Int) {
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
}
|
|
15
80
|
|
|
16
81
|
override fun getName(): String {
|
|
17
82
|
return NAME
|
|
18
83
|
}
|
|
19
84
|
|
|
85
|
+
override fun initialize() {
|
|
86
|
+
super.initialize()
|
|
87
|
+
OmiClient(reactApplicationContext!!)
|
|
88
|
+
OmiClient.instance.setListener(callListener)
|
|
89
|
+
}
|
|
90
|
+
|
|
20
91
|
@ReactMethod
|
|
21
92
|
fun initCall(data: ReadableMap, promise: Promise) {
|
|
22
93
|
currentActivity?.runOnUiThread {
|
|
23
|
-
val userName = data.getString("userName")
|
|
24
|
-
val password = data.getString("password")
|
|
25
|
-
val realm = data.getString("realm")
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
94
|
+
val userName = data.getString("userName")
|
|
95
|
+
val password = data.getString("password")
|
|
96
|
+
val realm = data.getString("realm")
|
|
97
|
+
val host = data.getString("host")
|
|
98
|
+
val isVideo = data.getBoolean("isVideo")
|
|
99
|
+
if (userName != null && password != null && realm != null && host != null) {
|
|
100
|
+
OmiClient.register(
|
|
101
|
+
reactApplicationContext!!,
|
|
102
|
+
userName,
|
|
103
|
+
password,
|
|
104
|
+
isVideo,
|
|
105
|
+
realm,
|
|
106
|
+
host = host,
|
|
107
|
+
customUI = true,
|
|
108
|
+
isTcp = true
|
|
109
|
+
)
|
|
110
|
+
}
|
|
111
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
112
|
+
ActivityCompat.requestPermissions(
|
|
113
|
+
currentActivity!!,
|
|
114
|
+
arrayOf(
|
|
115
|
+
Manifest.permission.USE_SIP,
|
|
116
|
+
Manifest.permission.CALL_PHONE,
|
|
117
|
+
Manifest.permission.CAMERA,
|
|
118
|
+
Manifest.permission.MODIFY_AUDIO_SETTINGS,
|
|
119
|
+
Manifest.permission.RECORD_AUDIO,
|
|
120
|
+
Manifest.permission.POST_NOTIFICATIONS,
|
|
121
|
+
),
|
|
122
|
+
0,
|
|
123
|
+
)
|
|
124
|
+
} else {
|
|
125
|
+
ActivityCompat.requestPermissions(
|
|
126
|
+
currentActivity!!,
|
|
127
|
+
arrayOf(
|
|
128
|
+
Manifest.permission.USE_SIP,
|
|
129
|
+
Manifest.permission.CALL_PHONE,
|
|
130
|
+
Manifest.permission.CAMERA,
|
|
131
|
+
Manifest.permission.MODIFY_AUDIO_SETTINGS,
|
|
132
|
+
Manifest.permission.RECORD_AUDIO,
|
|
133
|
+
),
|
|
134
|
+
0,
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
if (isVideo) {
|
|
138
|
+
val cm = currentActivity!!.getSystemService(Context.CAMERA_SERVICE) as CameraManager
|
|
139
|
+
OmiClient.instance.setCameraManager(cm)
|
|
140
|
+
}
|
|
40
141
|
promise.resolve(true)
|
|
41
142
|
}
|
|
42
143
|
}
|
|
43
144
|
|
|
145
|
+
@ReactMethod
|
|
146
|
+
fun getInitialCall(promise: Promise) {
|
|
147
|
+
currentActivity?.runOnUiThread {
|
|
148
|
+
promise.resolve(false)
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@ReactMethod
|
|
153
|
+
fun joinCall(promise: Promise) {
|
|
154
|
+
OmiClient.instance.pickUp(true)
|
|
155
|
+
promise.resolve(true)
|
|
156
|
+
}
|
|
157
|
+
|
|
44
158
|
@ReactMethod
|
|
45
159
|
fun updateToken(data: ReadableMap, promise: Promise) {
|
|
46
160
|
currentActivity?.runOnUiThread {
|
|
@@ -51,21 +165,18 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
|
|
|
51
165
|
"",
|
|
52
166
|
deviceTokenAndroid,
|
|
53
167
|
deviceId,
|
|
54
|
-
appId
|
|
168
|
+
appId,
|
|
55
169
|
)
|
|
56
170
|
promise.resolve(true)
|
|
57
171
|
}
|
|
58
172
|
}
|
|
59
173
|
|
|
60
|
-
|
|
61
174
|
@ReactMethod
|
|
62
175
|
fun startCall(data: ReadableMap, promise: Promise) {
|
|
63
176
|
val phoneNumber = data.getString("phoneNumber") as String
|
|
64
177
|
val isVideo = data.getBoolean("isVideo")
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
promise.resolve(true)
|
|
68
|
-
}
|
|
178
|
+
OmiClient.instance.startCall(phoneNumber, isVideo)
|
|
179
|
+
promise.resolve(true)
|
|
69
180
|
}
|
|
70
181
|
|
|
71
182
|
@ReactMethod
|
|
@@ -78,48 +189,16 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
|
|
|
78
189
|
fun toggleMute(promise: Promise) {
|
|
79
190
|
OmiClient.instance.toggleMute()
|
|
80
191
|
promise.resolve(true)
|
|
192
|
+
isMute = !isMute
|
|
193
|
+
sendEvent(MUTED, isMute)
|
|
81
194
|
}
|
|
82
195
|
|
|
83
196
|
@ReactMethod
|
|
84
|
-
fun toggleSpeak(
|
|
85
|
-
|
|
86
|
-
OmiClient.instance.toggleSpeaker(
|
|
87
|
-
promise.resolve(true)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
@ReactMethod
|
|
91
|
-
fun decline(promise: Promise) {
|
|
92
|
-
OmiClient.instance.decline()
|
|
93
|
-
promise.resolve(true)
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
@ReactMethod
|
|
97
|
-
fun hangup(data: ReadableMap, promise: Promise) {
|
|
98
|
-
val callId = data.getInt("callId")
|
|
99
|
-
OmiClient.instance.hangUp(callId)
|
|
100
|
-
promise.resolve(true)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
@ReactMethod
|
|
105
|
-
fun onCallStart(data: ReadableMap, promise: Promise) {
|
|
106
|
-
val callId = data.getInt("callId")
|
|
107
|
-
OmiClient.instance.onCallStarted(callId)
|
|
108
|
-
promise.resolve(true)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
@ReactMethod
|
|
112
|
-
fun onHold(data: ReadableMap, promise: Promise) {
|
|
113
|
-
val isHold = data.getBoolean("isHold")
|
|
114
|
-
OmiClient.instance.onHold(isHold)
|
|
115
|
-
promise.resolve(true)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
@ReactMethod
|
|
119
|
-
fun onMute(data: ReadableMap, promise: Promise) {
|
|
120
|
-
val isMute = data.getBoolean("isMute")
|
|
121
|
-
OmiClient.instance.onMuted(isMute)
|
|
197
|
+
fun toggleSpeak(promise: Promise) {
|
|
198
|
+
icSpeaker = !icSpeaker
|
|
199
|
+
OmiClient.instance.toggleSpeaker(icSpeaker)
|
|
122
200
|
promise.resolve(true)
|
|
201
|
+
sendEvent(SPEAKER, icSpeaker)
|
|
123
202
|
}
|
|
124
203
|
|
|
125
204
|
@ReactMethod
|
|
@@ -141,7 +220,7 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
|
|
|
141
220
|
companion object {
|
|
142
221
|
const val NAME = "OmikitPlugin"
|
|
143
222
|
fun onDestroy() {
|
|
144
|
-
|
|
223
|
+
|
|
145
224
|
}
|
|
146
225
|
|
|
147
226
|
fun onRequestPermissionsResult(
|
|
@@ -156,38 +235,6 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
|
|
|
156
235
|
}
|
|
157
236
|
}
|
|
158
237
|
|
|
159
|
-
override fun incomingReceived(callerId: Int, phoneNumber: String?) {
|
|
160
|
-
val map: WritableMap = WritableNativeMap()
|
|
161
|
-
map.putInt("callerId", callerId)
|
|
162
|
-
sendEvent("phoneNumber", phoneNumber)
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
override fun onCallEnd() {
|
|
166
|
-
sendEvent("onCallEnd", false)
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
override fun onCallEstablished() {
|
|
170
|
-
sendEvent("onCallEstablished", null)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
override fun onConnectionTimeout() {
|
|
174
|
-
sendEvent("onConnectionTimeout", null)
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
override fun onHold(isHold: Boolean) {
|
|
178
|
-
sendEvent("onHold", null)
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
override fun onMuted(isMuted: Boolean) {
|
|
182
|
-
val map: WritableMap = WritableNativeMap()
|
|
183
|
-
map.putBoolean("isMuted", isMuted)
|
|
184
|
-
sendEvent("onMuted", map)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
override fun onRinging() {
|
|
188
|
-
sendEvent("onRinging", null)
|
|
189
|
-
}
|
|
190
|
-
|
|
191
238
|
private fun sendEvent(eventName: String?, params: Any?) {
|
|
192
239
|
currentActivity?.runOnUiThread {
|
|
193
240
|
reactApplicationContext.getJSModule(RCTNativeAppEventEmitter::class.java)
|
|
@@ -3,29 +3,18 @@ package com.omikitplugin.constants
|
|
|
3
3
|
//EVENT
|
|
4
4
|
const val INIT_CALL = "INIT_CALL";
|
|
5
5
|
const val UPDATE_TOKEN = "UPDATE_TOKEN";
|
|
6
|
-
const val START_OMI_SERVICE = "START_OMI_SERVICE";
|
|
7
6
|
const val START_CALL = "START_CALL";
|
|
8
7
|
const val END_CALL = "END_CALL";
|
|
9
8
|
const val TOGGLE_MUTE = "TOGGLE_MUTE";
|
|
10
9
|
const val TOGGLE_SPEAK = "TOGGLE_SPEAK";
|
|
11
|
-
const val CHECK_ON_GOING_CALL = "CHECK_ON_GOING_CALL";
|
|
12
|
-
const val DECLINE = "DECLINE";
|
|
13
|
-
const val FORWARD_CALL_TO = "FORWARD_CALL_TO";
|
|
14
|
-
const val HANGUP = "HANGUP";
|
|
15
|
-
const val ON_CALL_STARTED = "ON_CALL_STARTED";
|
|
16
|
-
const val ON_HOLD = "ON_HOLD";
|
|
17
|
-
const val ON_IN_COMING_RECEIVE = "ON_IN_COMING_RECEIVE";
|
|
18
|
-
const val ON_MUTE = "ON_MUTE";
|
|
19
|
-
const val ON_OUT_GOING = "ON_OUT_GOING";
|
|
20
10
|
const val REGISTER = "REGISTER";
|
|
21
11
|
const val SEND_DTMF = "SEND_DTMF";
|
|
22
12
|
|
|
23
13
|
//LISTENER
|
|
24
|
-
const val
|
|
25
|
-
const val
|
|
26
|
-
const val
|
|
27
|
-
const val
|
|
28
|
-
const val
|
|
29
|
-
const val
|
|
30
|
-
const val
|
|
31
|
-
|
|
14
|
+
const val CALL_ESTABLISHED = "CALL_ESTABLISHED"
|
|
15
|
+
const val CALL_END = "CALL_END"
|
|
16
|
+
const val INCOMING_RECEIVED = "INCOMING_RECEIVED"
|
|
17
|
+
//const val CONNECTION_TIMEOUT = "CONNECTION_TIMEOUT"
|
|
18
|
+
const val HOLD = "HOLD"
|
|
19
|
+
const val MUTED = "MUTED"
|
|
20
|
+
const val SPEAKER = "SPEAKER"
|
|
@@ -15,15 +15,10 @@ import AVFoundation
|
|
|
15
15
|
class CallManager {
|
|
16
16
|
|
|
17
17
|
static private var instance: CallManager? = nil // Instance
|
|
18
|
-
var call: OMICall? // Call
|
|
19
|
-
private var numberRetry: Int = 0
|
|
20
|
-
var isCallError: Bool = false // check when call error
|
|
21
18
|
private let omiLib = OMISIPLib.sharedInstance()
|
|
22
|
-
|
|
23
|
-
var currentConfirmedCall : OMICall?
|
|
19
|
+
var isSpeaker = false
|
|
24
20
|
var videoManager: OMIVideoViewManager?
|
|
25
21
|
|
|
26
|
-
|
|
27
22
|
/// Get instance
|
|
28
23
|
static func shareInstance() -> CallManager {
|
|
29
24
|
if (instance == nil) {
|
|
@@ -32,6 +27,14 @@ class CallManager {
|
|
|
32
27
|
return instance!
|
|
33
28
|
}
|
|
34
29
|
|
|
30
|
+
func getAvailableCall() -> OMICall? {
|
|
31
|
+
var currentCall = omiLib.getCurrentConfirmCall()
|
|
32
|
+
if (currentCall == nil) {
|
|
33
|
+
currentCall = omiLib.getNewestCall()
|
|
34
|
+
}
|
|
35
|
+
return currentCall
|
|
36
|
+
}
|
|
37
|
+
|
|
35
38
|
func updateToken(params: [String: Any]) {
|
|
36
39
|
if let apnsToken = params["apnsToken"] as? String {
|
|
37
40
|
OmiClient.setUserPushNotificationToken(apnsToken)
|
|
@@ -39,19 +42,14 @@ class CallManager {
|
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
func initEndpoint(params: [String: Any]){
|
|
42
|
-
var isSupportVideoCall = false
|
|
43
45
|
if let userName = params["userName"] as? String, let password = params["password"] as? String, let realm = params["realm"] as? String {
|
|
44
46
|
OmiClient.initWithUsername(userName, password: password, realm: realm)
|
|
45
|
-
if let isVideoCall = params["isVideo"] as? Bool {
|
|
46
|
-
isSupportVideoCall = isVideoCall
|
|
47
|
-
}
|
|
48
|
-
OmiClient.startOmiService(isSupportVideoCall)
|
|
49
|
-
if (isSupportVideoCall) {
|
|
50
|
-
OmiClient.registerAccount()
|
|
51
|
-
videoManager = OMIVideoViewManager.init()
|
|
52
|
-
}
|
|
53
|
-
registerNotificationCenter()
|
|
54
47
|
}
|
|
48
|
+
if let isVideoCall = params["isVideo"] as? Bool, isVideoCall == true {
|
|
49
|
+
OmiClient.startOmiService(true)
|
|
50
|
+
videoManager = OMIVideoViewManager.init()
|
|
51
|
+
}
|
|
52
|
+
registerNotificationCenter()
|
|
55
53
|
}
|
|
56
54
|
|
|
57
55
|
func registerNotificationCenter() {
|
|
@@ -70,7 +68,7 @@ class CallManager {
|
|
|
70
68
|
)
|
|
71
69
|
}
|
|
72
70
|
}
|
|
73
|
-
|
|
71
|
+
|
|
74
72
|
@objc func callDealloc(_ notification: NSNotification) {
|
|
75
73
|
guard let userInfo = notification.userInfo,
|
|
76
74
|
let call = userInfo[OMINotificationUserInfoCallKey] as? OMICall else {
|
|
@@ -79,7 +77,6 @@ class CallManager {
|
|
|
79
77
|
if (call.callState == .disconnected) {
|
|
80
78
|
DispatchQueue.main.async {
|
|
81
79
|
OmikitPlugin.instance.sendEvent(withName: onCallEnd, body: [:])
|
|
82
|
-
self.currentConfirmedCall = nil
|
|
83
80
|
}
|
|
84
81
|
}
|
|
85
82
|
}
|
|
@@ -95,7 +92,6 @@ class CallManager {
|
|
|
95
92
|
case .calling:
|
|
96
93
|
if (!call.isIncoming) {
|
|
97
94
|
NSLog("Outgoing call, in CALLING state, with UUID \(call.uuid)")
|
|
98
|
-
OmikitPlugin.instance.sendEvent(withName: onRinging, body: [:])
|
|
99
95
|
}
|
|
100
96
|
break
|
|
101
97
|
case .early:
|
|
@@ -109,19 +105,10 @@ class CallManager {
|
|
|
109
105
|
}
|
|
110
106
|
break
|
|
111
107
|
case .confirmed:
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
OmikitPlugin.instance.sendEvent(withName: onMuted, body: ["isMuted": call.muted])
|
|
117
|
-
self.currentConfirmedCall = call
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
NSLog("Outgoing call, in CONFIRMED state, with UUID: \(call.uuid)")
|
|
121
|
-
OmikitPlugin.instance.sendEvent(withName: onCallEstablished, body: [:])
|
|
122
|
-
OmikitPlugin.instance.sendEvent(withName: onMuted, body: ["isMuted": call.muted])
|
|
123
|
-
self.currentConfirmedCall = call
|
|
124
|
-
}
|
|
108
|
+
NSLog("Outgoing call, in CONFIRMED state, with UUID: \(call.uuid)")
|
|
109
|
+
OmikitPlugin.instance.sendEvent(withName: onCallEstablished, body: ["isVideo": call.isVideo, "callerNumber": call.callerNumber])
|
|
110
|
+
print(call.muted)
|
|
111
|
+
OmikitPlugin.instance.sendOnMuteStatus()
|
|
125
112
|
break
|
|
126
113
|
case .disconnected:
|
|
127
114
|
if (!call.connected) {
|
|
@@ -129,36 +116,26 @@ class CallManager {
|
|
|
129
116
|
} else if (!call.userDidHangUp) {
|
|
130
117
|
NSLog("Call remotly ended, in DISCONNECTED state, with UUID: \(call.uuid)")
|
|
131
118
|
}
|
|
132
|
-
print(omiLib.getCurrentCall()?.uuid.uuidString)
|
|
133
119
|
print(call.uuid.uuidString)
|
|
134
|
-
|
|
135
|
-
OmikitPlugin.instance.sendEvent(withName: onCallEnd, body: [:])
|
|
136
|
-
currentConfirmedCall = nil
|
|
137
|
-
break
|
|
138
|
-
}
|
|
139
|
-
if currentConfirmedCall == nil {
|
|
140
|
-
OmikitPlugin.instance.sendEvent(withName: onCallEnd, body: [:])
|
|
141
|
-
break
|
|
142
|
-
}
|
|
143
|
-
print(omiLib.getNewestCall()?.uuid.uuidString)
|
|
120
|
+
OmikitPlugin.instance.sendEvent(withName: onCallEnd, body: [:])
|
|
144
121
|
break
|
|
145
122
|
case .incoming:
|
|
146
|
-
OmikitPlugin.instance.sendEvent(withName: incomingReceived, body: ["
|
|
123
|
+
OmikitPlugin.instance.sendEvent(withName: incomingReceived, body: ["isVideo": call.isVideo, "callerNumber": call.callerNumber ?? ""])
|
|
147
124
|
break
|
|
148
125
|
case .muted:
|
|
149
|
-
|
|
126
|
+
print("muteddddddd")
|
|
150
127
|
break
|
|
151
128
|
case .hold:
|
|
152
|
-
|
|
129
|
+
print("holdddddddd")
|
|
153
130
|
break
|
|
154
|
-
|
|
131
|
+
default:
|
|
155
132
|
NSLog("Default call state")
|
|
133
|
+
break
|
|
156
134
|
}
|
|
157
135
|
}
|
|
158
136
|
|
|
159
137
|
/// Start call
|
|
160
138
|
func startCall(_ phoneNumber: String, isVideo: Bool) {
|
|
161
|
-
registerNotificationCenter()
|
|
162
139
|
if (isVideo) {
|
|
163
140
|
OmiClient.startVideoCall(phoneNumber)
|
|
164
141
|
return
|
|
@@ -166,82 +143,49 @@ class CallManager {
|
|
|
166
143
|
OmiClient.startCall(phoneNumber)
|
|
167
144
|
}
|
|
168
145
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
146
|
+
func endAvailableCall() {
|
|
147
|
+
guard let call = getAvailableCall() else {
|
|
148
|
+
OmikitPlugin.instance.sendEvent(withName: onCallEnd, body: [:])
|
|
172
149
|
return
|
|
173
150
|
}
|
|
174
|
-
omiLib.callManager.end(call)
|
|
175
|
-
if error != nil {
|
|
176
|
-
NSLog("error hanging up call(\(call.uuid.uuidString)): \(error!)")
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
OmikitPlugin.instance.sendEvent(withName: onCallEnd, body: [:])
|
|
180
|
-
NotificationCenter.default.removeObserver(self)
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
func endCurrentConfirmCall() {
|
|
184
|
-
guard let call = omiLib.getCurrentCall() else {
|
|
185
|
-
endNewestCall()
|
|
186
|
-
return
|
|
187
|
-
}
|
|
188
|
-
omiLib.callManager.end(call) { error in
|
|
189
|
-
if error != nil {
|
|
190
|
-
NSLog("error hanging up call(\(call.uuid.uuidString)): \(error!)")
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
OmikitPlugin.instance.sendEvent(withName: onCallEnd, body: [:])
|
|
194
|
-
NotificationCenter.default.removeObserver(self)
|
|
151
|
+
omiLib.callManager.end(call)
|
|
195
152
|
}
|
|
196
153
|
|
|
197
154
|
|
|
198
155
|
func endAllCalls() {
|
|
199
156
|
omiLib.callManager.endAllCalls()
|
|
200
|
-
|
|
201
|
-
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
func joinCall() {
|
|
160
|
+
guard let call = getAvailableCall() else {
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
OmiClient.answerIncommingCall(call.uuid)
|
|
202
164
|
}
|
|
203
165
|
|
|
204
166
|
func sendDTMF(character: String) {
|
|
205
|
-
guard let call =
|
|
167
|
+
guard let call = getAvailableCall() else {
|
|
206
168
|
return
|
|
207
169
|
}
|
|
208
170
|
try? call.sendDTMF(character)
|
|
209
171
|
}
|
|
210
172
|
|
|
211
|
-
|
|
212
173
|
/// Toogle mtue
|
|
213
|
-
func toggleMute(
|
|
214
|
-
guard let
|
|
215
|
-
return
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
omiLib.callManager.toggleMute(for: omicall) { error in
|
|
219
|
-
if error != nil {
|
|
220
|
-
NSLog("toggle mute error: \(error))")
|
|
221
|
-
}
|
|
174
|
+
func toggleMute() {
|
|
175
|
+
guard let call = getAvailableCall() else {
|
|
176
|
+
return
|
|
222
177
|
}
|
|
223
|
-
|
|
178
|
+
try? call.toggleMute()
|
|
224
179
|
}
|
|
225
180
|
|
|
226
181
|
/// Toogle hold
|
|
227
|
-
func toggleHold(
|
|
228
|
-
guard let
|
|
182
|
+
func toggleHold() {
|
|
183
|
+
guard let call = getAvailableCall() else {
|
|
229
184
|
return
|
|
230
185
|
}
|
|
231
|
-
|
|
232
|
-
guard let self = self else { return }
|
|
233
|
-
self.omiLib.callManager.toggleHold(for: omicall) { error in
|
|
234
|
-
if error != nil {
|
|
235
|
-
NSLog("Error holding current call: \(error!)")
|
|
236
|
-
return
|
|
237
|
-
} else {
|
|
238
|
-
completion()
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
186
|
+
try? call.toggleHold()
|
|
242
187
|
}
|
|
243
188
|
|
|
244
|
-
|
|
245
189
|
/// Toogle speaker
|
|
246
190
|
func toogleSpeaker() {
|
|
247
191
|
do {
|
|
@@ -255,22 +199,21 @@ class CallManager {
|
|
|
255
199
|
}
|
|
256
200
|
} catch (let error){
|
|
257
201
|
NSLog("Error toogleSpeaker current call: \(error)")
|
|
258
|
-
|
|
202
|
+
|
|
259
203
|
}
|
|
260
204
|
}
|
|
261
205
|
|
|
262
|
-
|
|
263
206
|
func inputs() -> [[String: String]] {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
207
|
+
let inputs = AVAudioSession.sharedInstance().availableInputs ?? []
|
|
208
|
+
let results = inputs.map { item in
|
|
209
|
+
return [
|
|
210
|
+
"name": item.portName,
|
|
211
|
+
"id": item.uid,
|
|
212
|
+
]
|
|
213
|
+
}
|
|
214
|
+
return results
|
|
272
215
|
}
|
|
273
|
-
|
|
216
|
+
|
|
274
217
|
func setInput(id: String) {
|
|
275
218
|
let inputs = AVAudioSession.sharedInstance().availableInputs ?? []
|
|
276
219
|
if let newOutput = inputs.first(where: {$0.uid == id}) {
|
|
@@ -281,10 +224,10 @@ class CallManager {
|
|
|
281
224
|
func outputs() -> [[String: String]] {
|
|
282
225
|
let outputs = AVAudioSession.sharedInstance().currentRoute.outputs
|
|
283
226
|
var results = outputs.map { item in
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
227
|
+
return [
|
|
228
|
+
"name": item.portName,
|
|
229
|
+
"id": item.uid,
|
|
230
|
+
]
|
|
288
231
|
}
|
|
289
232
|
let hasSpeaker = results.contains{ $0["name"] == "Speaker" }
|
|
290
233
|
if (!hasSpeaker) {
|
|
@@ -334,29 +277,29 @@ class CallManager {
|
|
|
334
277
|
}
|
|
335
278
|
}
|
|
336
279
|
|
|
337
|
-
// func getLocalPreviewView(callback: @escaping (UIView) -> Void) {
|
|
338
|
-
// guard let videoManager = videoManager else { return }
|
|
339
|
-
// videoManager.localView {previewView in
|
|
340
|
-
// DispatchQueue.main.async {
|
|
341
|
-
// if (previewView != nil) {
|
|
342
|
-
// previewView!.contentMode = .scaleAspectFill
|
|
343
|
-
// callback(previewView!)
|
|
344
|
-
// }
|
|
345
|
-
// }
|
|
346
|
-
// }
|
|
347
|
-
// }
|
|
348
|
-
//
|
|
349
|
-
// func getRemotePreviewView(callback: @escaping (UIView) -> Void) {
|
|
350
|
-
// guard let videoManager = videoManager else { return }
|
|
351
|
-
// videoManager.remoteView { previewView in
|
|
352
|
-
// DispatchQueue.main.async {
|
|
353
|
-
// if (previewView != nil) {
|
|
354
|
-
// previewView!.contentMode = .scaleAspectFill
|
|
355
|
-
// callback(previewView!)
|
|
356
|
-
// }
|
|
357
|
-
// }
|
|
358
|
-
// }
|
|
359
|
-
// }
|
|
280
|
+
// func getLocalPreviewView(callback: @escaping (UIView) -> Void) {
|
|
281
|
+
// guard let videoManager = videoManager else { return }
|
|
282
|
+
// videoManager.localView {previewView in
|
|
283
|
+
// DispatchQueue.main.async {
|
|
284
|
+
// if (previewView != nil) {
|
|
285
|
+
// previewView!.contentMode = .scaleAspectFill
|
|
286
|
+
// callback(previewView!)
|
|
287
|
+
// }
|
|
288
|
+
// }
|
|
289
|
+
// }
|
|
290
|
+
// }
|
|
291
|
+
//
|
|
292
|
+
// func getRemotePreviewView(callback: @escaping (UIView) -> Void) {
|
|
293
|
+
// guard let videoManager = videoManager else { return }
|
|
294
|
+
// videoManager.remoteView { previewView in
|
|
295
|
+
// DispatchQueue.main.async {
|
|
296
|
+
// if (previewView != nil) {
|
|
297
|
+
// previewView!.contentMode = .scaleAspectFill
|
|
298
|
+
// callback(previewView!)
|
|
299
|
+
// }
|
|
300
|
+
// }
|
|
301
|
+
// }
|
|
302
|
+
// }
|
|
360
303
|
}
|
|
361
304
|
|
|
362
305
|
|