@ermis-network/ermis-chat-sdk 2.0.0 → 2.0.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.
Files changed (54) hide show
  1. package/README.md +330 -0
  2. package/dist/encryption/index.browser.cjs +13045 -0
  3. package/dist/encryption/index.browser.cjs.map +1 -0
  4. package/dist/encryption/index.browser.mjs +12959 -0
  5. package/dist/encryption/index.browser.mjs.map +1 -0
  6. package/dist/encryption/index.cjs +13045 -0
  7. package/dist/encryption/index.cjs.map +1 -0
  8. package/dist/encryption/index.d.mts +3 -0
  9. package/dist/encryption/index.d.ts +3 -0
  10. package/dist/encryption/index.mjs +12959 -0
  11. package/dist/encryption/index.mjs.map +1 -0
  12. package/dist/index-CcvHIY5q.d.mts +4988 -0
  13. package/dist/index-CcvHIY5q.d.ts +4988 -0
  14. package/dist/index.browser.cjs +20192 -5766
  15. package/dist/index.browser.cjs.map +1 -1
  16. package/dist/index.browser.full-bundle.min.js +20 -16
  17. package/dist/index.browser.full-bundle.min.js.map +1 -1
  18. package/dist/index.browser.mjs +20106 -5731
  19. package/dist/index.browser.mjs.map +1 -1
  20. package/dist/index.cjs +20191 -5765
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/index.d.mts +15 -1337
  23. package/dist/index.d.ts +15 -1337
  24. package/dist/index.mjs +20106 -5731
  25. package/dist/index.mjs.map +1 -1
  26. package/dist/wasm_worker.worker.mjs +8 -4
  27. package/dist/wasm_worker.worker.mjs.map +1 -1
  28. package/package.json +21 -6
  29. package/public/e2ee-media-stream-worker.js +627 -0
  30. package/public/openmls_wasm_bg.wasm +0 -0
  31. package/src/attachment_utils.ts +0 -148
  32. package/src/auth.ts +0 -352
  33. package/src/channel.ts +0 -1879
  34. package/src/channel_state.ts +0 -612
  35. package/src/client.ts +0 -1759
  36. package/src/client_state.ts +0 -55
  37. package/src/connection.ts +0 -587
  38. package/src/ermis_call_node.ts +0 -1046
  39. package/src/errors.ts +0 -60
  40. package/src/events.ts +0 -46
  41. package/src/hevc_decoder_config.ts +0 -305
  42. package/src/index.ts +0 -17
  43. package/src/media_stream_receiver.ts +0 -593
  44. package/src/media_stream_sender.ts +0 -465
  45. package/src/shims/empty.ts +0 -1
  46. package/src/signal_message.ts +0 -171
  47. package/src/system_message.ts +0 -259
  48. package/src/token_manager.ts +0 -48
  49. package/src/types.ts +0 -594
  50. package/src/utils.ts +0 -553
  51. package/src/wasm/ermis_call_node_wasm.d.ts +0 -156
  52. package/src/wasm/ermis_call_node_wasm.js +0 -1568
  53. package/src/wasm_worker.ts +0 -219
  54. package/src/wasm_worker_proxy.ts +0 -244
@@ -1,259 +0,0 @@
1
- /**
2
- * Duration lookup: milliseconds → human-readable text.
3
- */
4
- const DURATION_MAP: Record<string, string> = {
5
- '10000': '10 seconds',
6
- '30000': '30 seconds',
7
- '60000': '1 minute',
8
- '300000': '5 minutes',
9
- '900000': '15 minutes',
10
- '3600000': '60 minutes',
11
- };
12
-
13
- /**
14
- * Resolve a user ID to a display name using the provided map.
15
- * Falls back to the raw userId if no entry is found.
16
- */
17
- function resolveUser(userId: string, userMap: Record<string, string>): string {
18
- return userMap[userId] ?? userId;
19
- }
20
-
21
- /**
22
- * Translation templates for system messages.
23
- * Placeholders: {{user}}, {{channel}}, {{type}}, {{duration}}, {{targetUser}}, {{admin}}
24
- */
25
- export interface SystemMessageTranslations {
26
- // Format IDs as keys
27
- '1'?: string;
28
- '2'?: string;
29
- '3'?: string;
30
- '4'?: string;
31
- '5'?: string;
32
- '6'?: string;
33
- '7'?: string;
34
- '8'?: string;
35
- '9'?: string;
36
- '10'?: string;
37
- '11'?: string;
38
- '12'?: string;
39
- '13'?: string;
40
- '14'?: string;
41
- '15_on'?: string;
42
- '15_off'?: string;
43
- '16'?: string;
44
- '17'?: string;
45
- '18'?: string;
46
- '19'?: string;
47
- '20'?: string;
48
-
49
- // Semantic aliases
50
- changeName?: string; // 1
51
- changeAvatar?: string; // 2
52
- changeDescription?: string; // 3
53
- removed?: string; // 4
54
- banned?: string; // 5
55
- unbanned?: string; // 6
56
- promoted?: string; // 7
57
- demoted?: string; // 8
58
- permissionsUpdated?: string; // 9
59
- joined?: string; // 10
60
- declined?: string; // 11
61
- left?: string; // 12
62
- clearedHistory?: string; // 13
63
- changeType?: string; // 14
64
- cooldownOn?: string; // 15_on
65
- cooldownOff?: string; // 15_off
66
- bannedWordsUpdated?: string; // 16
67
- added?: string; // 17
68
- adminTransfer?: string; // 18
69
- pinned?: string; // 19
70
- unpinned?: string; // 20
71
-
72
- public?: string;
73
- private?: string;
74
- userFallback?: string;
75
- adminFallback?: string;
76
- durationUnitMin?: string; // "minute" / "minutes"
77
- durationUnitSec?: string; // "second" / "seconds"
78
- }
79
-
80
- /**
81
- * Parse a raw system message string into a human-readable sentence.
82
- *
83
- * The raw format is: `"<formatId> <userID> [<param1> <param2> ...]"`
84
- *
85
- * @param value - Raw system message string from the server
86
- * @param userMap - Mapping of user IDs → display names
87
- * @param translations - Optional translation templates
88
- * @returns Parsed text, or the original string if the format is unknown
89
- */
90
- export function parseSystemMessage(
91
- value: string,
92
- userMap: Record<string, string>,
93
- translations?: SystemMessageTranslations,
94
- ): string {
95
- if (!value || typeof value !== 'string') return value ?? '';
96
-
97
- const trimmed = value.trim();
98
- if (!trimmed) return '';
99
-
100
- const parts = trimmed.split(' ');
101
- const formatId = parts[0];
102
- const userId = parts[1] ?? '';
103
- const userName = userId ? resolveUser(userId, userMap) : (translations?.userFallback ?? 'User');
104
-
105
- switch (formatId) {
106
- // 1: userName changed the channel name to channelName (may contain spaces)
107
- case '1': {
108
- const channelName = parts.slice(2).join(' ');
109
- const template = translations?.['1'] ?? translations?.changeName;
110
- if (template) {
111
- return template.replace('{{user}}', userName).replace('{{channel}}', channelName);
112
- }
113
- return `${userName} changed the channel name to ${channelName}.`;
114
- }
115
-
116
- // 2–13, 16–17: single-user actions
117
- case '2': {
118
- const template = translations?.['2'] ?? translations?.changeAvatar;
119
- if (template) return template.replace('{{user}}', userName);
120
- return `${userName} changed the channel avatar.`;
121
- }
122
- case '3': {
123
- const template = translations?.['3'] ?? translations?.changeDescription;
124
- if (template) return template.replace('{{user}}', userName);
125
- return `${userName} changed the channel description.`;
126
- }
127
- case '4': {
128
- const template = translations?.['4'] ?? translations?.removed;
129
- if (template) return template.replace('{{user}}', userName);
130
- return `${userName} was removed from the channel.`;
131
- }
132
- case '5': {
133
- const template = translations?.['5'] ?? translations?.banned;
134
- if (template) return template.replace('{{user}}', userName);
135
- return `${userName} was banned.`;
136
- }
137
- case '6': {
138
- const template = translations?.['6'] ?? translations?.unbanned;
139
- if (template) return template.replace('{{user}}', userName);
140
- return `${userName} was unbanned.`;
141
- }
142
- case '7': {
143
- const template = translations?.['7'] ?? translations?.promoted;
144
- if (template) return template.replace('{{user}}', userName);
145
- return `${userName} was promoted to moderator.`;
146
- }
147
- case '8': {
148
- const template = translations?.['8'] ?? translations?.demoted;
149
- if (template) return template.replace('{{user}}', userName);
150
- return `${userName} was demoted from moderator.`;
151
- }
152
- case '9': {
153
- const template = translations?.['9'] ?? translations?.permissionsUpdated;
154
- if (template) return template.replace('{{user}}', userName);
155
- return `${userName}'s permissions were updated.`;
156
- }
157
- case '10': {
158
- const template = translations?.['10'] ?? translations?.joined;
159
- if (template) return template.replace('{{user}}', userName);
160
- return `${userName} joined the channel.`;
161
- }
162
- case '11': {
163
- const template = translations?.['11'] ?? translations?.declined;
164
- if (template) return template.replace('{{user}}', userName);
165
- return `${userName} declined the channel invitation.`;
166
- }
167
- case '12': {
168
- const template = translations?.['12'] ?? translations?.left;
169
- if (template) return template.replace('{{user}}', userName);
170
- return `${userName} left the channel.`;
171
- }
172
- case '13': {
173
- const template = translations?.['13'] ?? translations?.clearedHistory;
174
- if (template) return template.replace('{{user}}', userName);
175
- return `${userName} cleared the chat history.`;
176
- }
177
-
178
- // 14: channel type change (true = public, false = private)
179
- case '14': {
180
- const rawType = parts[2] ?? '';
181
- const typeKey = rawType === 'true' ? 'public' : 'private';
182
- const channelType = translations?.[typeKey] ?? typeKey;
183
- const template = translations?.['14'] ?? translations?.changeType;
184
- if (template) {
185
- return template.replace('{{user}}', userName).replace('{{type}}', channelType);
186
- }
187
- return `${userName} changed the channel to ${channelType}.`;
188
- }
189
-
190
- case '15': {
191
- const duration = parts[2] ?? '0';
192
- if (duration === '0') {
193
- const template = translations?.['15_off'] ?? translations?.cooldownOff;
194
- if (template) return template.replace('{{user}}', userName);
195
- return `${userName} disabled cooldown.`;
196
- }
197
-
198
- let durationText = `${duration}ms`;
199
- const minLabel = translations?.durationUnitMin ?? 'minute';
200
- const secLabel = translations?.durationUnitSec ?? 'seconds';
201
-
202
- if (duration === '10000') durationText = `10 ${secLabel}`;
203
- else if (duration === '30000') durationText = `30 ${secLabel}`;
204
- else if (duration === '60000') durationText = `1 ${minLabel}`;
205
- else if (duration === '300000') durationText = `5 ${minLabel}`;
206
- else if (duration === '900000') durationText = `15 ${minLabel}`;
207
- else if (duration === '3600000') durationText = `60 ${minLabel}`;
208
-
209
- const template = translations?.['15_on'] ?? translations?.cooldownOn;
210
- if (template) {
211
- return template.replace('{{user}}', userName).replace('{{duration}}', durationText);
212
- }
213
- return `${userName} enabled cooldown for ${durationText}.`;
214
- }
215
-
216
- case '16': {
217
- const template = translations?.['16'] ?? translations?.bannedWordsUpdated;
218
- if (template) return template.replace('{{user}}', userName);
219
- return `${userName} updated the banned words.`;
220
- }
221
- case '17': {
222
- const template = translations?.['17'] ?? translations?.added;
223
- if (template) return template.replace('{{user}}', userName);
224
- return `${userName} was added to the channel.`;
225
- }
226
-
227
- // 18: admin transfer (two user IDs)
228
- case '18': {
229
- const oldUserId = parts[1] ?? '';
230
- const newUserId = parts[2] ?? '';
231
- const oldUserName = oldUserId ? resolveUser(oldUserId, userMap) : (translations?.userFallback ?? 'User');
232
- const newUserName = newUserId ? resolveUser(newUserId, userMap) : (translations?.userFallback ?? 'User');
233
- const adminLabel = translations?.adminFallback ?? 'Admin';
234
- const template = translations?.['18'] ?? translations?.adminTransfer;
235
- if (template) {
236
- return template
237
- .replace('{{user}}', oldUserName)
238
- .replace('{{targetUser}}', newUserName)
239
- .replace('{{admin}}', adminLabel);
240
- }
241
- return `${adminLabel} ${oldUserName} left and assigned ${newUserName} as the new admin.`;
242
- }
243
-
244
- // 19–20: pin / unpin (userId + msgID)
245
- case '19': {
246
- const template = translations?.['19'] ?? translations?.pinned;
247
- if (template) return template.replace('{{user}}', userName);
248
- return `${userName} pinned a message.`;
249
- }
250
- case '20': {
251
- const template = translations?.['20'] ?? translations?.unpinned;
252
- if (template) return template.replace('{{user}}', userName);
253
- return `${userName} unpinned a message.`;
254
- }
255
-
256
- default:
257
- return trimmed;
258
- }
259
- }
@@ -1,48 +0,0 @@
1
- import { ExtendableGenerics, DefaultGenerics, UserResponse } from './types';
2
-
3
- /**
4
- * TokenManager
5
- *
6
- * Manages token storage and retrieval for the chat client.
7
- */
8
- export class TokenManager<ErmisChatGenerics extends ExtendableGenerics = DefaultGenerics> {
9
- loadTokenPromise: Promise<string> | null;
10
- token?: string;
11
- user?: UserResponse<ErmisChatGenerics>;
12
-
13
- constructor() {
14
- this.loadTokenPromise = null;
15
- }
16
-
17
- /**
18
- * Set the static string token.
19
- */
20
- setTokenOrProvider = async (tokenOrProvider: string | null, user: UserResponse<ErmisChatGenerics>) => {
21
- this.user = user;
22
-
23
- if (typeof tokenOrProvider === 'string') {
24
- this.token = tokenOrProvider;
25
- }
26
-
27
- this.loadTokenPromise = Promise.resolve(this.token as string);
28
- };
29
-
30
- /**
31
- * Resets the token manager.
32
- */
33
- reset = () => {
34
- this.token = undefined;
35
- this.user = undefined;
36
- this.loadTokenPromise = null;
37
- };
38
-
39
- /**
40
- * Resolves when token is ready.
41
- */
42
- tokenReady = () => this.loadTokenPromise;
43
-
44
- /** Returns the current token */
45
- getToken = () => {
46
- return this.token;
47
- };
48
- }