@regantis-sdk/react-native-chat 0.1.2 → 0.1.4
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 +27 -7
- package/RegantisReactNativeChat.podspec +1 -1
- package/android/build.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +22 -1
- package/android/src/main/java/technology/regantis/chat/RegantisChatNativeModule.java +161 -55
- package/android/src/main/res/xml/regantis_chat_file_paths.xml +4 -0
- package/assets/regantis_logo_black.png +0 -0
- package/assets/regantis_logo_white.png +0 -0
- package/assets/soft_glow.png +0 -0
- package/index.d.ts +2 -1
- package/ios/RegantisChatNative.h +1 -1
- package/ios/RegantisChatNative.m +113 -32
- package/package.json +2 -1
- package/src/RegantisChat.js +572 -55
- package/src/client.js +19 -4
- package/src/defaults.js +1 -1
- package/src/native.js +5 -5
package/src/client.js
CHANGED
|
@@ -119,6 +119,7 @@ class RegantisChatClient {
|
|
|
119
119
|
upload: null,
|
|
120
120
|
realtime: null,
|
|
121
121
|
realtimeConnected: false,
|
|
122
|
+
soundAvailable: false,
|
|
122
123
|
remoteTyping: '',
|
|
123
124
|
sending: false,
|
|
124
125
|
uploading: false,
|
|
@@ -153,6 +154,10 @@ class RegantisChatClient {
|
|
|
153
154
|
return `regantis_chat_visitor_${this.options.apiKey}`;
|
|
154
155
|
}
|
|
155
156
|
|
|
157
|
+
soundStorageKey() {
|
|
158
|
+
return `regantis_chat_sound_${this.options.apiKey}`;
|
|
159
|
+
}
|
|
160
|
+
|
|
156
161
|
async start() {
|
|
157
162
|
this.destroyed = false;
|
|
158
163
|
this.setState({ loading: true, error: '' });
|
|
@@ -190,7 +195,9 @@ class RegantisChatClient {
|
|
|
190
195
|
}
|
|
191
196
|
|
|
192
197
|
setSoundEnabled(enabled) {
|
|
193
|
-
|
|
198
|
+
const value = this.state.soundAvailable && enabled ? 1 : 0;
|
|
199
|
+
this.setState({ settings: { ...this.state.settings, sound_enabled: value } });
|
|
200
|
+
if (this.state.soundAvailable) native.setItem(this.soundStorageKey(), value ? '1' : '0').catch(() => {});
|
|
194
201
|
}
|
|
195
202
|
|
|
196
203
|
async loadConfig() {
|
|
@@ -201,12 +208,20 @@ class RegantisChatClient {
|
|
|
201
208
|
|
|
202
209
|
const settings = normalizeSettings({ ...(data.settings || {}), ...(this.options.theme || {}) });
|
|
203
210
|
const texts = { ...(data.texts || {}), ...(this.options.texts || {}) };
|
|
211
|
+
const soundAvailable = Number(settings.sound_enabled || 0) === 1;
|
|
212
|
+
if (soundAvailable) {
|
|
213
|
+
const storedSound = await native.getItem(this.soundStorageKey());
|
|
214
|
+
if (storedSound !== null && storedSound !== undefined) settings.sound_enabled = String(storedSound) === '0' ? 0 : 1;
|
|
215
|
+
} else {
|
|
216
|
+
settings.sound_enabled = 0;
|
|
217
|
+
}
|
|
204
218
|
this.setState({
|
|
205
219
|
config: data,
|
|
206
220
|
settings,
|
|
207
221
|
texts,
|
|
208
222
|
languages: Array.isArray(data.languages) ? data.languages : [],
|
|
209
223
|
translationCustomerEnabled: Number(data.translation_customer_enabled || 0) === 1,
|
|
224
|
+
soundAvailable,
|
|
210
225
|
});
|
|
211
226
|
return data;
|
|
212
227
|
}
|
|
@@ -438,10 +453,10 @@ class RegantisChatClient {
|
|
|
438
453
|
}
|
|
439
454
|
|
|
440
455
|
async pickAndUpload(kind) {
|
|
441
|
-
const type = kind === 'image' ? 'image' : 'file';
|
|
442
|
-
const file = kind === '
|
|
456
|
+
const type = kind === 'image' || kind === 'camera' ? 'image' : 'file';
|
|
457
|
+
const file = kind === 'camera' ? await native.takePhoto() : await native.pickAttachment(type);
|
|
443
458
|
if (!file) return null;
|
|
444
|
-
return this.uploadAttachment(file,
|
|
459
|
+
return this.uploadAttachment(file, type);
|
|
445
460
|
}
|
|
446
461
|
|
|
447
462
|
async setTranslationLanguage(languageCode) {
|
package/src/defaults.js
CHANGED
package/src/native.js
CHANGED
|
@@ -32,11 +32,11 @@ async function pickAttachment(kind) {
|
|
|
32
32
|
return native.pickAttachment(kind === 'image' ? 'image' : 'file');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
async function
|
|
36
|
-
if (!native || !native.
|
|
37
|
-
throw new Error('
|
|
35
|
+
async function takePhoto() {
|
|
36
|
+
if (!native || !native.takePhoto) {
|
|
37
|
+
throw new Error('NATIVE_CAMERA_UNAVAILABLE');
|
|
38
38
|
}
|
|
39
|
-
return native.
|
|
39
|
+
return native.takePhoto();
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
function playIncomingSound() {
|
|
@@ -51,6 +51,6 @@ module.exports = {
|
|
|
51
51
|
removeItem,
|
|
52
52
|
getAppInfo,
|
|
53
53
|
pickAttachment,
|
|
54
|
-
|
|
54
|
+
takePhoto,
|
|
55
55
|
playIncomingSound,
|
|
56
56
|
};
|