omikit-plugin 0.2.0 → 0.3.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
CHANGED
|
@@ -1,21 +1,165 @@
|
|
|
1
|
-
#
|
|
1
|
+
# OMICALL SDK FOR React-Native
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The OmiKit exposes the <a href="https://www.npmjs.com/package/omikit-plugin">omikit-plugin</a>.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
The most important part of the framework is :
|
|
6
|
+
|
|
7
|
+
- Help to easy integrate with Omicall.
|
|
8
|
+
- Easy custom Call UI/UX.
|
|
9
|
+
- Optimize codec voip for you.
|
|
10
|
+
- Full inteface to interactive with core function like sound/ringtone/codec.
|
|
11
|
+
|
|
12
|
+
## Status
|
|
13
|
+
|
|
14
|
+
Currently active maintained
|
|
15
|
+
|
|
16
|
+
## Running
|
|
17
|
+
|
|
18
|
+
Install via npm:
|
|
6
19
|
|
|
7
20
|
```sh
|
|
8
21
|
npm install omikit-plugin
|
|
9
22
|
```
|
|
10
23
|
|
|
11
|
-
|
|
24
|
+
Install via yarn:
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
yarn add omikit-plugin
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Configuration
|
|
31
|
+
|
|
32
|
+
#### Android:
|
|
33
|
+
|
|
34
|
+
- Add this setting in `build.gradle`:
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
jcenter() // Warning: this repository is going to shut down soon
|
|
38
|
+
maven {
|
|
39
|
+
url("https://vihat.jfrog.io/artifactory/vihat-local-repo")
|
|
40
|
+
credentials {
|
|
41
|
+
username = "anonymous"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
classpath 'com.google.gms:google-services:4.3.13' //in dependencies
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
- Add this setting In `app/build.gradle`:
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
apply plugin: 'com.android.application'
|
|
54
|
+
apply plugin: 'kotlin-android'
|
|
55
|
+
apply plugin: 'com.google.gms.google-services'
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Push Notification:
|
|
59
|
+
|
|
60
|
+
- Add `google-service.json` in `android/app` (For more information, you can refer <a href="https://rnfirebase.io/">Firebase core</a>)
|
|
61
|
+
|
|
62
|
+
- For more setting information, please refer <a href="https://api.omicall.com/web-sdk/mobile-sdk/android-sdk/cau-hinh-push-notification">Omicall Config Push for Android</a>
|
|
63
|
+
|
|
64
|
+
#### iOS: Set up environment and library:
|
|
65
|
+
|
|
66
|
+
- AppDelete.h
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
#import <OmiKit/OmiKit-umbrella.h>
|
|
70
|
+
#import <UserNotifications/UserNotifications.h>
|
|
71
|
+
|
|
72
|
+
@interface AppDelegate : UIResponder <UIApplicationDelegate, RCTBridgeDelegate>
|
|
73
|
+
|
|
74
|
+
@property (nonatomic, strong) UIWindow *window;
|
|
75
|
+
@property (nonatomic, strong) PushKitManager *pushkitManager;
|
|
76
|
+
@property (nonatomic, strong) CallKitProviderDelegate * provider;
|
|
77
|
+
@property (nonatomic, strong) PKPushRegistry * voipRegistry;
|
|
78
|
+
|
|
79
|
+
@end
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
- AppDelete.m
|
|
12
84
|
|
|
13
|
-
|
|
85
|
+
```
|
|
86
|
+
#import <OmiKit/OmiKit.h>
|
|
87
|
+
|
|
88
|
+
[OmiClient setEnviroment:KEY_OMI_APP_ENVIROMENT_SANDBOX];
|
|
89
|
+
self.provider = [[CallKitProviderDelegate alloc] initWithCallManager: [OMISIPLib sharedInstance].callManager];
|
|
90
|
+
self.voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
|
|
91
|
+
self.pushkitManager = [[PushKitManager alloc] initWithVoipRegistry: self.voipRegistry];
|
|
92
|
+
//Add into `didFinishLaunchingWithOptions` function
|
|
93
|
+
```
|
|
14
94
|
|
|
15
|
-
|
|
95
|
+
- Save token for `OmiClient`, if you don't use `Messaging` for iOS:
|
|
16
96
|
|
|
17
|
-
|
|
97
|
+
```
|
|
98
|
+
- (void)application:(UIApplication*)app didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)devToken
|
|
99
|
+
{
|
|
100
|
+
// parse token bytes to string
|
|
101
|
+
const char *data = [devToken bytes];
|
|
102
|
+
NSMutableString *token = [NSMutableString string];
|
|
103
|
+
for (NSUInteger i = 0; i < [devToken length]; i++)
|
|
104
|
+
{
|
|
105
|
+
[token appendFormat:@"%02.2hhX", data[i]];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// print the token in the console.
|
|
109
|
+
NSLog(@"Push Notification Token: %@", [token copy]);
|
|
110
|
+
[OmiClient setUserPushNotificationToken:[token copy]];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
```
|
|
18
114
|
|
|
19
|
-
|
|
115
|
+
Push Notification:
|
|
116
|
+
Omicall need two certificates: VOIP Push Certificate & User Push Notification Certificate
|
|
117
|
+
|
|
118
|
+
- For more information, please refer <a href="https://api.omicall.com/web-sdk/mobile-sdk/ios-sdk/cau-hinh-push-notification">Omicall Push Notification for iOS</a>
|
|
119
|
+
|
|
120
|
+
## Implement
|
|
121
|
+
|
|
122
|
+
- Set up Firebase Messaging: <a href="https://rnfirebase.io/messaging/usage">messaging</a> plugin.
|
|
123
|
+
|
|
124
|
+
```
|
|
125
|
+
//if you use only on Android. you only implement for Android.
|
|
126
|
+
//because we use APNS to push notification on iOS so you don't need add Firebase for iOS.
|
|
127
|
+
//But you can use firebase-messaging to get APNS token for iOS.
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
- Call actions:
|
|
131
|
+
|
|
132
|
+
* `initCall` : register and init OmiCall. You need send Object value with `userName`, `password` and `realm`.
|
|
133
|
+
* `updateToken` : update token for sdk. You need send `fcmToken` for Android and send `apnsToken` for iOS.
|
|
134
|
+
* `startCall` : start Call.
|
|
135
|
+
* `endCall` : end Call.
|
|
136
|
+
* `toggleMute` : toggle the microphone status.
|
|
137
|
+
* `toggleSpeaker` : toggle the voice status. You need send Object value with `useSpeaker`.
|
|
138
|
+
* `sendDTMF` : send DTMF for call server. You need send Object value with `character` value.
|
|
139
|
+
|
|
140
|
+
* Event listener:
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
useEffect(() => {
|
|
144
|
+
omiEmitter.addListener('incomingReceived', incomingReceived);
|
|
145
|
+
omiEmitter.addListener('onCallEstablished', onCallEstablished);
|
|
146
|
+
omiEmitter.addListener('onCallEnd', onCallEnd);
|
|
147
|
+
omiEmitter.addListener('onMuted', onMuted);
|
|
148
|
+
omiEmitter.addListener('onRinging', onRinging);
|
|
149
|
+
return () => {
|
|
150
|
+
omiEmitter.removeAllListeners('incomingReceived');
|
|
151
|
+
omiEmitter.removeAllListeners('onCallEstablished');
|
|
152
|
+
omiEmitter.removeAllListeners('onCallEnd');
|
|
153
|
+
omiEmitter.removeAllListeners('onMuted');
|
|
154
|
+
omiEmitter.removeAllListeners('onRinging');
|
|
155
|
+
};
|
|
156
|
+
}, []);
|
|
157
|
+
|
|
158
|
+
```
|
|
20
159
|
|
|
21
|
-
|
|
160
|
+
* Event List: `We support 5 events`
|
|
161
|
+
* `onCallEnd`: Trigger when end the call.
|
|
162
|
+
* `onCallEstablished`: Trigger when we created the call.
|
|
163
|
+
* `onRinging`: Trigger when the phone is ringing.
|
|
164
|
+
* `onHold`: Trigger when user hold the call. From parameters, you can reviceved correct status from server through `isHold`
|
|
165
|
+
* `onMuted`: Trigger when user muted the call. From parameters, you can reviceved correct status from server through `isMuted`
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
package com.omikitplugin
|
|
2
2
|
|
|
3
3
|
import android.Manifest
|
|
4
|
-
import android.os.Handler
|
|
5
4
|
import androidx.core.app.ActivityCompat
|
|
6
5
|
import com.facebook.react.ReactActivity
|
|
7
|
-
import com.facebook.react.ReactInstanceManager
|
|
8
6
|
import com.facebook.react.bridge.*
|
|
9
7
|
import com.facebook.react.modules.core.RCTNativeAppEventEmitter
|
|
10
8
|
import vn.vihat.omicall.omisdk.OmiClient
|
|
@@ -159,10 +157,9 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
|
|
|
159
157
|
}
|
|
160
158
|
|
|
161
159
|
override fun incomingReceived(callerId: Int, phoneNumber: String?) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
))
|
|
160
|
+
val map: WritableMap = WritableNativeMap()
|
|
161
|
+
map.putInt("callerId", callerId)
|
|
162
|
+
sendEvent("phoneNumber", phoneNumber)
|
|
166
163
|
}
|
|
167
164
|
|
|
168
165
|
override fun onCallEnd() {
|
|
@@ -182,9 +179,9 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
|
|
|
182
179
|
}
|
|
183
180
|
|
|
184
181
|
override fun onMuted(isMuted: Boolean) {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
)
|
|
182
|
+
val map: WritableMap = WritableNativeMap()
|
|
183
|
+
map.putBoolean("isMuted", isMuted)
|
|
184
|
+
sendEvent("onMuted", map)
|
|
188
185
|
}
|
|
189
186
|
|
|
190
187
|
override fun onRinging() {
|
|
@@ -192,7 +189,9 @@ class OmikitPluginModule(reactContext: ReactApplicationContext?) :
|
|
|
192
189
|
}
|
|
193
190
|
|
|
194
191
|
private fun sendEvent(eventName: String?, params: Any?) {
|
|
195
|
-
|
|
196
|
-
.
|
|
192
|
+
currentActivity?.runOnUiThread {
|
|
193
|
+
reactApplicationContext.getJSModule(RCTNativeAppEventEmitter::class.java)
|
|
194
|
+
.emit(eventName, params)
|
|
195
|
+
}
|
|
197
196
|
}
|
|
198
197
|
}
|