@moxtradeveloper/react-native-moxo-module 8.9.5 → 8.13.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/LICENSE CHANGED
@@ -1,6 +1,21 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2022 john.hu
4
- Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
3
+ Copyright (c) 2023 Moxo
5
4
 
6
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,17 +1,43 @@
1
- # react-native-moxo-module
2
- reactnative-moxo-module is based on native Moxo MEPSDK, for now it only provides ability to call native SDK functions.
1
+ ![moxo](https://assets-global.website-files.com/612ecbcc615e87b0b9b38524/62037243f5ede375a8705a34_Moxo-Website-Button.svg)
2
+
3
+ [ [Introduce](#introduce) • [Preparation](#preparation) • [Installation](#installation) • [Initialization](#initialization) • [Sample Code](#sample-code) • [API Doc](#api-doc)]
4
+
5
+ ## Introduce
6
+
7
+ **react-native-moxo-module** is a [moxo sdk](https://www.moxo.com/platform/sdks) react-native wrapper. Provide Moxo OneStop capabilities to your mobile app built on [React Native](https://reactnative.dev/)
8
+
9
+ ### Supported Platforms
10
+
11
+ * iOS 13.0+
12
+ * Android 4.4+
13
+
14
+ ## Preparation
15
+
16
+ Below sdk or tools are required before start to use react-native-moxo-module.
17
+
18
+ * Node.js v14+
19
+ * Watchman
20
+
21
+ ### Android
22
+
23
+ * Android Studio
24
+ * Android SDK v19+
25
+
26
+ ### iOS
27
+
28
+ * Xcode v14.1+
29
+ * Cocoapod v1.11.0+
30
+
31
+ For more react-native set up details, please ref to [react native official site](https://reactnative.dev/docs/environment-setup)
3
32
 
4
33
  ## Installation
5
34
 
6
35
  ```sh
7
- npm install react-native-moxo-module
36
+ npm install @moxtradeveloper/react-native-moxo-module
8
37
  ```
9
- #### Supported platforms
10
- iOS: iOS 13, Xcode 14
11
-
12
- Android:
13
38
 
14
39
  ### iOS Specific Steps
40
+
15
41
  * Add moxo cocoapod repo as source into Podfile under your iOS project.
16
42
  * Change pod deployment platform to iOS 13
17
43
 
@@ -30,13 +56,13 @@ install! 'cocoapods', :deterministic_uuids => false
30
56
  # Rest of the file.....
31
57
  ```
32
58
 
33
- ## Quick start
34
- ```js
35
- import * as moxo from 'react-native-moxo-module';
59
+ ## Initialization
36
60
 
37
- // Setup domain
38
- moxo.setup('myenv.moxo.com')
61
+ ### Login
62
+
63
+ Before login, we need to get access token, by Moxo RestAPI:
39
64
 
65
+ ```js
40
66
  // Get access token
41
67
  const response = await fetch('https://myenv.moxo.com/v1/core/oauth/token', {
42
68
  method: 'POST',
@@ -53,22 +79,50 @@ const response = await fetch('https://myenv.moxo.com/v1/core/oauth/token', {
53
79
  })
54
80
  const json = await response.json();
55
81
  token = json.access_token
82
+ ```
56
83
 
84
+ Import plugin before use, then initialize moxo sdk and login with access token:
85
+
86
+ ```js
87
+ import * as moxo from 'react-native-moxo-module';
88
+ // Setup domain
89
+ moxo.setup('myenv.moxo.com')
57
90
  //Login and show moxo engagement platform window
58
- moxo.link(token).then((success)=>{
91
+ moxo.link(token).then((result)=>{
59
92
  if (result)
60
- moxo.showMEPWindow();
93
+ console.log(`Link success`)
61
94
  }).catch((err=>{
62
95
  console.log(`Link failed!:${err}`);
63
96
  }))
64
97
  ```
98
+
99
+ ### Show MEP window
100
+
101
+ After login successful, we can show MEP window directly.
102
+
103
+ ```js
104
+ moxo.showMEPWindow();
105
+ ```
106
+
107
+ ## Sample Code
108
+
109
+ ### Open existing chat
110
+
111
+ If user is logged in, call open chat API to open existing chat. If not logged in or chat does not exists, API will return error with error code and error message.
112
+
113
+ ```js
114
+ moxo.openChat('CBSmiUUjyIJP7gR8YIpiagvH', '')
115
+ ```
116
+
65
117
  ### Notification
118
+
66
119
  To enable notification feature, you'll need to integrate a notification module first, here we take [react-native-notifications](https://www.npmjs.com/package/react-native-notifications) for example, which can help to get device token and notification payload.
67
120
 
68
121
  #### Register notification
69
- Through react-native-notifications registerRemoteNotifications(), post user agreement, notification will be enabled for your app.
122
+
123
+ Through react-native-notifications registerRemoteNotifications(), post user agreement, notification will be enabled for your app.
70
124
  Call registerRemoteNotificationsRegistered() to get a device token.
71
- Then pass token to moxo function ```registerNotification()``` will register notification to Moxo server.
125
+ Then pass token to moxo function ``registerNotification()`` will register notification to Moxo server.
72
126
 
73
127
  ```js
74
128
  Notifications.registerRemoteNotifications();
@@ -84,7 +138,8 @@ Then pass token to moxo function ```registerNotification()``` will register noti
84
138
  ```
85
139
 
86
140
  #### Handle notification
87
- For example, once notification received, and user tapped notification, react-native-notifications function registerNotificationOpened will be triggered with notification payload data. Then pass payload to moxo function ```parseNotification()``` like below:
141
+
142
+ For example, once notification received, and user tapped notification, react-native-notifications function registerNotificationOpened will be triggered with notification payload data. Then pass payload to moxo function ``parseNotification()`` like below:
88
143
 
89
144
  ```js
90
145
  Notifications.events().registerNotificationOpened((notification: Notification, completion: () => void, action?: NotificationActionResponse) => {
@@ -101,10 +156,10 @@ For example, once notification received, and user tapped notification, react-nat
101
156
  });
102
157
  ```
103
158
 
104
- If is a Moxo notification, then callback of the ```parseNotification()``` would be triggered with info parameter. Usually info contains 'chat_id' or 'meet_id', depends one which kind of notification you received.
159
+ If is a Moxo notification, then callback of the ``parseNotification()`` would be triggered with info parameter. Usually info contains 'chat_id' or 'meet_id', depends one which kind of notification you received.
105
160
  To do more, you can invoke function openChat(chat_id) to open target chat directly.
106
161
 
107
- #### Sample notification payload
162
+ #### Sample notification payload
108
163
 
109
164
  ##### iOS
110
165
 
@@ -135,7 +190,7 @@ To do more, you can invoke function openChat(chat_id) to open target chat direct
135
190
  }
136
191
  ```
137
192
 
138
- ##### Android
193
+ ##### Android
139
194
 
140
195
  ```json
141
196
  [
@@ -172,8 +227,6 @@ To do more, you can invoke function openChat(chat_id) to open target chat direct
172
227
  }]
173
228
  ```
174
229
 
175
- ## License
176
-
177
- ISC
230
+ ## API Doc
178
231
 
179
- ---
232
+ [API doc](https://htmlpreview.github.io/?https://github.com/Moxtra/react-native-moxo-module/blob/main/docs/index.html)
@@ -148,7 +148,7 @@ dependencies {
148
148
  //noinspection GradleDynamicVersion
149
149
  implementation "com.facebook.react:react-native:+"
150
150
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
151
- implementation "com.moxtra:mep-sdk:8.9.5"
151
+ implementation "com.moxtra:mep-sdk:8.13.1"
152
152
  // From node_modules
153
153
  }
154
154
 
@@ -84,7 +84,31 @@ class MoxoModuleModule(reactContext: ReactApplicationContext) :
84
84
  }
85
85
  })
86
86
  }
87
+ }
88
+
89
+ @ReactMethod
90
+ fun unlink(keepNotification: Boolean) {
91
+ Log.d(TAG, "unlink called with keep notification $keepNotification")
92
+ val callback: ApiCallback<Void?> = object : ApiCallback<Void?> {
93
+ override fun onCompleted(rult: Void?) {
94
+ Log.d(TAG, "unlink successful...")
95
+ }
96
+
97
+ override fun onError(errorCode: Int, errorMsg: String) {
98
+ Log.w(TAG, "unlink failed with error code $errorCode and error message $errorMsg ...")
99
+ }
100
+ }
101
+ if (keepNotification) {
102
+ MEPClient.localUnlink(callback)
103
+ } else {
104
+ MEPClient.unlink(callback)
105
+ }
106
+ }
87
107
 
108
+ @ReactMethod
109
+ fun getUnreadMessageCount(options: ReadableMap?, promise: Promise?) {
110
+ var unreadCount = MEPClient.getUnreadMessageCount()
111
+ promise?.resolve(unreadCount)
88
112
  }
89
113
 
90
114
  @ReactMethod
@@ -185,8 +209,8 @@ class MoxoModuleModule(reactContext: ReactApplicationContext) :
185
209
  }
186
210
 
187
211
  @ReactMethod
188
- fun removeListener(eventName: String) {
189
- Log.d(TAG, "removeListener called...")
212
+ fun removeListeners(count: Integer) {
213
+ Log.d(TAG, "removeListeners called...")
190
214
  }
191
215
 
192
216
  @ReactMethod
@@ -234,6 +258,7 @@ class MoxoModuleModule(reactContext: ReactApplicationContext) :
234
258
  var meetId = rlt.getValue(key)
235
259
  jsonObject.put("session_id", meetId)
236
260
  }
261
+
237
262
  else -> continue
238
263
  }
239
264
  }
@@ -256,6 +281,38 @@ class MoxoModuleModule(reactContext: ReactApplicationContext) :
256
281
  }
257
282
  }
258
283
 
284
+ @ReactMethod
285
+ fun showMeetRinger(sessionId: String, promise: Promise?) {
286
+ Log.d(TAG, "show meet ringer called with session id $sessionId")
287
+ if (!MEPClient.isLinked()) {
288
+ promise?.reject("-1", "Not linked")
289
+ return
290
+ }
291
+ if (sessionId.isEmpty()) {
292
+ promise?.reject("-1", "session id is empty!")
293
+ return
294
+ }
295
+ MEPClient.showMeetRinger(sessionId, object : ApiCallback<Void> {
296
+ override fun onCompleted(rlt: Void?) {
297
+ Log.d(TAG, "show meet ringer success ...")
298
+ promise?.resolve("Show meet ringer success")
299
+ }
300
+
301
+ override fun onError(errorCode: Int, errorMsg: String?) {
302
+ Log.w(TAG, "show meet ringer failed with $errorCode and $errorMsg ...")
303
+ promise?.reject("-1", "Show meet ringer failed with $errorCode and $errorMsg")
304
+ }
305
+ })
306
+ }
307
+
308
+ @ReactMethod
309
+ fun changeLanguage(lang: String) {
310
+ Log.d(TAG, "changeLanguage called with $lang ...")
311
+ if (lang.isNotEmpty()) {
312
+ MEPClient.changeLanguage(lang)
313
+ }
314
+ }
315
+
259
316
  private fun json2Intent(jsonObject: JSONObject?): Intent {
260
317
  var intent = Intent()
261
318
  var keys = jsonObject?.keys();
package/ios/MoxoModule.m CHANGED
@@ -8,6 +8,7 @@ RCT_EXTERN_METHOD(link:(NSString *)token
8
8
  RCT_EXTERN_METHOD(unlink:(BOOL)keepNotification)
9
9
  RCT_EXTERN_METHOD(showMEPWindow)
10
10
  RCT_EXTERN_METHOD(hideMEPWindow)
11
+ RCT_EXTERN_METHOD(changeLanguage:(NSString *)language)
11
12
  RCT_EXTERN_METHOD(openChat:(NSString *)chatId
12
13
  feedSequence:(NSNumber *__nonnull)feedSequence
13
14
  withResolver:(RCTPromiseResolveBlock)resolve
@@ -51,6 +51,13 @@ class MoxoModule: RCTEventEmitter, MEPClientDelegate {
51
51
  }
52
52
  }
53
53
 
54
+ @objc(changeLanguage:)
55
+ func changeLanguage(language:String) {
56
+ DispatchQueue.main.async {
57
+ MEPClient.sharedInstance().changeLanguage(language)
58
+ }
59
+ }
60
+
54
61
  @objc(openChat:feedSequence:withResolver:withRejecter:)
55
62
  func openChat(chatId:String,feedSequence:NSNumber,resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) {
56
63
  DispatchQueue.main.async {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moxtradeveloper/react-native-moxo-module",
3
- "version": "8.9.5",
3
+ "version": "8.13.1",
4
4
  "description": "Plugin for adding Moxtra services to react-native Apps.",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -33,7 +33,8 @@
33
33
  "release": "release-it",
34
34
  "example": "yarn --cwd example",
35
35
  "bootstrap": "yarn example && yarn install && yarn example pods",
36
- "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build"
36
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build",
37
+ "doc":"typedoc ./src/index.tsx --skipErrorChecking"
37
38
  },
38
39
  "keywords": [
39
40
  "moxtra",
@@ -49,21 +50,18 @@
49
50
  "author": "john.hu <john.hu@moxo.com>",
50
51
  "license": "ISC",
51
52
  "bugs": {
52
- "url": "https://www.moxtra.com"
53
+ "url": "https://www.moxtra.com"
53
54
  },
54
55
  "homepage": "https://www.moxtra.com",
55
56
  "publishConfig": {
56
57
  "registry": "https://registry.npmjs.org/"
57
58
  },
58
59
  "devDependencies": {
59
- "@arkweid/lefthook": "^0.7.7",
60
- "@commitlint/config-conventional": "^17.0.2",
61
60
  "@react-native-community/eslint-config": "^3.0.2",
62
61
  "@release-it/conventional-changelog": "^5.0.0",
63
62
  "@types/jest": "^28.1.2",
64
63
  "@types/react": "~17.0.21",
65
64
  "@types/react-native": "0.70.0",
66
- "commitlint": "^17.0.2",
67
65
  "del-cli": "^5.0.0",
68
66
  "eslint": "^8.4.1",
69
67
  "eslint-config-prettier": "^8.5.0",
@@ -75,6 +73,7 @@
75
73
  "react-native": "0.70.6",
76
74
  "react-native-builder-bob": "^0.20.0",
77
75
  "release-it": "^15.0.0",
76
+ "typedoc": "^0.24.8",
78
77
  "typescript": "^4.5.2"
79
78
  },
80
79
  "resolutions": {
@@ -17,7 +17,7 @@ Pod::Spec.new do |s|
17
17
  s.public_header_files = 'ios/*.h'
18
18
  s.swift_version = '5.0'
19
19
  s.dependency "React-Core"
20
- s.dependency 'MEPSDK', '~> 8.9.5'
20
+ s.dependency 'MEPSDK', '~> 8.13.1'
21
21
 
22
22
  # Don't install the dependencies when we run `pod install` in the old architecture.
23
23
  if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
package/src/index.tsx CHANGED
@@ -68,6 +68,13 @@ export function hideMEPWindow() {
68
68
  return MoxoModule.hideMEPWindow();
69
69
  }
70
70
 
71
+ /**
72
+ * Change language, language code should follow ISO 639-1 standard.
73
+ */
74
+ export function changeLanguage(language: string) {
75
+ return MoxoModule.changeLanguage(language);
76
+ }
77
+
71
78
  /**
72
79
  * Open chat with chat Id and scroll to the specified feed
73
80
  * @param {string} chatId - Id of chat.
@@ -134,3 +141,11 @@ export function parseNotification(payload:object): Promise<object> {
134
141
  return MoxoModule.parseNotification(payload);
135
142
  }
136
143
 
144
+ /**
145
+ * Show meet ringer with session Id. For Android only.
146
+ * @param {string} sessionId - session Id
147
+ */
148
+ export function showMeetRinger(sessionId:string): Promise<object> {
149
+ return MoxoModule.showMeetRinger(sessionId);
150
+ }
151
+