@zelloptt/react-native-zello-sdk 0.1.0

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.
Files changed (84) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +21 -0
  3. package/android/build.gradle +122 -0
  4. package/android/gradle.properties +5 -0
  5. package/android/src/main/AndroidManifest.xml +3 -0
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/com/zellosdk/DummyPackage.kt +18 -0
  8. package/android/src/main/java/com/zellosdk/ZelloAndroidSdkModule.kt +437 -0
  9. package/android/src/main/java/com/zellosdk/ZelloAndroidSdkModuleHelper.kt +198 -0
  10. package/ios/Extensions/Date+Extension.swift +5 -0
  11. package/ios/Extensions/UIImage+Extension.swift +9 -0
  12. package/ios/Extensions/ZelloContact+Extension.swift +52 -0
  13. package/ios/Extensions/ZelloHistoryAlertMessage+Extension.swift +18 -0
  14. package/ios/Extensions/ZelloHistoryImageMessage+Extension.swift +17 -0
  15. package/ios/Extensions/ZelloHistoryLocationMessage+Extension.swift +23 -0
  16. package/ios/Extensions/ZelloHistoryTextMessage+Extension.swift +18 -0
  17. package/ios/Extensions/ZelloHistoryVoiceMessage+Extension.swift +18 -0
  18. package/ios/Extensions/ZelloIOSSdkModule+Extension.swift +285 -0
  19. package/ios/Extensions/ZelloIncomingEmergency+Extension.swift +16 -0
  20. package/ios/Extensions/ZelloOutgoingEmergency+Extension.swift +14 -0
  21. package/ios/Extensions/ZelloRecentEntry+Extension.swift +16 -0
  22. package/ios/ZelloIOSSdkModule.swift +209 -0
  23. package/ios/ZelloIOSSdkModuleBridge.h +5 -0
  24. package/ios/ZelloIOSSdkModuleBridge.m +44 -0
  25. package/lib/commonjs/events/index.js +43 -0
  26. package/lib/commonjs/events/index.js.map +1 -0
  27. package/lib/commonjs/index.js +47 -0
  28. package/lib/commonjs/index.js.map +1 -0
  29. package/lib/commonjs/package.json +1 -0
  30. package/lib/commonjs/sdk/index.js +833 -0
  31. package/lib/commonjs/sdk/index.js.map +1 -0
  32. package/lib/commonjs/types/index.js +518 -0
  33. package/lib/commonjs/types/index.js.map +1 -0
  34. package/lib/commonjs/utils/algorithms/index.js +79 -0
  35. package/lib/commonjs/utils/algorithms/index.js.map +1 -0
  36. package/lib/commonjs/utils/index.js +60 -0
  37. package/lib/commonjs/utils/index.js.map +1 -0
  38. package/lib/module/events/index.js +39 -0
  39. package/lib/module/events/index.js.map +1 -0
  40. package/lib/module/index.js +10 -0
  41. package/lib/module/index.js.map +1 -0
  42. package/lib/module/package.json +1 -0
  43. package/lib/module/sdk/index.js +829 -0
  44. package/lib/module/sdk/index.js.map +1 -0
  45. package/lib/module/types/index.js +547 -0
  46. package/lib/module/types/index.js.map +1 -0
  47. package/lib/module/utils/algorithms/index.js +72 -0
  48. package/lib/module/utils/algorithms/index.js.map +1 -0
  49. package/lib/module/utils/index.js +52 -0
  50. package/lib/module/utils/index.js.map +1 -0
  51. package/lib/typescript/commonjs/package.json +1 -0
  52. package/lib/typescript/commonjs/src/events/index.d.ts +192 -0
  53. package/lib/typescript/commonjs/src/events/index.d.ts.map +1 -0
  54. package/lib/typescript/commonjs/src/index.d.ts +6 -0
  55. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  56. package/lib/typescript/commonjs/src/sdk/index.d.ts +221 -0
  57. package/lib/typescript/commonjs/src/sdk/index.d.ts.map +1 -0
  58. package/lib/typescript/commonjs/src/types/index.d.ts +560 -0
  59. package/lib/typescript/commonjs/src/types/index.d.ts.map +1 -0
  60. package/lib/typescript/commonjs/src/utils/algorithms/index.d.ts +21 -0
  61. package/lib/typescript/commonjs/src/utils/algorithms/index.d.ts.map +1 -0
  62. package/lib/typescript/commonjs/src/utils/index.d.ts +8 -0
  63. package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -0
  64. package/lib/typescript/module/package.json +1 -0
  65. package/lib/typescript/module/src/events/index.d.ts +192 -0
  66. package/lib/typescript/module/src/events/index.d.ts.map +1 -0
  67. package/lib/typescript/module/src/index.d.ts +6 -0
  68. package/lib/typescript/module/src/index.d.ts.map +1 -0
  69. package/lib/typescript/module/src/sdk/index.d.ts +221 -0
  70. package/lib/typescript/module/src/sdk/index.d.ts.map +1 -0
  71. package/lib/typescript/module/src/types/index.d.ts +560 -0
  72. package/lib/typescript/module/src/types/index.d.ts.map +1 -0
  73. package/lib/typescript/module/src/utils/algorithms/index.d.ts +21 -0
  74. package/lib/typescript/module/src/utils/algorithms/index.d.ts.map +1 -0
  75. package/lib/typescript/module/src/utils/index.d.ts +8 -0
  76. package/lib/typescript/module/src/utils/index.d.ts.map +1 -0
  77. package/package.json +195 -0
  78. package/react-native-zello-sdk.podspec +43 -0
  79. package/src/events/index.ts +191 -0
  80. package/src/index.ts +8 -0
  81. package/src/sdk/index.ts +1038 -0
  82. package/src/types/index.ts +818 -0
  83. package/src/utils/algorithms/index.ts +88 -0
  84. package/src/utils/index.ts +145 -0
@@ -0,0 +1,829 @@
1
+ "use strict";
2
+
3
+ var _Zello;
4
+ function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
5
+ function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
6
+ function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
7
+ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
8
+ function _possibleConstructorReturn(t, e) { if (e && ("object" == typeof e || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); }
9
+ function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; }
10
+ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
11
+ function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
12
+ function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
13
+ function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
14
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
15
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
16
+ function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
17
+ import { NativeEventEmitter, NativeModules } from 'react-native';
18
+ import { isAndroid } from "../utils/index.js";
19
+ import { ZelloAccountStatus, ZelloAlertMessage, ZelloChannelUser, ZelloConnectionError, ZelloConnectionState, ZelloContactType, ZelloImageMessage, ZelloIncomingVoiceMessage, ZelloLocationMessage, ZelloOutgoingEmergency, ZelloOutgoingVoiceMessage, ZelloOutgoingVoiceMessageError, ZelloOutgoingVoiceMessageState, ZelloRecentEntry, ZelloTextMessage } from "../types/index.js";
20
+ import EventEmitter from 'react-native/Libraries/vendor/emitter/EventEmitter';
21
+ import { compareNameAscending, sortedArrayFind } from "../utils/algorithms/index.js";
22
+ import { bridgeContactToSdkContact, bridgeHistoryMessageToSdkHistoryMessage, bridgeIncomingEmergencyToSdkIncomingEmergency } from "../utils/index.js";
23
+ import { ZelloEvent } from "../events/index.js";
24
+ const {
25
+ ZelloAndroidSdkModule,
26
+ ZelloIOSSdkModule
27
+ } = NativeModules;
28
+
29
+ /**
30
+ * Zello SDK.
31
+ * This class is a singleton, and can be accessed via {@link Zello.getInstance}.
32
+ */
33
+ export let Zello = /*#__PURE__*/function (_EventEmitter) {
34
+ function Zello() {
35
+ var _this;
36
+ _classCallCheck(this, Zello);
37
+ _this = _callSuper(this, Zello);
38
+ /**
39
+ * The current connection state of the SDK.
40
+ */
41
+ _defineProperty(_this, "state", ZelloConnectionState.Disconnected);
42
+ /**
43
+ * The currently selected contact.
44
+ */
45
+ _defineProperty(_this, "selectedContact", void 0);
46
+ /**
47
+ * The list of {@link ZelloUser} in the contact list. Sorted by name, ascending.
48
+ */
49
+ _defineProperty(_this, "users", []);
50
+ /**
51
+ * The list of {@link ZelloChannel} in the contact list. Sorted by name, ascending.
52
+ */
53
+ _defineProperty(_this, "channels", []);
54
+ /**
55
+ * The current account status. undefined when {@link state} is not {@link ZelloConnectionState.Connected}.
56
+ */
57
+ _defineProperty(_this, "accountStatus", void 0);
58
+ /**
59
+ * The current incoming voice message.
60
+ */
61
+ _defineProperty(_this, "incomingVoiceMessage", void 0);
62
+ /**
63
+ * The current outgoing voice message.
64
+ */
65
+ _defineProperty(_this, "outgoingVoiceMessage", void 0);
66
+ /**
67
+ * The configured emergency channel.
68
+ */
69
+ _defineProperty(_this, "emergencyChannel", void 0);
70
+ /**
71
+ * The list of incoming emergencies. There can be multiple emergencies on the emergency channel at once.
72
+ * Sorted by start timestamp, ascending.
73
+ */
74
+ _defineProperty(_this, "incomingEmergencies", []);
75
+ /**
76
+ * The current outgoing emergency.
77
+ */
78
+ _defineProperty(_this, "outgoingEmergency", void 0);
79
+ /**
80
+ * The list of recent entries. Sorted by timestamp, descending.
81
+ */
82
+ _defineProperty(_this, "recents", []);
83
+ /**
84
+ * The currently playing history voice message.
85
+ */
86
+ _defineProperty(_this, "historyVoiceMessage", void 0);
87
+ _defineProperty(_this, "eventListener", void 0);
88
+ const sdk = Zello.getSdk();
89
+ if (sdk) {
90
+ let eventEmitter;
91
+ if (isAndroid) {
92
+ eventEmitter = new NativeEventEmitter();
93
+ } else {
94
+ eventEmitter = new NativeEventEmitter(sdk);
95
+ }
96
+ _this.setupEventListener(eventEmitter);
97
+ }
98
+ return _this;
99
+ }
100
+
101
+ /**
102
+ * Sets configuration variables for the SDK.
103
+ *
104
+ * At the moment, this is only functional on Android.
105
+ *
106
+ * @param config The configuration to set.
107
+ */
108
+ _inherits(Zello, _EventEmitter);
109
+ return _createClass(Zello, [{
110
+ key: "configure",
111
+ value: function configure(config) {
112
+ if (isAndroid) {
113
+ ZelloAndroidSdkModule.configure(config.android.enableOfflineMessagePushNotifications, config.android.enableForegroundService);
114
+ } else {
115
+ ZelloIOSSdkModule.configure(config.ios.isDebugBuild);
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Destroys the SDK instance and cleans up resources.
121
+ * Call this when you are done using the SDK instance for good (application quit).
122
+ */
123
+ }, {
124
+ key: "destroy",
125
+ value: function destroy() {
126
+ this.removeAllListeners();
127
+ this.eventListener?.remove();
128
+ }
129
+
130
+ /**
131
+ * Signs into to the Zello Work network using the provided credentials.
132
+ * This will typically trigger the {@link ZelloEvent.CONNECT_STARTED} event, followed by either {@link ZelloEvent.CONNECT_SUCCEEDED} or {@link ZelloEvent.CONNECT_FAILED}.
133
+ * However, if the state is incorrect, {@link ZelloEvent.CONNECT_FAILED} will be triggered immediately.
134
+ * @param credentials The credentials to use for signing in.
135
+ */
136
+ }, {
137
+ key: "connect",
138
+ value: function connect(credentials) {
139
+ if (isAndroid) {
140
+ ZelloAndroidSdkModule.connect(credentials.network, credentials.username, credentials.password);
141
+ } else {
142
+ ZelloIOSSdkModule.connect(credentials.network, credentials.username, credentials.password);
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Signs out of the Zello Work network.
148
+ * This will trigger the {@link ZelloEvent.DISCONNECTED} event.
149
+ */
150
+ }, {
151
+ key: "disconnect",
152
+ value: function disconnect() {
153
+ if (isAndroid) {
154
+ ZelloAndroidSdkModule.disconnect();
155
+ } else {
156
+ ZelloIOSSdkModule.disconnect();
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Returns the user with the given name. Case-insensitive.
162
+ * @param name The name of the user to search for.
163
+ * @return The user with the given name, or null if no user with that name exists.
164
+ */
165
+ }, {
166
+ key: "getUser",
167
+ value: function getUser(name) {
168
+ return sortedArrayFind(this.users, name, compareNameAscending);
169
+ }
170
+
171
+ /**
172
+ * Returns the channel with the given name. Case-insensitive.
173
+ * @param name The name of the channel to search for.
174
+ * @return The channel with the given name, or null if no channel with that name exists.
175
+ */
176
+ }, {
177
+ key: "getChannel",
178
+ value: function getChannel(name) {
179
+ return sortedArrayFind(this.channels, name, compareNameAscending);
180
+ }
181
+
182
+ /**
183
+ * Sets the selected contact.
184
+ * While optional, this is typically used for tracking the contact that the user is currently interacting with.
185
+ * This will trigger the {@link ZelloEvent.SELECTED_CONTACT_CHANGED} event.
186
+ * @param contact The contact to set as selected.
187
+ */
188
+ }, {
189
+ key: "setSelectedContact",
190
+ value: function setSelectedContact(contact) {
191
+ const isChannel = contact.type === ZelloContactType.Channel;
192
+ if (isAndroid) {
193
+ ZelloAndroidSdkModule.setSelectedContact(contact.name, isChannel);
194
+ } else {
195
+ ZelloIOSSdkModule.selectContact(contact.name, isChannel);
196
+ }
197
+ }
198
+
199
+ /**
200
+ * Sets the user's online account status.
201
+ * This will trigger the {@link ZelloEvent.ACCOUNT_STATUS_CHANGED} event.
202
+ * @param status The account status to set.
203
+ */
204
+ }, {
205
+ key: "setAccountStatus",
206
+ value: function setAccountStatus(status) {
207
+ if (isAndroid) {
208
+ ZelloAndroidSdkModule.setAccountStatus(status);
209
+ } else {
210
+ ZelloIOSSdkModule.setAccountStatus(status);
211
+ }
212
+ }
213
+
214
+ /**
215
+ * Connects to the given channel.
216
+ * Once connected, the user will be able to send and receive messages from the channel.
217
+ * This will trigger the {@link ZelloEvent.CONTACT_LIST_UPDATED} event.
218
+ * @param channel The channel to connect to.
219
+ */
220
+ }, {
221
+ key: "connectChannel",
222
+ value: function connectChannel(channel) {
223
+ if (isAndroid) {
224
+ ZelloAndroidSdkModule.connectChannel(channel.name);
225
+ } else {
226
+ ZelloIOSSdkModule.connectChannel(channel.name);
227
+ }
228
+ }
229
+
230
+ /**
231
+ * Disconnects from the given channel.
232
+ * Once disconnected, the user will no longer be able to send or receive messages from the channel.
233
+ * This will trigger the {@link ZelloEvent.CONTACT_LIST_UPDATED} event.
234
+ * @param channel The channel to disconnect from.
235
+ */
236
+ }, {
237
+ key: "disconnectChannel",
238
+ value: function disconnectChannel(channel) {
239
+ if (isAndroid) {
240
+ ZelloAndroidSdkModule.disconnectChannel(channel.name);
241
+ } else {
242
+ ZelloIOSSdkModule.disconnectChannel(channel.name);
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Starts a voice message with the given contact.
248
+ * This will trigger the {@link ZelloEvent.OUTGOING_VOICE_MESSAGE_CONNECTING} event, followed by the {@link ZelloEvent.OUTGOING_VOICE_MESSAGE_STARTED} event.
249
+ * If there is an error, the {@link ZelloEvent.OUTGOING_VOICE_MESSAGE_STOPPED} event will be triggered.
250
+ * @param contact The contact to start the voice message with.
251
+ */
252
+ }, {
253
+ key: "startVoiceMessage",
254
+ value: function startVoiceMessage(contact) {
255
+ const isChannel = contact.type === ZelloContactType.Channel;
256
+ if (isAndroid) {
257
+ ZelloAndroidSdkModule.startVoiceMessage(contact.name, isChannel);
258
+ } else {
259
+ ZelloIOSSdkModule.startVoiceMessage(contact.name, isChannel);
260
+ }
261
+ }
262
+
263
+ /**
264
+ * Stops the current outgoing voice message.
265
+ * This will trigger the {@link ZelloEvent.OUTGOING_VOICE_MESSAGE_STOPPED} event.
266
+ */
267
+ }, {
268
+ key: "stopVoiceMessage",
269
+ value: function stopVoiceMessage() {
270
+ if (isAndroid) {
271
+ ZelloAndroidSdkModule.stopVoiceMessage();
272
+ } else {
273
+ ZelloIOSSdkModule.stopVoiceMessage();
274
+ }
275
+ }
276
+
277
+ /**
278
+ * Sends the image message data to the given contact.
279
+ * This will trigger the {@link ZelloEvent.OUTGOING_IMAGE_MESSAGE_SENT} or {@link ZelloEvent.OUTGOING_IMAGE_MESSAGE_SEND_FAILED} event.
280
+ * @param contact The contact to send the image to.
281
+ * @param data The image data to send.
282
+ */
283
+ }, {
284
+ key: "sendImage",
285
+ value: function sendImage(contact, data) {
286
+ const isChannel = contact.type === ZelloContactType.Channel;
287
+ if (isAndroid) {
288
+ ZelloAndroidSdkModule.sendImage(contact.name, isChannel, data);
289
+ } else {
290
+ ZelloIOSSdkModule.sendImage(contact.name, isChannel, data);
291
+ }
292
+ }
293
+
294
+ /**
295
+ * Sends the alert message to the given contact.
296
+ * This will trigger the {@link ZelloEvent.OUTGOING_ALERT_MESSAGE_SENT} or {@link ZelloEvent.OUTGOING_ALERT_MESSAGE_SEND_FAILED} event.
297
+ * @param contact The contact to send the alert to.
298
+ */
299
+ }, {
300
+ key: "sendLocation",
301
+ value: function sendLocation(contact) {
302
+ const isChannel = contact.type === ZelloContactType.Channel;
303
+ if (isAndroid) {
304
+ ZelloAndroidSdkModule.sendLocation(contact.name, isChannel);
305
+ } else {
306
+ ZelloIOSSdkModule.sendLocation(contact.name, isChannel);
307
+ }
308
+ }
309
+
310
+ /**
311
+ * Sends the text message to the given contact.
312
+ * This will trigger the {@link ZelloEvent.OUTGOING_TEXT_MESSAGE_SENT} or {@link ZelloEvent.OUTGOING_TEXT_MESSAGE_SEND_FAILED} event.
313
+ * @param contact The contact to send the text to.
314
+ * @param text The text to send.
315
+ */
316
+ }, {
317
+ key: "sendText",
318
+ value: function sendText(contact, text) {
319
+ const isChannel = contact.type === ZelloContactType.Channel;
320
+ if (isAndroid) {
321
+ ZelloAndroidSdkModule.sendText(contact.name, isChannel, text);
322
+ } else {
323
+ ZelloIOSSdkModule.sendText(contact.name, isChannel, text);
324
+ }
325
+ }
326
+
327
+ /**
328
+ * Sends the alert message to the given contact.
329
+ * This will trigger the {@link ZelloEvent.OUTGOING_ALERT_MESSAGE_SENT} or {@link ZelloEvent.OUTGOING_ALERT_MESSAGE_SEND_FAILED} event.
330
+ * @param contact The contact to send the alert to.
331
+ * @param text The text to send.
332
+ * @param level Optional; The alert level to send. Only applicable for channels.
333
+ */
334
+ }, {
335
+ key: "sendAlert",
336
+ value: function sendAlert(contact, text, level) {
337
+ const isChannel = contact.type === ZelloContactType.Channel;
338
+ if (isAndroid) {
339
+ ZelloAndroidSdkModule.sendAlert(contact.name, isChannel, text, level);
340
+ } else {
341
+ ZelloIOSSdkModule.sendAlert(contact.name, isChannel, text, level);
342
+ }
343
+ }
344
+
345
+ /**
346
+ * Submits a problem report to Zello.
347
+ * Additionally, please contact us to provide more information on what happened.
348
+ */
349
+ }, {
350
+ key: "submitProblemReport",
351
+ value: function submitProblemReport() {
352
+ if (isAndroid) {
353
+ ZelloAndroidSdkModule.submitProblemReport();
354
+ } else {
355
+ ZelloIOSSdkModule.submitProblemReport();
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Mutes the given contact. When muted, incoming messages from this contact will not play live, but will still appear in the history.
361
+ * This will trigger the {@link ZelloEvent.CONTACT_LIST_UPDATED} event.
362
+ * @param contact The contact to mute.
363
+ */
364
+ }, {
365
+ key: "muteContact",
366
+ value: function muteContact(contact) {
367
+ const isChannel = contact.type === ZelloContactType.Channel;
368
+ if (isAndroid) {
369
+ ZelloAndroidSdkModule.muteContact(contact.name, isChannel);
370
+ } else {
371
+ ZelloIOSSdkModule.muteContact(contact.name, isChannel);
372
+ }
373
+ }
374
+
375
+ /**
376
+ * Unmutes a previously muted contact. When unmuted, incoming messages from this contact will play live.
377
+ * This will trigger the {@link ZelloEvent.CONTACT_LIST_UPDATED} event.
378
+ * @param contact The contact to unmute.
379
+ */
380
+ }, {
381
+ key: "unmuteContact",
382
+ value: function unmuteContact(contact) {
383
+ const isChannel = contact.type === ZelloContactType.Channel;
384
+ if (isAndroid) {
385
+ ZelloAndroidSdkModule.unmuteContact(contact.name, isChannel);
386
+ } else {
387
+ ZelloIOSSdkModule.unmuteContact(contact.name, isChannel);
388
+ }
389
+ }
390
+
391
+ /**
392
+ * Starts an outgoing emergency to the emergency channel.
393
+ * Upon starting, the user's location will be sent, an alert message will be sent, and a 10-second-long voice message will start recording.
394
+ * This will trigger the {@link ZelloEvent.OUTGOING_EMERGENCY_STARTED} event.
395
+ */
396
+ }, {
397
+ key: "startEmergency",
398
+ value: function startEmergency() {
399
+ if (isAndroid) {
400
+ ZelloAndroidSdkModule.startEmergency();
401
+ } else {
402
+ ZelloIOSSdkModule.startEmergency();
403
+ }
404
+ }
405
+
406
+ /**
407
+ * Stops the outgoing emergency.
408
+ * This will trigger the {@link ZelloEvent.OUTGOING_EMERGENCY_STOPPED} event.
409
+ */
410
+ }, {
411
+ key: "stopEmergency",
412
+ value: function stopEmergency() {
413
+ if (isAndroid) {
414
+ ZelloAndroidSdkModule.stopEmergency();
415
+ } else {
416
+ ZelloIOSSdkModule.stopEmergency();
417
+ }
418
+ }
419
+
420
+ /**
421
+ * Returns the history messages for the given contact.
422
+ * @param contact The contact to get the history for.
423
+ * @param size Optional; The number of history items to retrieve. Defaults to 50.
424
+ * @return The history items for the given contact.
425
+ */
426
+ }, {
427
+ key: "getHistory",
428
+ value: function getHistory(contact, size) {
429
+ const defaultHistorySize = 50;
430
+ return new Promise(resolve => {
431
+ const isChannel = contact.type === ZelloContactType.Channel;
432
+ const callback = history => {
433
+ if (!history) {
434
+ resolve([]);
435
+ return;
436
+ }
437
+ const messages = history.map(message => bridgeHistoryMessageToSdkHistoryMessage(message)).filter(item => item !== undefined);
438
+ resolve(messages);
439
+ };
440
+ if (isAndroid) {
441
+ ZelloAndroidSdkModule.getHistory(contact.name, isChannel, size ?? defaultHistorySize, callback);
442
+ } else {
443
+ ZelloIOSSdkModule.getHistory(contact.name, isChannel, size ?? defaultHistorySize, callback);
444
+ }
445
+ });
446
+ }
447
+
448
+ /**
449
+ * Plays the given history message.
450
+ * This will trigger the {@link ZelloEvent.HISTORY_PLAYBACK_STARTED} event.
451
+ * @param message The history message to play.
452
+ */
453
+ }, {
454
+ key: "playHistoryMessage",
455
+ value: function playHistoryMessage(message) {
456
+ const isChannel = message.contact.type === ZelloContactType.Channel;
457
+ if (isAndroid) {
458
+ ZelloAndroidSdkModule.playHistoryMessage(message.historyId, message.contact.name, isChannel);
459
+ } else {
460
+ ZelloIOSSdkModule.playHistoryMessage(message.historyId, message.contact.name, isChannel);
461
+ }
462
+ }
463
+
464
+ /**
465
+ * Stops the current history message playback.
466
+ * This will trigger the {@link ZelloEvent.HISTORY_PLAYBACK_STOPPED} event.
467
+ */
468
+ }, {
469
+ key: "stopHistoryMessagePlayback",
470
+ value: function stopHistoryMessagePlayback() {
471
+ if (isAndroid) {
472
+ ZelloAndroidSdkModule.stopHistoryMessagePlayback();
473
+ } else {
474
+ ZelloIOSSdkModule.stopHistoryMessagePlayback();
475
+ }
476
+ }
477
+
478
+ /**
479
+ * Returns the image data for the given history image message.
480
+ * @param message The history image message to get the image data for.
481
+ * @return The image data for the given history image message.
482
+ */
483
+ }, {
484
+ key: "getImageDataForHistoryImageMessage",
485
+ value: function getImageDataForHistoryImageMessage(message) {
486
+ return new Promise(resolve => {
487
+ const isChannel = message.contact.type === ZelloContactType.Channel;
488
+ if (isAndroid) {
489
+ ZelloAndroidSdkModule.getImageDataForHistoryImageMessage(message.historyId, message.contact.name, isChannel, data => resolve(data));
490
+ } else {
491
+ ZelloIOSSdkModule.getHistoryImageData(message.historyId, message.contact.name, isChannel, data => resolve(data));
492
+ }
493
+ });
494
+ }
495
+ }, {
496
+ key: "setupEventListener",
497
+ value: function setupEventListener(eventEmitter) {
498
+ this.eventListener = eventEmitter.addListener('zellosdk', event => {
499
+ const eventName = event.eventName;
500
+ switch (eventName) {
501
+ case 'onConnectFailed':
502
+ {
503
+ this.state = ZelloConnectionState.Disconnected;
504
+ const error = event.error?.toLowerCase() ?? ZelloConnectionError.Unknown;
505
+ this.emit(ZelloEvent.CONNECT_FAILED, this.state, error);
506
+ break;
507
+ }
508
+ case 'onConnectStarted':
509
+ {
510
+ this.state = ZelloConnectionState.Connecting;
511
+ this.emit(ZelloEvent.CONNECT_STARTED, this.state);
512
+ break;
513
+ }
514
+ case 'onConnectSucceeded':
515
+ {
516
+ this.state = ZelloConnectionState.Connected;
517
+ this.emit(ZelloEvent.CONNECT_SUCCEEDED, this.state);
518
+ break;
519
+ }
520
+ case 'onDisconnected':
521
+ {
522
+ this.state = ZelloConnectionState.Disconnected;
523
+ this.emit(ZelloEvent.DISCONNECTED, this.state);
524
+ break;
525
+ }
526
+ case 'onWillReconnect':
527
+ {
528
+ this.state = ZelloConnectionState.Reconnecting;
529
+ this.emit(ZelloEvent.RECONNECTING, this.state);
530
+ break;
531
+ }
532
+ case 'onContactListUpdated':
533
+ {
534
+ this.clearContactList();
535
+ this.users = event.users.map(user => bridgeContactToSdkContact(user));
536
+ this.users.sort(compareNameAscending);
537
+ this.channels = event.channels.map(channel => bridgeContactToSdkContact(channel));
538
+ this.channels.sort(compareNameAscending);
539
+ if (event.emergencyChannel) {
540
+ this.emergencyChannel = bridgeContactToSdkContact(event.emergencyChannel);
541
+ }
542
+ this.emit(ZelloEvent.CONTACT_LIST_UPDATED, this.users, this.channels);
543
+ break;
544
+ }
545
+ case 'onSelectedContactChanged':
546
+ {
547
+ this.selectedContact = event.contact ? bridgeContactToSdkContact(event.contact) : undefined;
548
+ this.emit(ZelloEvent.SELECTED_CONTACT_CHANGED, this.selectedContact);
549
+ break;
550
+ }
551
+ case 'onAccountStatusChanged':
552
+ {
553
+ const statusValue = event.status?.toLowerCase();
554
+ if (!statusValue || Object.values(ZelloAccountStatus).includes(statusValue)) {
555
+ this.accountStatus = statusValue;
556
+ this.emit(ZelloEvent.ACCOUNT_STATUS_CHANGED, this.accountStatus);
557
+ }
558
+ break;
559
+ }
560
+ case 'onIncomingVoiceMessageStarted':
561
+ {
562
+ const contact = bridgeContactToSdkContact(event.contact);
563
+ if (!contact) {
564
+ break;
565
+ }
566
+ this.incomingVoiceMessage = new ZelloIncomingVoiceMessage(contact, new ZelloChannelUser(event.channelUserName), parseInt(event.timestamp, 10));
567
+ this.emit(ZelloEvent.INCOMING_VOICE_MESSAGE_STARTED, this.incomingVoiceMessage);
568
+ break;
569
+ }
570
+ case 'onIncomingVoiceMessageStopped':
571
+ {
572
+ this.incomingVoiceMessage = undefined;
573
+ const contact = bridgeContactToSdkContact(event.contact);
574
+ if (!contact) {
575
+ break;
576
+ }
577
+ this.emit(ZelloEvent.INCOMING_VOICE_MESSAGE_STOPPED, new ZelloIncomingVoiceMessage(contact, new ZelloChannelUser(event.channelUserName), parseInt(event.timestamp, 10)));
578
+ break;
579
+ }
580
+ case 'onOutgoingVoiceMessageConnecting':
581
+ {
582
+ const contact = bridgeContactToSdkContact(event.contact);
583
+ if (!contact) {
584
+ break;
585
+ }
586
+ this.outgoingVoiceMessage = new ZelloOutgoingVoiceMessage(contact, parseInt(event.timestamp, 10), ZelloOutgoingVoiceMessageState.Connecting);
587
+ this.emit(ZelloEvent.OUTGOING_VOICE_MESSAGE_CONNECTING, this.outgoingVoiceMessage);
588
+ break;
589
+ }
590
+ case 'onOutgoingVoiceMessageStarted':
591
+ {
592
+ const contact = bridgeContactToSdkContact(event.contact);
593
+ if (!contact) {
594
+ break;
595
+ }
596
+ this.outgoingVoiceMessage = new ZelloOutgoingVoiceMessage(contact, parseInt(event.timestamp, 10), ZelloOutgoingVoiceMessageState.Sending);
597
+ this.emit(ZelloEvent.OUTGOING_VOICE_MESSAGE_STARTED, this.outgoingVoiceMessage);
598
+ break;
599
+ }
600
+ case 'onOutgoingVoiceMessageStopped':
601
+ {
602
+ this.outgoingVoiceMessage = undefined;
603
+ const contact = bridgeContactToSdkContact(event.contact);
604
+ if (!contact) {
605
+ break;
606
+ }
607
+ const isError = event.error != null; // This checks for both null and undefined
608
+ let error;
609
+ if (isError) {
610
+ error = event.error?.toLowerCase() ?? ZelloOutgoingVoiceMessageError.Unknown;
611
+ }
612
+ this.emit(ZelloEvent.OUTGOING_VOICE_MESSAGE_STOPPED, new ZelloOutgoingVoiceMessage(contact, parseInt(event.timestamp, 10), isError ? ZelloOutgoingVoiceMessageState.Failed : ZelloOutgoingVoiceMessageState.Sent), error);
613
+ break;
614
+ }
615
+ case 'onIncomingImageMessage':
616
+ {
617
+ const contact = bridgeContactToSdkContact(event.contact);
618
+ if (!contact) {
619
+ break;
620
+ }
621
+ this.emit(ZelloEvent.INCOMING_IMAGE_MESSAGE_RECEIVED, new ZelloImageMessage(contact, new ZelloChannelUser(event.channelUserName), true, parseInt(event.timestamp, 10), event.thumbnail, event.image));
622
+ break;
623
+ }
624
+ case 'onOutgoingImageMessageSent':
625
+ {
626
+ const contact = bridgeContactToSdkContact(event.contact);
627
+ if (!contact) {
628
+ break;
629
+ }
630
+ this.emit(ZelloEvent.OUTGOING_IMAGE_MESSAGE_SENT, new ZelloImageMessage(contact, undefined, false, parseInt(event.timestamp, 10), event.thumbnail, event.image));
631
+ break;
632
+ }
633
+ case 'onOutgoingImageMessageSendFailed':
634
+ {
635
+ const contact = bridgeContactToSdkContact(event.contact);
636
+ if (!contact) {
637
+ break;
638
+ }
639
+ this.emit(ZelloEvent.OUTGOING_IMAGE_MESSAGE_SEND_FAILED, new ZelloImageMessage(contact, undefined, false, parseInt(event.timestamp, 10), event.thumbnail, event.image));
640
+ break;
641
+ }
642
+ case 'onIncomingAlertMessage':
643
+ {
644
+ const contact = bridgeContactToSdkContact(event.contact);
645
+ if (!contact) {
646
+ break;
647
+ }
648
+ this.emit(ZelloEvent.INCOMING_ALERT_MESSAGE_RECEIVED, new ZelloAlertMessage(contact, new ZelloChannelUser(event.channelUserName), true, parseInt(event.timestamp, 10), event.text));
649
+ break;
650
+ }
651
+ case 'onOutgoingAlertMessageSent':
652
+ {
653
+ const contact = bridgeContactToSdkContact(event.contact);
654
+ if (!contact) {
655
+ break;
656
+ }
657
+ this.emit(ZelloEvent.OUTGOING_ALERT_MESSAGE_SENT, new ZelloAlertMessage(contact, undefined, false, parseInt(event.timestamp, 10), event.text));
658
+ break;
659
+ }
660
+ case 'onOutgoingAlertMessageSendFailed':
661
+ {
662
+ const contact = bridgeContactToSdkContact(event.contact);
663
+ if (!contact) {
664
+ break;
665
+ }
666
+ this.emit(ZelloEvent.OUTGOING_ALERT_MESSAGE_SEND_FAILED, new ZelloAlertMessage(contact, undefined, false, parseInt(event.timestamp, 10), event.text));
667
+ break;
668
+ }
669
+ case 'onIncomingTextMessage':
670
+ {
671
+ const contact = bridgeContactToSdkContact(event.contact);
672
+ if (!contact) {
673
+ break;
674
+ }
675
+ this.emit(ZelloEvent.INCOMING_TEXT_MESSAGE_RECEIVED, new ZelloTextMessage(contact, new ZelloChannelUser(event.channelUserName), true, parseInt(event.timestamp, 10), event.text));
676
+ break;
677
+ }
678
+ case 'onOutgoingTextMessageSent':
679
+ {
680
+ const contact = bridgeContactToSdkContact(event.contact);
681
+ if (!contact) {
682
+ break;
683
+ }
684
+ this.emit(ZelloEvent.OUTGOING_TEXT_MESSAGE_SENT, new ZelloTextMessage(contact, undefined, false, parseInt(event.timestamp, 10), event.text));
685
+ break;
686
+ }
687
+ case 'onOutgoingTextMessageSendFailed':
688
+ {
689
+ const contact = bridgeContactToSdkContact(event.contact);
690
+ if (!contact) {
691
+ break;
692
+ }
693
+ this.emit(ZelloEvent.OUTGOING_TEXT_MESSAGE_SEND_FAILED, new ZelloTextMessage(contact, undefined, false, parseInt(event.timestamp, 10), event.text));
694
+ break;
695
+ }
696
+ case 'onIncomingLocationMessage':
697
+ {
698
+ const contact = bridgeContactToSdkContact(event.contact);
699
+ if (!contact) {
700
+ break;
701
+ }
702
+ this.emit(ZelloEvent.INCOMING_LOCATION_MESSAGE_RECEIVED, new ZelloLocationMessage(contact, new ZelloChannelUser(event.channelUserName), true, parseInt(event.timestamp, 10), event.latitude, event.longitude, event.accuracy, event.address).contact);
703
+ break;
704
+ }
705
+ case 'onOutgoingLocationMessageSent':
706
+ {
707
+ const contact = bridgeContactToSdkContact(event.contact);
708
+ if (!contact) {
709
+ break;
710
+ }
711
+ this.emit(ZelloEvent.OUTGOING_LOCATION_MESSAGE_SENT, new ZelloLocationMessage(contact, undefined, false, parseInt(event.timestamp, 10), event.latitude, event.longitude, event.accuracy, event.address));
712
+ break;
713
+ }
714
+ case 'onOutgoingLocationMessageSendFailed':
715
+ {
716
+ const contact = bridgeContactToSdkContact(event.contact);
717
+ if (!contact) {
718
+ break;
719
+ }
720
+ this.emit(ZelloEvent.OUTGOING_LOCATION_MESSAGE_SEND_FAILED, new ZelloLocationMessage(contact, undefined, false, parseInt(event.timestamp, 10), event.latitude, event.longitude, event.accuracy, event.address));
721
+ break;
722
+ }
723
+ case 'onIncomingEmergencyStarted':
724
+ {
725
+ this.incomingEmergencies = [];
726
+ event.emergencies.forEach(emergency => {
727
+ const incomingEmergency = bridgeIncomingEmergencyToSdkIncomingEmergency(emergency);
728
+ if (incomingEmergency) {
729
+ this.incomingEmergencies.push(incomingEmergency);
730
+ }
731
+ });
732
+ this.incomingEmergencies.sort((a, b) => a.startTimestamp - b.startTimestamp);
733
+ this.emit(ZelloEvent.INCOMING_EMERGENCY_STARTED, bridgeIncomingEmergencyToSdkIncomingEmergency(event.emergency), this.incomingEmergencies);
734
+ break;
735
+ }
736
+ case 'onIncomingEmergencyStopped':
737
+ {
738
+ this.incomingEmergencies = [];
739
+ event.emergencies.forEach(emergency => {
740
+ const incomingEmergency = bridgeIncomingEmergencyToSdkIncomingEmergency(emergency);
741
+ if (incomingEmergency) {
742
+ this.incomingEmergencies.push(incomingEmergency);
743
+ }
744
+ });
745
+ this.emit(ZelloEvent.INCOMING_EMERGENCY_STOPPED, bridgeIncomingEmergencyToSdkIncomingEmergency(event.emergency));
746
+ break;
747
+ }
748
+ case 'onOutgoingEmergencyStarted':
749
+ {
750
+ const channel = bridgeContactToSdkContact(event.channel);
751
+ if (!channel) {
752
+ break;
753
+ }
754
+ this.outgoingEmergency = new ZelloOutgoingEmergency(channel, parseInt(event.startTimestamp, 10), undefined);
755
+ this.emit(ZelloEvent.OUTGOING_EMERGENCY_STARTED, this.outgoingEmergency);
756
+ break;
757
+ }
758
+ case 'onOutgoingEmergencyStopped':
759
+ {
760
+ const channel = bridgeContactToSdkContact(event.channel);
761
+ if (!channel) {
762
+ break;
763
+ }
764
+ this.outgoingEmergency = undefined;
765
+ this.emit(ZelloEvent.OUTGOING_EMERGENCY_STOPPED, new ZelloOutgoingEmergency(channel, parseInt(event.startTimestamp, 10), event.endTimestamp));
766
+ break;
767
+ }
768
+ case 'onRecentsUpdated':
769
+ {
770
+ this.recents = event.recents.map(recent => {
771
+ const contact = bridgeContactToSdkContact(recent.contact);
772
+ if (!contact) {
773
+ return undefined;
774
+ }
775
+ const channelUser = recent.channelUser ? new ZelloChannelUser(recent.channelUser) : undefined;
776
+ return new ZelloRecentEntry(contact, channelUser, parseInt(recent.timestamp, 10), recent.type.toLowerCase(), recent.incoming);
777
+ }).filter(recent => recent !== undefined);
778
+ this.emit(ZelloEvent.RECENTS_UPDATED, this.recents);
779
+ break;
780
+ }
781
+ case 'onHistoryUpdated':
782
+ {
783
+ this.emit(ZelloEvent.HISTORY_UPDATED);
784
+ break;
785
+ }
786
+ case 'onHistoryPlaybackStarted':
787
+ {
788
+ this.historyVoiceMessage = bridgeHistoryMessageToSdkHistoryMessage(event);
789
+ this.emit(ZelloEvent.HISTORY_PLAYBACK_STARTED, this.historyVoiceMessage);
790
+ break;
791
+ }
792
+ case 'onHistoryPlaybackStopped':
793
+ {
794
+ this.historyVoiceMessage = undefined;
795
+ this.emit(ZelloEvent.HISTORY_PLAYBACK_STOPPED, this.historyVoiceMessage);
796
+ break;
797
+ }
798
+ default:
799
+ break;
800
+ }
801
+ });
802
+ }
803
+ }, {
804
+ key: "clearContactList",
805
+ value: function clearContactList() {
806
+ this.users = [];
807
+ this.channels = [];
808
+ }
809
+ }], [{
810
+ key: "getInstance",
811
+ value: function getInstance() {
812
+ if (!Zello.instance) {
813
+ Zello.instance = new Zello();
814
+ }
815
+ return Zello.instance;
816
+ }
817
+ }, {
818
+ key: "getSdk",
819
+ value: function getSdk() {
820
+ if (isAndroid) {
821
+ return ZelloAndroidSdkModule;
822
+ }
823
+ return ZelloIOSSdkModule;
824
+ }
825
+ }]);
826
+ }(EventEmitter);
827
+ _Zello = Zello;
828
+ _defineProperty(Zello, "instance", void 0);
829
+ //# sourceMappingURL=index.js.map