mediasfu-shared 1.0.3 → 1.0.5

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 CHANGED
@@ -1,103 +1,108 @@
1
- # mediasfu-shared
2
-
3
- `mediasfu-shared` is the framework-agnostic MediaSFU runtime package. It exposes the shared room helpers, mediasoup/socket flows, state utilities, and TypeScript types used by the MediaSFU SDK family.
4
-
5
- ## When To Use This Package
6
-
7
- Use `mediasfu-shared` when you want to:
8
-
9
- - build your own browser client on top of MediaSFU primitives without adopting a framework-specific UI package
10
- - share MediaSFU room, media, and participant logic across React, Vue, Angular, Svelte, or plain TypeScript codebases
11
- - import low-level helpers such as `createRoomOnMediaSFU`, `joinRoomOnMediaSFU`, `connectSocket`, `SocketManager`, and the exported consumers, methods, and types entry points
12
-
13
- ## Installation
14
-
15
- ```bash
16
- npm install mediasfu-shared mediasoup-client socket.io-client
17
- ```
18
-
19
- `mediasoup-client` and `socket.io-client` are peer dependencies, so install them in the host app.
20
-
21
- ## Backend Requirement
22
-
23
- The cloud room helpers in this package target `https://mediasfu.com/v1/rooms/` by default.
24
-
25
- - Use MediaSFU Cloud when you want managed room creation, signaling, and media routing. Pass `apiUserName` and `apiKey`.
26
- - Use MediaSFU Open / Community Edition when you self-host. Pass a non-MediaSFU `localLink` such as `http://localhost:3000`.
27
-
28
- ## Quick Example
29
-
30
- ```ts
31
- import {
32
- SocketManager,
33
- connectSocket,
34
- createRoomOnMediaSFU,
35
- joinRoomOnMediaSFU,
36
- } from 'mediasfu-shared';
37
-
38
- const createResult = await createRoomOnMediaSFU({
39
- payload: {
40
- action: 'create',
41
- userName: 'Ada',
42
- duration: 60,
43
- capacity: 10,
44
- },
45
- apiUserName: 'your-api-username',
46
- apiKey: 'your-64-character-api-key',
47
- });
48
-
49
- const joinResult = await joinRoomOnMediaSFU({
50
- payload: {
51
- action: 'join',
52
- meetingID: 'room123',
53
- userName: 'Ben',
54
- },
55
- apiUserName: 'your-api-username',
56
- apiKey: 'your-64-character-api-key',
57
- });
58
-
59
- const socket = await connectSocket({
60
- apiUserName: 'your-api-username',
61
- apiKey: 'your-64-character-api-key',
62
- apiToken: 'your-api-token',
63
- link: 'https://mediasfu.com/socket',
64
- });
65
-
66
- const socketManager = new SocketManager({ socket });
67
-
68
- console.log(createResult.success, joinResult.success, socketManager.socket.connected);
69
- ```
70
-
71
- ## Import Paths
72
-
73
- - `mediasfu-shared` exposes the full public runtime surface.
74
- - `mediasfu-shared/consumers` is useful when you want consumer/grid helpers only.
75
- - `mediasfu-shared/methods` is useful when you want action utilities and room helpers.
76
- - `mediasfu-shared/types` is useful when you only need TypeScript contracts.
77
-
78
- ## Documentation
79
-
80
- - Main docs: [https://mediasfu.com/documentation](https://mediasfu.com/documentation)
81
- - User guide: [https://mediasfu.com/user-guide](https://mediasfu.com/user-guide)
82
- - MediaSFU Open / CE: [https://github.com/MediaSFU/MediaSFUOpen](https://github.com/MediaSFU/MediaSFUOpen)
83
-
84
- Generate package-local API docs with:
85
-
86
- ```bash
87
- npm run build-docs
88
- ```
89
-
90
- ## Related Packages
91
-
92
- - [mediasfu-reactjs](https://www.npmjs.com/package/mediasfu-reactjs)
93
- - [mediasfu-vue](https://www.npmjs.com/package/mediasfu-vue)
94
- - [mediasfu-angular](https://www.npmjs.com/package/mediasfu-angular)
95
-
96
- ## Support
97
-
98
- - GitHub issues: [https://github.com/MediaSFU/MediaSFU-Shared/issues](https://github.com/MediaSFU/MediaSFU-Shared/issues)
99
- - Email: info@mediasfu.com
100
-
101
- ## License
102
-
103
- MIT. See [LICENSE](LICENSE).
1
+ # mediasfu-shared · [mediasfu-shared on npm](https://www.npmjs.com/package/mediasfu-shared)
2
+
3
+ **mediasfu-shared** is the framework-agnostic WebRTC runtime at the core of the MediaSFU SDK family. It provides shared room helpers, mediasoup signaling, socket management, media state utilities, and TypeScript types for React, Vue, Angular, Svelte, and plain TypeScript. Install with `npm install mediasfu-shared`.
4
+
5
+ `mediasfu-shared` is the framework-agnostic MediaSFU runtime package. It exposes the shared room helpers, mediasoup/socket flows, state utilities, and TypeScript types used by the MediaSFU SDK family.
6
+
7
+ ## When To Use This Package
8
+
9
+ Use `mediasfu-shared` when you want to:
10
+
11
+ - build your own browser client on top of MediaSFU primitives without adopting a framework-specific UI package
12
+ - share MediaSFU room, media, and participant logic across React, Vue, Angular, Svelte, or plain TypeScript codebases
13
+ - import low-level helpers such as `createRoomOnMediaSFU`, `joinRoomOnMediaSFU`, `connectSocket`, `SocketManager`, and the exported consumers, methods, and types entry points
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install mediasfu-shared mediasoup-client socket.io-client
19
+ ```
20
+
21
+ `mediasoup-client` and `socket.io-client` are peer dependencies, so install them in the host app.
22
+
23
+ ## Backend Requirement
24
+
25
+ The cloud room helpers in this package target `https://mediasfu.com/v1/rooms/` by default.
26
+
27
+ - Use MediaSFU Cloud when you want managed room creation, signaling, and media routing. Pass `apiUserName` and `apiKey`.
28
+ - Use MediaSFU Open / Community Edition when you self-host. Pass a non-MediaSFU `localLink` such as `http://localhost:3000`.
29
+
30
+ ## Quick Example
31
+
32
+ ```ts
33
+ import {
34
+ SocketManager,
35
+ connectSocket,
36
+ createRoomOnMediaSFU,
37
+ joinRoomOnMediaSFU,
38
+ } from 'mediasfu-shared';
39
+
40
+ const createResult = await createRoomOnMediaSFU({
41
+ payload: {
42
+ action: 'create',
43
+ userName: 'Ada',
44
+ duration: 60,
45
+ capacity: 10,
46
+ },
47
+ apiUserName: 'your-api-username',
48
+ apiKey: 'your-64-character-api-key',
49
+ });
50
+
51
+ const joinResult = await joinRoomOnMediaSFU({
52
+ payload: {
53
+ action: 'join',
54
+ meetingID: 'room123',
55
+ userName: 'Ben',
56
+ },
57
+ apiUserName: 'your-api-username',
58
+ apiKey: 'your-64-character-api-key',
59
+ });
60
+
61
+ const socket = await connectSocket({
62
+ apiUserName: 'your-api-username',
63
+ apiKey: 'your-64-character-api-key',
64
+ apiToken: 'your-api-token',
65
+ link: 'https://mediasfu.com/socket',
66
+ });
67
+
68
+ const socketManager = new SocketManager({ socket });
69
+
70
+ console.log(createResult.success, joinResult.success, socketManager.socket.connected);
71
+ ```
72
+
73
+ ## Import Paths
74
+
75
+ - `mediasfu-shared` exposes the full public runtime surface.
76
+ - `mediasfu-shared/consumers` is useful when you want consumer/grid helpers only.
77
+ - `mediasfu-shared/methods` is useful when you want action utilities and room helpers.
78
+ - `mediasfu-shared/types` is useful when you only need TypeScript contracts.
79
+
80
+ ## Documentation
81
+
82
+ - Main docs: [https://mediasfu.com/documentation](https://mediasfu.com/documentation)
83
+ - User guide: [https://mediasfu.com/user-guide](https://mediasfu.com/user-guide)
84
+ - MediaSFU Open / CE: [https://github.com/MediaSFU/MediaSFUOpen](https://github.com/MediaSFU/MediaSFUOpen)
85
+
86
+ Generate package-local API docs with:
87
+
88
+ ```bash
89
+ npm run build-docs
90
+ ```
91
+
92
+ ## Related Packages
93
+
94
+ | Package | Framework | npm |
95
+ |---------|-----------|-----|
96
+ | [mediasfu-reactjs](https://github.com/MediaSFU/MediaSFU-ReactJS) | React 18/19 | [`npm install mediasfu-reactjs`](https://www.npmjs.com/package/mediasfu-reactjs) |
97
+ | [mediasfu-vue](https://github.com/MediaSFU/MediaSFU-Vue) | Vue 3 / Composition API | [`npm install mediasfu-vue`](https://www.npmjs.com/package/mediasfu-vue) |
98
+ | [mediasfu-angular](https://github.com/MediaSFU/MediaSFU-Angular) | Angular 17/18/19 | [`npm install mediasfu-angular`](https://www.npmjs.com/package/mediasfu-angular) |
99
+ | [mediasfu-reactnative](https://www.npmjs.com/package/mediasfu-reactnative) | React Native | [`npm install mediasfu-reactnative`](https://www.npmjs.com/package/mediasfu-reactnative) |
100
+
101
+ ## Support
102
+
103
+ - GitHub issues: [https://github.com/MediaSFU/MediaSFU-Shared/issues](https://github.com/MediaSFU/MediaSFU-Shared/issues)
104
+ - Email: info@mediasfu.com
105
+
106
+ ## License
107
+
108
+ MIT. See [LICENSE](LICENSE).
package/dist/index.cjs CHANGED
@@ -6368,6 +6368,7 @@ const updateRoomParametersClient = ({ parameters }) => {
6368
6368
  }
6369
6369
  };
6370
6370
  const DEFAULT_MEDIA_SFU_ROOM_API_URL = "https://mediasfu.com/v1/rooms/";
6371
+ const getDefaultMediaSFURoomApiUrl = () => DEFAULT_MEDIA_SFU_ROOM_API_URL;
6371
6372
  const normalizeManagedRoomApi = (normalizedLink) => {
6372
6373
  if (normalizedLink.includes("/v1/rooms")) {
6373
6374
  return `${normalizedLink.replace(/\/$/, "")}/`;
@@ -6377,7 +6378,7 @@ const normalizeManagedRoomApi = (normalizedLink) => {
6377
6378
  const resolveMediaSFURoomApi = (localLink, action) => {
6378
6379
  const normalizedLink = localLink?.trim();
6379
6380
  if (!normalizedLink) {
6380
- return DEFAULT_MEDIA_SFU_ROOM_API_URL;
6381
+ return getDefaultMediaSFURoomApiUrl();
6381
6382
  }
6382
6383
  if (normalizedLink.includes("mediasfu.com")) {
6383
6384
  return normalizeManagedRoomApi(normalizedLink);
@@ -7917,6 +7918,9 @@ const sendMessage = async ({
7917
7918
  chatSetting
7918
7919
  }) => {
7919
7920
  let chatValue = false;
7921
+ const normalizedReceivers = (receivers ?? []).filter(
7922
+ (receiver) => typeof receiver === "string" && receiver.trim().length > 0
7923
+ );
7920
7924
  if (messagesLength > 100 && roomName.startsWith("d") || messagesLength > 500 && roomName.startsWith("s") || messagesLength > 1e5 && roomName.startsWith("p")) {
7921
7925
  showAlert?.({
7922
7926
  message: "You have reached the maximum number of messages allowed.",
@@ -7933,7 +7937,7 @@ const sendMessage = async ({
7933
7937
  });
7934
7938
  return;
7935
7939
  }
7936
- if (receivers.length < 1 && group === false) {
7940
+ if (normalizedReceivers.length < 1 && group === false && islevel === "2") {
7937
7941
  showAlert?.({
7938
7942
  message: "Please select a message to reply to",
7939
7943
  type: "danger",
@@ -7943,7 +7947,7 @@ const sendMessage = async ({
7943
7947
  }
7944
7948
  const messageObject = {
7945
7949
  sender: sender ? sender : member,
7946
- receivers,
7950
+ receivers: normalizedReceivers,
7947
7951
  message,
7948
7952
  timestamp: (/* @__PURE__ */ new Date()).toLocaleTimeString(),
7949
7953
  group: group !== void 0 && group !== null ? group : false
@@ -10100,13 +10104,112 @@ const TTS_SUPPORT_BY_LANGUAGE = {
10100
10104
  ca: "good",
10101
10105
  auto: "n/a"
10102
10106
  };
10107
+ const LANGUAGE_NAMES_EN = {
10108
+ en: "English",
10109
+ es: "Spanish",
10110
+ fr: "French",
10111
+ de: "German",
10112
+ it: "Italian",
10113
+ pt: "Portuguese",
10114
+ nl: "Dutch",
10115
+ ru: "Russian",
10116
+ zh: "Chinese",
10117
+ ja: "Japanese",
10118
+ ko: "Korean",
10119
+ ar: "Arabic",
10120
+ hi: "Hindi",
10121
+ bn: "Bengali",
10122
+ pa: "Punjabi",
10123
+ te: "Telugu",
10124
+ mr: "Marathi",
10125
+ ta: "Tamil",
10126
+ ur: "Urdu",
10127
+ gu: "Gujarati",
10128
+ kn: "Kannada",
10129
+ ml: "Malayalam",
10130
+ ne: "Nepali",
10131
+ si: "Sinhala",
10132
+ tr: "Turkish",
10133
+ pl: "Polish",
10134
+ vi: "Vietnamese",
10135
+ th: "Thai",
10136
+ id: "Indonesian",
10137
+ ms: "Malay",
10138
+ tl: "Filipino",
10139
+ km: "Khmer",
10140
+ lo: "Lao",
10141
+ my: "Burmese",
10142
+ sw: "Swahili",
10143
+ yo: "Yoruba",
10144
+ ha: "Hausa",
10145
+ ig: "Igbo",
10146
+ zu: "Zulu",
10147
+ xh: "Xhosa",
10148
+ af: "Afrikaans",
10149
+ st: "Sesotho",
10150
+ tn: "Tswana",
10151
+ sn: "Shona",
10152
+ am: "Amharic",
10153
+ so: "Somali",
10154
+ rw: "Kinyarwanda",
10155
+ mg: "Malagasy",
10156
+ ny: "Chichewa",
10157
+ ee: "Ewe",
10158
+ tw: "Twi",
10159
+ gaa: "Ga",
10160
+ he: "Hebrew",
10161
+ fa: "Persian",
10162
+ ps: "Pashto",
10163
+ ku: "Kurdish",
10164
+ uk: "Ukrainian",
10165
+ el: "Greek",
10166
+ cs: "Czech",
10167
+ ro: "Romanian",
10168
+ hu: "Hungarian",
10169
+ sv: "Swedish",
10170
+ da: "Danish",
10171
+ no: "Norwegian",
10172
+ fi: "Finnish",
10173
+ sk: "Slovak",
10174
+ bg: "Bulgarian",
10175
+ hr: "Croatian",
10176
+ et: "Estonian",
10177
+ lt: "Lithuanian",
10178
+ lv: "Latvian",
10179
+ sl: "Slovenian",
10180
+ sr: "Serbian",
10181
+ bs: "Bosnian",
10182
+ mk: "Macedonian",
10183
+ is: "Icelandic",
10184
+ ga: "Irish",
10185
+ cy: "Welsh",
10186
+ mt: "Maltese",
10187
+ lb: "Luxembourgish",
10188
+ sq: "Albanian",
10189
+ be: "Belarusian",
10190
+ ka: "Georgian",
10191
+ hy: "Armenian",
10192
+ az: "Azerbaijani",
10193
+ eu: "Basque",
10194
+ gl: "Galician",
10195
+ ca: "Catalan",
10196
+ la: "Latin",
10197
+ eo: "Esperanto",
10198
+ kk: "Kazakh",
10199
+ uz: "Uzbek",
10200
+ tg: "Tajik",
10201
+ ky: "Kyrgyz",
10202
+ tk: "Turkmen",
10203
+ mn: "Mongolian"
10204
+ };
10103
10205
  const getDisplayName = (code, locale, fallback) => {
10104
10206
  try {
10105
10207
  const displayNames = new Intl.DisplayNames([locale], { type: "language" });
10106
- return displayNames.of(code) || fallback;
10208
+ const result = displayNames.of(code);
10209
+ if (result) return result;
10107
10210
  } catch {
10108
- return fallback;
10109
10211
  }
10212
+ return LANGUAGE_NAMES_EN[code] ?? fallback;
10110
10213
  };
10111
10214
  const normalizeLanguageCode = (code) => {
10112
10215
  if (!code || typeof code !== "string") {
@@ -10153,6 +10256,58 @@ const getSupportedLanguages = (displayLocale = "en") => {
10153
10256
  };
10154
10257
  }).sort((left, right) => left.name.localeCompare(right.name));
10155
10258
  };
10259
+ const COMMON_LANGUAGE_CODES = [
10260
+ "en",
10261
+ "es",
10262
+ "fr",
10263
+ "de",
10264
+ "it",
10265
+ "pt",
10266
+ "nl",
10267
+ "ru",
10268
+ "zh",
10269
+ "ja",
10270
+ "ko",
10271
+ "ar",
10272
+ "hi",
10273
+ "bn",
10274
+ "tr",
10275
+ "pl",
10276
+ "vi",
10277
+ "th",
10278
+ "id",
10279
+ "ms",
10280
+ "sw",
10281
+ "yo",
10282
+ "ha",
10283
+ "ig",
10284
+ "zu",
10285
+ "am",
10286
+ "tw",
10287
+ "he",
10288
+ "fa",
10289
+ "uk",
10290
+ "el",
10291
+ "cs",
10292
+ "ro",
10293
+ "hu",
10294
+ "sv",
10295
+ "da",
10296
+ "no",
10297
+ "fi"
10298
+ ];
10299
+ const getCommonLanguages = (displayLocale = "en") => {
10300
+ return COMMON_LANGUAGE_CODES.map((code) => {
10301
+ const metadata = getLanguageMetadata(code);
10302
+ return {
10303
+ code,
10304
+ name: getLanguageName(code, displayLocale),
10305
+ nativeName: metadata.nativeName,
10306
+ region: metadata.region,
10307
+ ttsSupport: metadata.ttsSupport
10308
+ };
10309
+ }).sort((left, right) => left.name.localeCompare(right.name));
10310
+ };
10156
10311
  const TTS_PROVIDERS = {
10157
10312
  deepgram: { name: "Deepgram Aura", supportsSSML: false, isDefault: true },
10158
10313
  openai: { name: "OpenAI TTS", supportsSSML: false, multilingual: true },
@@ -12893,6 +13048,7 @@ const launchConfigureWhiteboard = ({
12893
13048
  }) => {
12894
13049
  updateIsConfigureWhiteboardModalVisible(!isConfigureWhiteboardModalVisible);
12895
13050
  };
13051
+ exports.COMMON_LANGUAGE_CODES = COMMON_LANGUAGE_CODES;
12896
13052
  exports.MediaStream = MediaStream$1;
12897
13053
  exports.MediaStreamTrack = MediaStreamTrack;
12898
13054
  exports.QnHDCons = QnHDCons;
@@ -12980,6 +13136,7 @@ exports.generateRandomRequestList = generateRandomRequestList;
12980
13136
  exports.generateRandomWaitingRoomList = generateRandomWaitingRoomList;
12981
13137
  exports.getActiveTranslationConsumers = getActiveTranslationConsumers;
12982
13138
  exports.getAvailableVoices = getAvailableVoices;
13139
+ exports.getCommonLanguages = getCommonLanguages;
12983
13140
  exports.getDomains = getDomains;
12984
13141
  exports.getEstimate = getEstimate;
12985
13142
  exports.getLanguageMetadata = getLanguageMetadata;