@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/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
- this.setState({ settings: { ...this.state.settings, sound_enabled: enabled ? 1 : 0 } });
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 === 'screenshot' ? await native.captureScreenshot() : await native.pickAttachment(type);
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, kind === 'screenshot' ? 'image' : type);
459
+ return this.uploadAttachment(file, type);
445
460
  }
446
461
 
447
462
  async setTranslationLanguage(languageCode) {
package/src/defaults.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module.exports = {
4
4
  DEFAULT_SERVER_URL: 'https://www.crm.regantis.technology',
5
- SDK_VERSION: '0.1.2',
5
+ SDK_VERSION: '0.1.4',
6
6
  DEFAULT_SETTINGS: {
7
7
  operator_name: 'Operator',
8
8
  use_profile_names: 0,
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 captureScreenshot() {
36
- if (!native || !native.captureScreenshot) {
37
- throw new Error('NATIVE_SCREENSHOT_UNAVAILABLE');
35
+ async function takePhoto() {
36
+ if (!native || !native.takePhoto) {
37
+ throw new Error('NATIVE_CAMERA_UNAVAILABLE');
38
38
  }
39
- return native.captureScreenshot();
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
- captureScreenshot,
54
+ takePhoto,
55
55
  playIncomingSound,
56
56
  };