@moxtradeveloper/react-native-moxo-module 10.11.2 → 10.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/src/index.tsx CHANGED
@@ -1,48 +1,50 @@
1
- import { NativeEventEmitter, NativeModules, Platform } from 'react-native';
1
+ import { Platform } from 'react-native';
2
+ import type { EventSubscription } from 'react-native';
3
+ import NativeMoxoModule from './NativeMoxoModule';
4
+ import type { Spec } from './NativeMoxoModule';
5
+
2
6
  const LINKING_ERROR =
3
7
  `The package 'react-native-moxo-module' doesn't seem to be linked. Make sure: \n\n` +
4
8
  Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
5
9
  '- You rebuilt the app after installing the package\n' +
6
10
  '- You are not using Expo Go\n';
7
- const UNREAD_MSG_EVENT = "onUnreadMessageCountUpdated";
8
- const TAP_WINDOW_CLOSE_EVENT = "tapWindowCloseEvent";
9
-
10
- const MoxoModule = NativeModules.MoxoModule
11
- ? NativeModules.MoxoModule
12
- : new Proxy(
13
- {},
14
- {
15
- get() {
16
- throw new Error(LINKING_ERROR);
17
- },
18
- }
19
- )
20
- const MoxoEventEmitter = new NativeEventEmitter(MoxoModule);
11
+
12
+ const MoxoModule: Spec =
13
+ NativeMoxoModule ??
14
+ new Proxy({} as Spec, {
15
+ get() {
16
+ throw new Error(LINKING_ERROR);
17
+ },
18
+ });
19
+
21
20
  /**
22
21
  * Setup domain
23
22
  * Notice: This API MUST be invoked first before 'link'
24
23
  *
25
- * @param {string} baseDomain - Your server domain
24
+ * @param {string} domain - Your server domain
26
25
  * @param {object} options - SSL cert options, sample:
27
26
  * {
28
27
  * //SSL cert organization name. Optional, default is null.
29
- * "certOrgName" : "Moxo, Inc."
30
- *
28
+ * "certOrgName" : "Moxo, Inc."
29
+ *
31
30
  * //SSL cert public key.
32
- * "certPublicKey" : "-----BEGIN PUBLIC KEY-----\nYOUR PUBLIC KEY\n-----END PUBLIC KEY-----\n"
33
- *
31
+ * "certPublicKey" : "-----BEGIN PUBLIC KEY-----\nYOUR PUBLIC KEY\n-----END PUBLIC KEY-----\n"
32
+ *
34
33
  * //Ignore bad SSL cert or not. Default is true.
35
34
  * ignoreBadCert : false
36
35
  * }
37
36
  */
38
- export function setup(domain: string, options?:object) {
39
- return MoxoModule.setup(domain,options);
37
+ export function setup(domain: string, options?: object) {
38
+ // Older Android builds accepted the options as a JSON string.
39
+ const linkOptions =
40
+ typeof options === 'string' ? JSON.parse(options) : options;
41
+ return MoxoModule.setup(domain, linkOptions);
40
42
  }
41
43
 
42
44
  /**
43
45
  * Link user with access token.
44
46
  * @param {string} token - User access token
45
- */
47
+ */
46
48
  export function link(token: string): Promise<boolean> {
47
49
  return MoxoModule.link(token);
48
50
  }
@@ -50,28 +52,28 @@ export function link(token: string): Promise<boolean> {
50
52
  /**
51
53
  * Unlink user.
52
54
  * @param {boolean} keepNotification - Keep notification after user unlink
53
- */
55
+ */
54
56
  export function unlink(keepNotification: boolean = false) {
55
57
  return MoxoModule.unlink(keepNotification);
56
58
  }
57
59
 
58
60
  /**
59
61
  * Show mep main window.
60
- */
62
+ */
61
63
  export function showMEPWindow() {
62
64
  return MoxoModule.showMEPWindow();
63
65
  }
64
66
 
65
67
  /**
66
68
  * Hide mep main window.
67
- */
69
+ */
68
70
  export function hideMEPWindow() {
69
71
  return MoxoModule.hideMEPWindow();
70
72
  }
71
73
 
72
74
  /**
73
75
  * Change language, language code should follow ISO 639-1 standard.
74
- */
76
+ */
75
77
  export function changeLanguage(language: string) {
76
78
  return MoxoModule.changeLanguage(language);
77
79
  }
@@ -80,20 +82,23 @@ export function changeLanguage(language: string) {
80
82
  * Open chat with chat Id and scroll to the specified feed
81
83
  * @param {string} chatId - Id of chat.
82
84
  * @param {number} feedSequence - Sequence of feed.
83
- */
84
- export function openChat(chatId: string, feedSequence:number): Promise<boolean> {
85
- return MoxoModule.openChat(chatId,feedSequence);
85
+ */
86
+ export function openChat(
87
+ chatId: string,
88
+ feedSequence: number
89
+ ): Promise<boolean> {
90
+ return MoxoModule.openChat(chatId, feedSequence);
86
91
  }
87
92
 
88
93
  /**
89
94
  * Open relation chat with user
90
- * @param {object} options - User object, includes either uniqueId or email of target relation user, sample:
95
+ * @param {object} options - User object, includes either uniqueId or email of target relation user, sample:
91
96
  * {
92
- * "uniqueId" : "user_unique_id_1"
93
- * //or
97
+ * "uniqueId" : "user_unique_id_1"
98
+ * //or
94
99
  * "email" : "user_email "
95
100
  * }
96
- */
101
+ */
97
102
  export function openRelation(options: object): Promise<boolean> {
98
103
  return MoxoModule.openRelation(options);
99
104
  }
@@ -101,8 +106,8 @@ export function openRelation(options: object): Promise<boolean> {
101
106
  /**
102
107
  * Get unread message count of current user.
103
108
  * @param {object} options - Reserved option.
104
- */
105
- export function getUnreadMessageCount(options?:object): Promise<number> {
109
+ */
110
+ export function getUnreadMessageCount(options?: object): Promise<number> {
106
111
  return MoxoModule.getUnreadMessageCount(options);
107
112
  }
108
113
 
@@ -110,17 +115,19 @@ export function getUnreadMessageCount(options?:object): Promise<number> {
110
115
  * Set the callback when unread messages count updated
111
116
  *
112
117
  * @param {function} callback - Would be invoked when user unread messages count updated, with an integer parameter which represents unread messages count post update
113
- */
114
- export function onUnreadMessageCountUpdated(callback:(count:number) => void) {
115
- MoxoEventEmitter.addListener(UNREAD_MSG_EVENT,callback);
118
+ */
119
+ export function onUnreadMessageCountUpdated(
120
+ callback: (count: number) => void
121
+ ): EventSubscription {
122
+ return MoxoModule.onUnreadMessageCountUpdated(callback);
116
123
  }
117
124
 
118
125
  /**
119
- * Register Moxo notification with device token
126
+ * Register Moxo notification with device token
120
127
  *
121
128
  * @param {string} deviceToken - Device token
122
- */
123
- export function registerNotification(deviceToken:string) {
129
+ */
130
+ export function registerNotification(deviceToken: string) {
124
131
  return MoxoModule.registerNotification(deviceToken);
125
132
  }
126
133
 
@@ -137,22 +144,24 @@ export function registerNotification(deviceToken:string) {
137
144
  * }
138
145
  *
139
146
  * @param {object} payload - Notification payload
140
- */
141
- export function parseNotification(payload:object): Promise<object> {
147
+ */
148
+ export function parseNotification(payload: object): Promise<object> {
142
149
  return MoxoModule.parseNotification(payload);
143
150
  }
144
151
 
145
152
  /**
146
153
  * Show meet ringer with session Id. For Android only.
147
- * @param {string} sessionId - session Id
148
- */
149
- export function showMeetRinger(sessionId:string): Promise<object> {
150
- return MoxoModule.showMeetRinger(sessionId);
154
+ * @param {string} sessionId - session Id
155
+ */
156
+ export function showMeetRinger(sessionId: string): Promise<object> {
157
+ return MoxoModule.showMeetRinger(
158
+ sessionId
159
+ ) as Promise<unknown> as Promise<object>;
151
160
  }
152
161
 
153
162
  /**
154
163
  * Start meet with options.
155
- *
164
+ *
156
165
  * @param topic Topic of meeting
157
166
  * @param options Start meet options.
158
167
  * {
@@ -176,8 +185,9 @@ export function startMeet(topic: string, options?: object): Promise<object> {
176
185
  /**
177
186
  * Set the callback when user tap close button on MEP window
178
187
  * You should call hideMEPWindow() to hide MEP window in this callback if you want to hide MEP window
179
- */
180
- export function onTapWindowClose(callback: () => void) {
181
- MoxoEventEmitter.addListener(TAP_WINDOW_CLOSE_EVENT, callback);
188
+ */
189
+ export function onTapWindowClose(callback: () => void): EventSubscription {
190
+ const subscription = MoxoModule.onTapWindowClose(callback);
191
+ MoxoModule.enableTapWindowCloseEvent();
192
+ return subscription;
182
193
  }
183
-
@@ -1,4 +0,0 @@
1
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
- >
3
-
4
- </manifest>
@@ -1,4 +0,0 @@
1
- #import <React/RCTBridgeModule.h>
2
- #import <React/RCTViewManager.h>
3
- #import <React/RCTEventEmitter.h>
4
- #import "MoxoModuleBridge.h"
package/ios/MoxoModule.m DELETED
@@ -1,39 +0,0 @@
1
- #import <React/RCTBridgeModule.h>
2
- #import <React/RCTEventEmitter.h>
3
- @interface RCT_EXTERN_MODULE(MoxoModule, RCTEventEmitter)
4
- RCT_EXTERN_METHOD(setup:(NSString *)domain options:(NSDictionary *)options)
5
- RCT_EXTERN_METHOD(link:(NSString *)token
6
- withResolver:(RCTPromiseResolveBlock)resolve
7
- withRejecter:(RCTPromiseRejectBlock)reject)
8
- RCT_EXTERN_METHOD(unlink:(BOOL)keepNotification)
9
- RCT_EXTERN_METHOD(showMEPWindow)
10
- RCT_EXTERN_METHOD(hideMEPWindow)
11
- RCT_EXTERN_METHOD(changeLanguage:(NSString *)language)
12
- RCT_EXTERN_METHOD(openChat:(NSString *)chatId
13
- feedSequence:(NSNumber *__nonnull)feedSequence
14
- withResolver:(RCTPromiseResolveBlock)resolve
15
- withRejecter:(RCTPromiseRejectBlock)reject)
16
- RCT_EXTERN_METHOD(openRelation:(NSDictionary *)user
17
- withResolver:(RCTPromiseResolveBlock)resolve
18
- withRejecter:(RCTPromiseRejectBlock)reject)
19
- RCT_EXTERN_METHOD(startMeet:(NSString *)topic
20
- options:(NSDictionary *)options
21
- withResolver:(RCTPromiseResolveBlock)resolve
22
- withRejecter:(RCTPromiseRejectBlock)reject)
23
- RCT_EXTERN_METHOD(getUnreadMessageCount:(NSDictionary *)options
24
- withResolver:(RCTPromiseResolveBlock)resolve
25
- withRejecter:(RCTPromiseRejectBlock)reject)
26
- RCT_EXTERN_METHOD(onUnreadMessageCountUpdated:(RCTResponseSenderBlock)callback)
27
- RCT_EXTERN_METHOD(registerNotification:(NSString *)deviceToken
28
- withResolver:(RCTPromiseResolveBlock)resolve
29
- withRejecter:(RCTPromiseRejectBlock)reject)
30
- RCT_EXTERN_METHOD(parseNotification:(NSDictionary *)payload
31
- withResolver:(RCTPromiseResolveBlock)resolve
32
- withRejecter:(RCTPromiseRejectBlock)reject)
33
-
34
- + (BOOL)requiresMainQueueSetup
35
- {
36
- return YES;
37
- }
38
-
39
- @end
@@ -1,183 +0,0 @@
1
- @objc(MoxoModule)
2
- class MoxoModule: RCTEventEmitter, MEPClientDelegate {
3
- let default_error_code = 999
4
- let default_error_message = "invalid parameters"
5
- let unread_message_event = "onUnreadMessageCountUpdated"
6
- let tap_close_event = "tapWindowCloseEvent"
7
- private var onUnreadMessageCountUpdated:RCTResponseSenderBlock? = nil;
8
-
9
- override class func moduleName() -> String! {
10
- return "MoxoModule"
11
- }
12
-
13
- @objc(setup:options:)
14
- func setup(domain: String, options: Dictionary<String, Any>) {
15
- MEPClient.sharedInstance().setup(withDomain: domain, linkConfig: nil)
16
- MEPClient.sharedInstance().delegate = self
17
- }
18
-
19
- @objc(link:withResolver:withRejecter:)
20
- func link(token: String,resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) {
21
- MEPClient.sharedInstance().linkUser(withAccessToken: token) { error in
22
- if let err = error as? NSError {
23
- reject("\(err.code)", err.localizedDescription, error)
24
- } else {
25
- resolve(true)
26
- }
27
- }
28
- }
29
-
30
- @objc(unlink:)
31
- func unlink(keepNotification: Bool) {
32
- DispatchQueue.main.async {
33
- if (keepNotification) {
34
- MEPClient.sharedInstance().localUnlink()
35
- } else {
36
- MEPClient.sharedInstance().unlink()
37
- }
38
- }
39
- }
40
-
41
- @objc(showMEPWindow)
42
- func showMEPWindow() {
43
- DispatchQueue.main.async {
44
- MEPClient.sharedInstance().showMEPWindow()
45
- }
46
- }
47
-
48
- @objc(hideMEPWindow)
49
- func hideMEPWindow() {
50
- DispatchQueue.main.async {
51
- MEPClient.sharedInstance().hideMEPWindow()
52
- }
53
- }
54
-
55
- @objc(changeLanguage:)
56
- func changeLanguage(language:String) {
57
- DispatchQueue.main.async {
58
- MEPClient.sharedInstance().changeLanguage(language)
59
- }
60
- }
61
-
62
- @objc(openChat:feedSequence:withResolver:withRejecter:)
63
- func openChat(chatId:String,feedSequence:NSNumber,resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) {
64
- DispatchQueue.main.async {
65
- MEPClient.sharedInstance().openChat(chatId, withFeedSequence: feedSequence == 0 ? nil : feedSequence) { error in
66
- if let err = error as? NSError {
67
- reject("\(err.code)", err.localizedDescription, error)
68
- } else {
69
- resolve(true)
70
- }
71
- }
72
- }
73
- }
74
-
75
- @objc(openRelation:withResolver:withRejecter:)
76
- func openRelation(user:Dictionary<String, String>,resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) {
77
- DispatchQueue.main.async {
78
- if let uniqueId = user["uniqueId"] {
79
- MEPClient.sharedInstance().openRelationChat(withUniqueID: uniqueId) { error in
80
- if let err = error as? NSError {
81
- reject("\(err.code)", err.localizedDescription, error)
82
- } else {
83
- resolve(true)
84
- }
85
- }
86
- } else if let email = user["email"] {
87
- MEPClient.sharedInstance().openRelationChat(withEmail: email) { error in
88
- if let err = error as? NSError {
89
- reject("\(err.code)", err.localizedDescription, error)
90
- } else {
91
- resolve(true)
92
- }
93
- }
94
- } else {
95
- let err = NSError(domain:MEPSDKErrorDomain, code:self.default_error_code, userInfo:[ NSLocalizedDescriptionKey: "No uniqueId or email found"])
96
- reject("\(self.default_error_code)", self.default_error_message, err)
97
- }
98
- }
99
- }
100
-
101
- @objc(getUnreadMessageCount:withResolver:withRejecter:)
102
- func getUnreadMessageCount(options:Dictionary<String,String>, resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) {
103
- let ret = MEPClient.sharedInstance().getUnreadMessageCount()
104
- resolve(ret)
105
- }
106
-
107
- @objc(startMeet:options:withResolver:withRejecter:)
108
- func startMeet(topic: String, options:Dictionary<String, Any>,resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) {
109
- DispatchQueue.main.async {
110
- let meetOption = MEPStartMeetOptions()
111
- meetOption.topic = topic
112
- meetOption.chatID = options["chat_id"] as? String ?? nil
113
- meetOption.uniqueIDs = options["unique_ids"] as? Array ?? nil
114
- meetOption.autoJoinAudio = options["auto_join_audio"] as? Bool ?? true
115
- meetOption.autoStartVideo = options["auto_start_video"] as? Bool ?? false
116
- meetOption.autoRecording = options["auto_recording"] as? Bool ?? false
117
- meetOption.instantCall = options["instant_call"] as? Bool ?? false
118
- MEPClient.sharedInstance().startMeet(withOption: meetOption) { error, meetId in
119
- if let err = error as? NSError {
120
- reject("\(err.code)", err.localizedDescription, error)
121
- } else {
122
- let ret = ["session_id": meetId]
123
- resolve(ret)
124
- }
125
- }
126
- }
127
- }
128
-
129
- //MARK: Notification
130
- @objc(registerNotification:withResolver:withRejecter:)
131
- func registerNotification(deviceToken:String,resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) {
132
- if let data = Data(hex: deviceToken) {
133
- MEPClient.sharedInstance().registerNotification(withDeviceToken: data) { error in
134
- if let err = error as? NSError {
135
- reject("\(err.code)", err.localizedDescription, error)
136
- } else {
137
- resolve(true)
138
- }
139
- }
140
- }
141
- }
142
-
143
- @objc(parseNotification:withResolver:withRejecter:)
144
- func parseNotification(payload:Dictionary<String, Any>,resolve:@escaping RCTPromiseResolveBlock, reject:@escaping RCTPromiseRejectBlock) {
145
- MEPClient.sharedInstance().parseRemoteNotification(payload) { error, ret in
146
- if let err = error as? NSError {
147
- reject("\(err.code)", err.localizedDescription, error)
148
- } else {
149
- resolve(ret)
150
- }
151
- }
152
- }
153
-
154
- //MARK: MEPClientDelegate
155
- func client(_ client: MEPClient, didUpdateUnreadCount unreadCount: UInt) {
156
- sendEvent(withName: unread_message_event, body: unreadCount)
157
- }
158
-
159
- func client(_ client: MEPClient, didTapClose sender: Any?) {
160
- sendEvent(withName: tap_close_event, body: nil)
161
- }
162
-
163
- //MARK: RCTBridgeModule
164
- override func supportedEvents() -> [String]! {
165
- return [unread_message_event, tap_close_event]
166
- }
167
- }
168
-
169
- extension Data {
170
- init?(hex: String) {
171
- guard hex.count.isMultiple(of: 2) else {
172
- return nil
173
- }
174
-
175
- let chars = hex.map { $0 }
176
- let bytes = stride(from: 0, to: chars.count, by: 2)
177
- .map { String(chars[$0]) + String(chars[$0 + 1]) }
178
- .compactMap { UInt8($0, radix: 16) }
179
-
180
- guard hex.count / bytes.count == 2 else { return nil }
181
- self.init(bytes)
182
- }
183
- }