@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.
- package/LICENSE +20 -0
- package/README.md +21 -0
- package/android/build.gradle +122 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/AndroidManifestNew.xml +2 -0
- package/android/src/main/java/com/zellosdk/DummyPackage.kt +18 -0
- package/android/src/main/java/com/zellosdk/ZelloAndroidSdkModule.kt +437 -0
- package/android/src/main/java/com/zellosdk/ZelloAndroidSdkModuleHelper.kt +198 -0
- package/ios/Extensions/Date+Extension.swift +5 -0
- package/ios/Extensions/UIImage+Extension.swift +9 -0
- package/ios/Extensions/ZelloContact+Extension.swift +52 -0
- package/ios/Extensions/ZelloHistoryAlertMessage+Extension.swift +18 -0
- package/ios/Extensions/ZelloHistoryImageMessage+Extension.swift +17 -0
- package/ios/Extensions/ZelloHistoryLocationMessage+Extension.swift +23 -0
- package/ios/Extensions/ZelloHistoryTextMessage+Extension.swift +18 -0
- package/ios/Extensions/ZelloHistoryVoiceMessage+Extension.swift +18 -0
- package/ios/Extensions/ZelloIOSSdkModule+Extension.swift +285 -0
- package/ios/Extensions/ZelloIncomingEmergency+Extension.swift +16 -0
- package/ios/Extensions/ZelloOutgoingEmergency+Extension.swift +14 -0
- package/ios/Extensions/ZelloRecentEntry+Extension.swift +16 -0
- package/ios/ZelloIOSSdkModule.swift +209 -0
- package/ios/ZelloIOSSdkModuleBridge.h +5 -0
- package/ios/ZelloIOSSdkModuleBridge.m +44 -0
- package/lib/commonjs/events/index.js +43 -0
- package/lib/commonjs/events/index.js.map +1 -0
- package/lib/commonjs/index.js +47 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/sdk/index.js +833 -0
- package/lib/commonjs/sdk/index.js.map +1 -0
- package/lib/commonjs/types/index.js +518 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/utils/algorithms/index.js +79 -0
- package/lib/commonjs/utils/algorithms/index.js.map +1 -0
- package/lib/commonjs/utils/index.js +60 -0
- package/lib/commonjs/utils/index.js.map +1 -0
- package/lib/module/events/index.js +39 -0
- package/lib/module/events/index.js.map +1 -0
- package/lib/module/index.js +10 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/sdk/index.js +829 -0
- package/lib/module/sdk/index.js.map +1 -0
- package/lib/module/types/index.js +547 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/utils/algorithms/index.js +72 -0
- package/lib/module/utils/algorithms/index.js.map +1 -0
- package/lib/module/utils/index.js +52 -0
- package/lib/module/utils/index.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/events/index.d.ts +192 -0
- package/lib/typescript/commonjs/src/events/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +6 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/sdk/index.d.ts +221 -0
- package/lib/typescript/commonjs/src/sdk/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/index.d.ts +560 -0
- package/lib/typescript/commonjs/src/types/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/algorithms/index.d.ts +21 -0
- package/lib/typescript/commonjs/src/utils/algorithms/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/index.d.ts +8 -0
- package/lib/typescript/commonjs/src/utils/index.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/src/events/index.d.ts +192 -0
- package/lib/typescript/module/src/events/index.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +6 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/sdk/index.d.ts +221 -0
- package/lib/typescript/module/src/sdk/index.d.ts.map +1 -0
- package/lib/typescript/module/src/types/index.d.ts +560 -0
- package/lib/typescript/module/src/types/index.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/algorithms/index.d.ts +21 -0
- package/lib/typescript/module/src/utils/algorithms/index.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/index.d.ts +8 -0
- package/lib/typescript/module/src/utils/index.d.ts.map +1 -0
- package/package.json +195 -0
- package/react-native-zello-sdk.podspec +43 -0
- package/src/events/index.ts +191 -0
- package/src/index.ts +8 -0
- package/src/sdk/index.ts +1038 -0
- package/src/types/index.ts +818 -0
- package/src/utils/algorithms/index.ts +88 -0
- package/src/utils/index.ts +145 -0
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ZelloContact } from '../../types';
|
|
2
|
+
import { isString } from 'lodash';
|
|
3
|
+
|
|
4
|
+
export function sortedArrayFind<T>(
|
|
5
|
+
array: readonly T[],
|
|
6
|
+
item: any,
|
|
7
|
+
comparator: (item: any, arrayElement: T) => number
|
|
8
|
+
): T | undefined {
|
|
9
|
+
const i = lowerBound(array, item, comparator);
|
|
10
|
+
if (i >= 0 && i < array.length && comparator(item, array[i]) === 0) {
|
|
11
|
+
return array[i];
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function lowerBound<T>(
|
|
17
|
+
array: readonly T[],
|
|
18
|
+
item: any,
|
|
19
|
+
comparator: (item: any, arrayElement: T) => number
|
|
20
|
+
): number {
|
|
21
|
+
let index = binarySearch(array, item, comparator);
|
|
22
|
+
// binarySearch returns the non-negative index of the item, or a negative index which is the -index - 1 where the item would be inserted
|
|
23
|
+
if (index < 0) {
|
|
24
|
+
index = -index - 1;
|
|
25
|
+
}
|
|
26
|
+
// Several identical objects may exist in the same collection; we need to find the first one
|
|
27
|
+
if (index > 0 && index < array.length) {
|
|
28
|
+
const foundObject = array[index];
|
|
29
|
+
while (index > 0) {
|
|
30
|
+
if (comparator(array[index - 1], foundObject) !== 0) {
|
|
31
|
+
break;
|
|
32
|
+
}
|
|
33
|
+
--index;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return index;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Binary search algorithm adapted from https://stackoverflow.com/a/29018745.
|
|
41
|
+
*
|
|
42
|
+
* The array may contain duplicate items. If there are more than one equal items in the array,
|
|
43
|
+
* the returned value can be the index of any one of the equal items.
|
|
44
|
+
*
|
|
45
|
+
* Time complexity: O(log n)
|
|
46
|
+
* @param array A sorted array.
|
|
47
|
+
* @param item An item to search for.
|
|
48
|
+
* @param comparator A comparator function. The function takes two arguments: (a, b) and returns:
|
|
49
|
+
* a negative number if a is less than b;
|
|
50
|
+
* 0 if a is equal to b;
|
|
51
|
+
* a positive number of a is greater than b.
|
|
52
|
+
* @return The index of the item in a sorted array or (-n-1) where n is the insertion point for the new item.
|
|
53
|
+
*/
|
|
54
|
+
export function binarySearch<T>(
|
|
55
|
+
array: readonly T[],
|
|
56
|
+
item: any,
|
|
57
|
+
comparator: (item: any, arrayElement: T) => number
|
|
58
|
+
): number {
|
|
59
|
+
let m = 0;
|
|
60
|
+
let n = array.length - 1;
|
|
61
|
+
while (m <= n) {
|
|
62
|
+
const k = (n + m) >> 1;
|
|
63
|
+
const cmp = comparator(item, array[k]);
|
|
64
|
+
if (cmp > 0) {
|
|
65
|
+
m = k + 1;
|
|
66
|
+
} else if (cmp < 0) {
|
|
67
|
+
n = k - 1;
|
|
68
|
+
} else {
|
|
69
|
+
return k;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return -m - 1;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function compareNameAscending(
|
|
76
|
+
a: ZelloContact | string,
|
|
77
|
+
b: ZelloContact | string
|
|
78
|
+
): number {
|
|
79
|
+
const alc = isString(a) ? a.toLowerCase() : a.name.toLowerCase();
|
|
80
|
+
const blc = isString(b) ? b.toLowerCase() : b.name.toLowerCase();
|
|
81
|
+
if (alc > blc) {
|
|
82
|
+
return 1;
|
|
83
|
+
}
|
|
84
|
+
if (alc < blc) {
|
|
85
|
+
return -1;
|
|
86
|
+
}
|
|
87
|
+
return 0;
|
|
88
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ZelloChannel,
|
|
3
|
+
ZelloChannelConnectionStatus,
|
|
4
|
+
ZelloChannelUser,
|
|
5
|
+
ZelloContact,
|
|
6
|
+
ZelloHistoryAlertMessage,
|
|
7
|
+
ZelloHistoryImageMessage,
|
|
8
|
+
ZelloHistoryLocationMessage,
|
|
9
|
+
ZelloHistoryMessage,
|
|
10
|
+
ZelloHistoryTextMessage,
|
|
11
|
+
ZelloHistoryVoiceMessage,
|
|
12
|
+
ZelloIncomingEmergency,
|
|
13
|
+
ZelloUser,
|
|
14
|
+
ZelloUserStatus,
|
|
15
|
+
} from '../types';
|
|
16
|
+
import { Platform } from 'react-native';
|
|
17
|
+
|
|
18
|
+
export const isSameContact = (a: ZelloContact, b: ZelloContact): boolean =>
|
|
19
|
+
a.name.toLowerCase() === b.name.toLowerCase() && a.type === b.type;
|
|
20
|
+
|
|
21
|
+
export const isAndroid = Platform.OS === 'android';
|
|
22
|
+
export const isiOS = Platform.OS === 'ios';
|
|
23
|
+
|
|
24
|
+
export function bridgeContactToSdkContact(
|
|
25
|
+
eventContact: any
|
|
26
|
+
): ZelloContact | undefined {
|
|
27
|
+
let contact: ZelloContact | undefined;
|
|
28
|
+
const contactName = eventContact.name;
|
|
29
|
+
if (contactName) {
|
|
30
|
+
if (eventContact.isChannel) {
|
|
31
|
+
contact = new ZelloChannel(
|
|
32
|
+
contactName,
|
|
33
|
+
eventContact.isMuted,
|
|
34
|
+
eventContact.isConnected
|
|
35
|
+
? ZelloChannelConnectionStatus.Connected
|
|
36
|
+
: eventContact.isConnecting
|
|
37
|
+
? ZelloChannelConnectionStatus.Connecting
|
|
38
|
+
: ZelloChannelConnectionStatus.Disconnected,
|
|
39
|
+
eventContact.usersOnline,
|
|
40
|
+
eventContact.options
|
|
41
|
+
);
|
|
42
|
+
} else {
|
|
43
|
+
const statusValue = eventContact.status.toLowerCase() as ZelloUserStatus;
|
|
44
|
+
let userStatus = ZelloUserStatus.Offline;
|
|
45
|
+
if (Object.values(ZelloUserStatus).includes(statusValue)) {
|
|
46
|
+
userStatus = statusValue;
|
|
47
|
+
}
|
|
48
|
+
contact = new ZelloUser(
|
|
49
|
+
contactName,
|
|
50
|
+
eventContact.displayName,
|
|
51
|
+
eventContact.isMuted,
|
|
52
|
+
userStatus,
|
|
53
|
+
eventContact.profilePictureUrl,
|
|
54
|
+
eventContact.profilePictureThumbnailUrl
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return contact;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function bridgeIncomingEmergencyToSdkIncomingEmergency(
|
|
62
|
+
emergency: any
|
|
63
|
+
): ZelloIncomingEmergency | undefined {
|
|
64
|
+
const channel = bridgeContactToSdkContact(emergency.channel) as ZelloChannel;
|
|
65
|
+
if (!channel) {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
return new ZelloIncomingEmergency(
|
|
69
|
+
channel,
|
|
70
|
+
new ZelloChannelUser(emergency.channelUserName),
|
|
71
|
+
emergency.emergencyId,
|
|
72
|
+
parseInt(emergency.startTimestamp, 10),
|
|
73
|
+
parseInt(emergency.endTimestamp, 10)
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function bridgeHistoryMessageToSdkHistoryMessage(
|
|
78
|
+
message: any
|
|
79
|
+
): ZelloHistoryMessage | undefined {
|
|
80
|
+
const contact = bridgeContactToSdkContact(message.contact);
|
|
81
|
+
if (!contact) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
switch (message.type) {
|
|
85
|
+
case 'voice':
|
|
86
|
+
return new ZelloHistoryVoiceMessage(
|
|
87
|
+
contact,
|
|
88
|
+
message.channelUserName
|
|
89
|
+
? new ZelloChannelUser(message.channelUserName)
|
|
90
|
+
: undefined,
|
|
91
|
+
parseInt(message.timestamp, 10),
|
|
92
|
+
message.historyId,
|
|
93
|
+
message.incoming,
|
|
94
|
+
message.durationMs
|
|
95
|
+
);
|
|
96
|
+
case 'image':
|
|
97
|
+
return new ZelloHistoryImageMessage(
|
|
98
|
+
contact,
|
|
99
|
+
message.channelUserName
|
|
100
|
+
? new ZelloChannelUser(message.channelUserName)
|
|
101
|
+
: undefined,
|
|
102
|
+
parseInt(message.timestamp, 10),
|
|
103
|
+
message.historyId,
|
|
104
|
+
message.incoming
|
|
105
|
+
);
|
|
106
|
+
case 'location':
|
|
107
|
+
return new ZelloHistoryLocationMessage(
|
|
108
|
+
contact,
|
|
109
|
+
message.channelUserName
|
|
110
|
+
? new ZelloChannelUser(message.channelUserName)
|
|
111
|
+
: undefined,
|
|
112
|
+
parseInt(message.timestamp, 10),
|
|
113
|
+
message.historyId,
|
|
114
|
+
message.incoming,
|
|
115
|
+
message.latitude,
|
|
116
|
+
message.longitude,
|
|
117
|
+
message.accuracy,
|
|
118
|
+
message.address
|
|
119
|
+
);
|
|
120
|
+
case 'text':
|
|
121
|
+
return new ZelloHistoryTextMessage(
|
|
122
|
+
contact,
|
|
123
|
+
message.channelUserName
|
|
124
|
+
? new ZelloChannelUser(message.channelUserName)
|
|
125
|
+
: undefined,
|
|
126
|
+
parseInt(message.timestamp, 10),
|
|
127
|
+
message.historyId,
|
|
128
|
+
message.incoming,
|
|
129
|
+
message.text
|
|
130
|
+
);
|
|
131
|
+
case 'alert':
|
|
132
|
+
return new ZelloHistoryAlertMessage(
|
|
133
|
+
contact,
|
|
134
|
+
message.channelUserName
|
|
135
|
+
? new ZelloChannelUser(message.channelUserName)
|
|
136
|
+
: undefined,
|
|
137
|
+
parseInt(message.timestamp, 10),
|
|
138
|
+
message.historyId,
|
|
139
|
+
message.incoming,
|
|
140
|
+
message.text
|
|
141
|
+
);
|
|
142
|
+
default:
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
}
|