@videosdk.live/react-sdk 0.2.1 → 0.2.2

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/dist/index.js CHANGED
@@ -5,6 +5,54 @@ var React__default = _interopDefault(React);
5
5
  var EventEmitter = _interopDefault(require('events'));
6
6
  var jsSdk = require('@videosdk.live/js-sdk');
7
7
 
8
+ function _arrayLikeToArray(r, a) {
9
+ (null == a || a > r.length) && (a = r.length);
10
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
11
+ return n;
12
+ }
13
+ function _createForOfIteratorHelperLoose(r, e) {
14
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
15
+ if (t) return (t = t.call(r)).next.bind(t);
16
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
17
+ t && (r = t);
18
+ var o = 0;
19
+ return function () {
20
+ return o >= r.length ? {
21
+ done: !0
22
+ } : {
23
+ done: !1,
24
+ value: r[o++]
25
+ };
26
+ };
27
+ }
28
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
29
+ }
30
+ function _extends() {
31
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
32
+ for (var e = 1; e < arguments.length; e++) {
33
+ var t = arguments[e];
34
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
35
+ }
36
+ return n;
37
+ }, _extends.apply(null, arguments);
38
+ }
39
+ function _objectWithoutPropertiesLoose(r, e) {
40
+ if (null == r) return {};
41
+ var t = {};
42
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
43
+ if (-1 !== e.indexOf(n)) continue;
44
+ t[n] = r[n];
45
+ }
46
+ return t;
47
+ }
48
+ function _unsupportedIterableToArray(r, a) {
49
+ if (r) {
50
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
51
+ var t = {}.toString.call(r).slice(8, -1);
52
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
53
+ }
54
+ }
55
+
8
56
  var eventPrifix = 'videosdk-live-react-sdk';
9
57
  var events = {
10
58
  'participant-joined': eventPrifix + "-participant-joined",
@@ -47,6 +95,19 @@ var events = {
47
95
  };
48
96
  var eventEmitter = new EventEmitter();
49
97
  eventEmitter.setMaxListeners(9999);
98
+ function debounce(func, delay) {
99
+ var timeout;
100
+ return function () {
101
+ var _this = this;
102
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
103
+ args[_key] = arguments[_key];
104
+ }
105
+ clearTimeout(timeout);
106
+ timeout = setTimeout(function () {
107
+ return func.apply(_this, args);
108
+ }, delay);
109
+ };
110
+ }
50
111
 
51
112
  var MeetingProviderContex = React.createContext();
52
113
  var useMeeting = function useMeeting(_temp) {
@@ -560,12 +621,19 @@ var MeetingProvider = function MeetingProvider(_ref) {
560
621
  eventEmitter.emit(events['mic-requested'], data);
561
622
  };
562
623
  var _handle_meeting_joined = function _handle_meeting_joined(data) {
563
- joinedOnFirstRender.current = true;
564
- setMessages(function (s) {
565
- return [].concat(s, data.messages);
566
- });
567
- eventEmitter.emit(events['meeting-joined'], data);
568
- setIsMeetingJoined(true);
624
+ if (data.switchRoomId) {
625
+ setMessages(function (s) {
626
+ return [].concat(s, data.messages);
627
+ });
628
+ eventEmitter.emit(events['meeting-joined'], data);
629
+ } else {
630
+ joinedOnFirstRender.current = true;
631
+ setMessages(function (s) {
632
+ return [].concat(s, data.messages);
633
+ });
634
+ eventEmitter.emit(events['meeting-joined'], data);
635
+ setIsMeetingJoined(true);
636
+ }
569
637
  };
570
638
  var _handle_meeting_left2 = function _handle_meeting_left() {
571
639
  eventEmitter.emit(events['meeting-left']);
@@ -860,6 +928,17 @@ var MeetingProvider = function MeetingProvider(_ref) {
860
928
  enableWebcam(customVideoTrack);
861
929
  }
862
930
  };
931
+ var switchTo = function switchTo(_ref3) {
932
+ var meetingId = _ref3.meetingId,
933
+ token = _ref3.token;
934
+ var meeting = meetingRef.current;
935
+ if (meeting) {
936
+ meeting.switchTo({
937
+ meetingId: meetingId,
938
+ token: token
939
+ });
940
+ }
941
+ };
863
942
  var disableScreenShare = function disableScreenShare() {
864
943
  var meeting = meetingRef.current;
865
944
  if (meeting) {
@@ -946,8 +1025,8 @@ var MeetingProvider = function MeetingProvider(_ref) {
946
1025
  meeting.changeMic(obj);
947
1026
  }
948
1027
  };
949
- var startVideo = function startVideo(_ref3) {
950
- var link = _ref3.link;
1028
+ var startVideo = function startVideo(_ref4) {
1029
+ var link = _ref4.link;
951
1030
  var meeting = meetingRef.current;
952
1031
  if (meeting) {
953
1032
  meeting.startVideo({
@@ -967,8 +1046,8 @@ var MeetingProvider = function MeetingProvider(_ref) {
967
1046
  meeting.resumeVideo();
968
1047
  }
969
1048
  };
970
- var pauseVideo = function pauseVideo(_ref4) {
971
- var currentTime = _ref4.currentTime;
1049
+ var pauseVideo = function pauseVideo(_ref5) {
1050
+ var currentTime = _ref5.currentTime;
972
1051
  var meeting = meetingRef.current;
973
1052
  if (meeting) {
974
1053
  meeting.pauseVideo({
@@ -976,8 +1055,20 @@ var MeetingProvider = function MeetingProvider(_ref) {
976
1055
  });
977
1056
  }
978
1057
  };
979
- var seekVideo = function seekVideo(_ref5) {
980
- var currentTime = _ref5.currentTime;
1058
+ var enableAdaptiveSubscription = function enableAdaptiveSubscription() {
1059
+ var meeting = meetingRef.current;
1060
+ if (meeting) {
1061
+ meeting.enableAdaptiveSubscription();
1062
+ }
1063
+ };
1064
+ var disableAdaptiveSubscription = function disableAdaptiveSubscription() {
1065
+ var meeting = meetingRef.current;
1066
+ if (meeting) {
1067
+ meeting.disableAdaptiveSubscription();
1068
+ }
1069
+ };
1070
+ var seekVideo = function seekVideo(_ref6) {
1071
+ var currentTime = _ref6.currentTime;
981
1072
  var meeting = meetingRef.current;
982
1073
  if (meeting) {
983
1074
  meeting.seekVideo({
@@ -997,9 +1088,9 @@ var MeetingProvider = function MeetingProvider(_ref) {
997
1088
  meeting.stopLivestream();
998
1089
  }
999
1090
  };
1000
- var connectTo = function connectTo(_ref6) {
1001
- var meetingId = _ref6.meetingId,
1002
- payload = _ref6.payload;
1091
+ var connectTo = function connectTo(_ref7) {
1092
+ var meetingId = _ref7.meetingId,
1093
+ payload = _ref7.payload;
1003
1094
  try {
1004
1095
  var _meeting3 = meetingRef.current;
1005
1096
  var _temp = function () {
@@ -1095,6 +1186,7 @@ var MeetingProvider = function MeetingProvider(_ref) {
1095
1186
  disableScreenShare: disableScreenShare,
1096
1187
  enableScreenShare: enableScreenShare,
1097
1188
  toggleScreenShare: toggleScreenShare,
1189
+ switchTo: switchTo,
1098
1190
  getMics: getMics,
1099
1191
  getWebcams: getWebcams,
1100
1192
  changeWebcam: changeWebcam,
@@ -1110,7 +1202,9 @@ var MeetingProvider = function MeetingProvider(_ref) {
1110
1202
  stopLivestream: stopLivestream,
1111
1203
  connectTo: connectTo,
1112
1204
  startHls: startHls,
1113
- stopHls: stopHls
1205
+ stopHls: stopHls,
1206
+ enableAdaptiveSubscription: enableAdaptiveSubscription,
1207
+ disableAdaptiveSubscription: disableAdaptiveSubscription
1114
1208
  }
1115
1209
  }, children);
1116
1210
  };
@@ -1124,7 +1218,11 @@ var useParticipant = function useParticipant(participantId, _temp) {
1124
1218
  _ref$onMediaStatusCha = _ref.onMediaStatusChanged,
1125
1219
  onMediaStatusChanged = _ref$onMediaStatusCha === void 0 ? function () {} : _ref$onMediaStatusCha,
1126
1220
  _ref$onVideoQualityCh = _ref.onVideoQualityChanged,
1127
- onVideoQualityChanged = _ref$onVideoQualityCh === void 0 ? function () {} : _ref$onVideoQualityCh;
1221
+ onVideoQualityChanged = _ref$onVideoQualityCh === void 0 ? function () {} : _ref$onVideoQualityCh,
1222
+ _ref$onStreamPaused = _ref.onStreamPaused,
1223
+ onStreamPaused = _ref$onStreamPaused === void 0 ? function () {} : _ref$onStreamPaused,
1224
+ _ref$onStreamResumed = _ref.onStreamResumed,
1225
+ onStreamResumed = _ref$onStreamResumed === void 0 ? function () {} : _ref$onStreamResumed;
1128
1226
  var _useState = React.useState(null),
1129
1227
  webcamStream = _useState[0],
1130
1228
  setwebcamStream = _useState[1];
@@ -1333,6 +1431,12 @@ var useParticipant = function useParticipant(participantId, _temp) {
1333
1431
  }
1334
1432
  participant === null || participant === void 0 ? void 0 : participant.on('stream-enabled', _handleStreamEnabled);
1335
1433
  participant === null || participant === void 0 ? void 0 : participant.on('stream-disabled', _handleStreamDisabled);
1434
+ participant === null || participant === void 0 ? void 0 : participant.on('stream-paused', function (data) {
1435
+ onStreamPaused(data);
1436
+ });
1437
+ participant === null || participant === void 0 ? void 0 : participant.on('stream-resumed', function (data) {
1438
+ onStreamResumed(data);
1439
+ });
1336
1440
  participant === null || participant === void 0 ? void 0 : participant.on('media-status-changed', _handleMediaStatusChanged);
1337
1441
  participant === null || participant === void 0 ? void 0 : participant.on('video-quality-changed', _handleVideoQualityChanged);
1338
1442
  eventEmitter.on(events['participant-mode-changed'], _handleParticipantModeChanged);
@@ -1957,6 +2061,7 @@ var useWhiteboard = function useWhiteboard() {
1957
2061
  };
1958
2062
  };
1959
2063
 
2064
+ var _excluded = ["participantId", "type"];
1960
2065
  var Constants = jsSdk.VideoSDK.Constants;
1961
2066
  var createCameraVideoTrack = function createCameraVideoTrack(_ref) {
1962
2067
  var _ref$cameraId = _ref.cameraId,
@@ -2028,6 +2133,167 @@ var getNetworkStats = function getNetworkStats(_temp) {
2028
2133
  return Promise.reject(e);
2029
2134
  }
2030
2135
  };
2136
+ var withAdaptiveObservers = function withAdaptiveObservers(VideoPlayerComponent) {
2137
+ var intersectionObserverOptions = {
2138
+ root: null,
2139
+ rootMargin: '0px',
2140
+ threshold: 0
2141
+ };
2142
+ var debounceDelay = 400;
2143
+ return function (props) {
2144
+ var participantId = props.participantId,
2145
+ type = props.type;
2146
+ var ref = React.useRef(null);
2147
+ var observerRef = React.useRef(null);
2148
+ var resizeObserverRef = React.useRef(null);
2149
+ var _useParticipant = useParticipant(participantId),
2150
+ participant = _useParticipant.participant;
2151
+ React.useEffect(function () {
2152
+ if (type === 'share' || !ref.current || !participant) return;
2153
+ var element = ref.current;
2154
+ if (!element || !participant) return;
2155
+ if (observerRef.current) observerRef.current.disconnect();
2156
+ var handleIntersectionChange = debounce(function (entries) {
2157
+ for (var _iterator = _createForOfIteratorHelperLoose(entries), _step; !(_step = _iterator()).done;) {
2158
+ var entry = _step.value;
2159
+ if (entry.intersectionRatio > 0) {
2160
+ for (var _iterator2 = _createForOfIteratorHelperLoose(participant.streams.values()), _step2; !(_step2 = _iterator2()).done;) {
2161
+ var stream = _step2.value;
2162
+ if (stream.kind === 'video' && stream.pausedBy !== 'SUB_MANAGER') {
2163
+ stream.resume();
2164
+ }
2165
+ }
2166
+ } else {
2167
+ for (var _iterator3 = _createForOfIteratorHelperLoose(participant.streams.values()), _step3; !(_step3 = _iterator3()).done;) {
2168
+ var _stream = _step3.value;
2169
+ if (_stream.kind === 'video') {
2170
+ _stream.pause();
2171
+ }
2172
+ }
2173
+ }
2174
+ }
2175
+ }, debounceDelay);
2176
+ observerRef.current = new IntersectionObserver(handleIntersectionChange, intersectionObserverOptions);
2177
+ var processResize = function processResize(width, height) {
2178
+ if (width > 0 && height > 0) {
2179
+ participant.setViewPort(width, height);
2180
+ }
2181
+ };
2182
+ var handleResize = debounce(function (entries) {
2183
+ var _entries$0$contentRec = entries[0].contentRect,
2184
+ width = _entries$0$contentRec.width,
2185
+ height = _entries$0$contentRec.height;
2186
+ processResize(width, height);
2187
+ }, debounceDelay);
2188
+ resizeObserverRef.current = new ResizeObserver(handleResize);
2189
+ resizeObserverRef.current.observe(element);
2190
+ observerRef.current.observe(element);
2191
+ return function () {
2192
+ if (observerRef.current) {
2193
+ observerRef.current.disconnect();
2194
+ }
2195
+ if (resizeObserverRef.current) {
2196
+ resizeObserverRef.current.disconnect();
2197
+ }
2198
+ };
2199
+ }, []);
2200
+ return /*#__PURE__*/React__default.createElement(VideoPlayerComponent, _extends({
2201
+ ref: ref
2202
+ }, props));
2203
+ };
2204
+ };
2205
+ var VideoSDKPlayer = React.forwardRef(function (_ref5, ref) {
2206
+ var participantId = _ref5.participantId,
2207
+ _ref5$type = _ref5.type,
2208
+ type = _ref5$type === void 0 ? 'video' : _ref5$type,
2209
+ _ref5$containerStyle = _ref5.containerStyle,
2210
+ containerStyle = _ref5$containerStyle === void 0 ? {} : _ref5$containerStyle,
2211
+ _ref5$className = _ref5.className,
2212
+ className = _ref5$className === void 0 ? '' : _ref5$className,
2213
+ _ref5$classNameVideo = _ref5.classNameVideo,
2214
+ classNameVideo = _ref5$classNameVideo === void 0 ? '' : _ref5$classNameVideo,
2215
+ _ref5$videoStyle = _ref5.videoStyle,
2216
+ videoStyle = _ref5$videoStyle === void 0 ? {} : _ref5$videoStyle;
2217
+ var _useParticipant2 = useParticipant(participantId),
2218
+ webcamOn = _useParticipant2.webcamOn,
2219
+ webcamStream = _useParticipant2.webcamStream,
2220
+ isLocal = _useParticipant2.isLocal;
2221
+ var webcamRef = React.useRef(null);
2222
+ React.useEffect(function () {
2223
+ if (webcamRef.current) {
2224
+ if (webcamOn && webcamStream) {
2225
+ var mediaStream = new MediaStream();
2226
+ mediaStream.addTrack(webcamStream.track);
2227
+ webcamRef.current.srcObject = mediaStream;
2228
+ webcamRef.current.play()["catch"](function (error) {
2229
+ return console.error('videoElem.current.play() failed', error);
2230
+ });
2231
+ } else {
2232
+ webcamRef.current.srcObject = null;
2233
+ }
2234
+ }
2235
+ }, [webcamStream, webcamOn]);
2236
+ return /*#__PURE__*/React__default.createElement("div", {
2237
+ ref: ref,
2238
+ className: "video-container participant-video-" + participantId + " " + (className || ''),
2239
+ style: _extends({
2240
+ objectFit: type === 'share' ? 'contain' : 'none',
2241
+ height: '100%'
2242
+ }, containerStyle)
2243
+ }, /*#__PURE__*/React__default.createElement("video", {
2244
+ width: "100%",
2245
+ height: "100%",
2246
+ ref: webcamRef,
2247
+ autoPlay: true,
2248
+ className: classNameVideo,
2249
+ style: isLocal ? _extends({
2250
+ transform: 'scaleX(-1)',
2251
+ WebkitTransform: 'scaleX(-1)'
2252
+ }, videoStyle) : videoStyle
2253
+ }));
2254
+ });
2255
+ var VideoPlayer = function VideoPlayer(_ref6) {
2256
+ var participantId = _ref6.participantId,
2257
+ type = _ref6.type,
2258
+ props = _objectWithoutPropertiesLoose(_ref6, _excluded);
2259
+ var VideoPlayerComponent = React.useMemo(function () {
2260
+ return type === 'share' ? VideoSDKPlayer : withAdaptiveObservers(VideoSDKPlayer);
2261
+ }, [type, participantId]);
2262
+ return /*#__PURE__*/React__default.createElement(VideoPlayerComponent, _extends({
2263
+ participantId: participantId,
2264
+ type: type
2265
+ }, props));
2266
+ };
2267
+ var AudioPlayer = function AudioPlayer(_ref7) {
2268
+ var participantId = _ref7.participantId,
2269
+ type = _ref7.type;
2270
+ var _useParticipant3 = useParticipant(participantId),
2271
+ micStream = _useParticipant3.micStream,
2272
+ isLocal = _useParticipant3.isLocal,
2273
+ screenShareAudioStream = _useParticipant3.screenShareAudioStream;
2274
+ var micRef = React.useRef(null);
2275
+ React.useEffect(function () {
2276
+ if (micRef.current) {
2277
+ var audioStream = type === 'shareAudio' ? screenShareAudioStream : micStream;
2278
+ if (audioStream) {
2279
+ var mediaStream = new MediaStream();
2280
+ mediaStream.addTrack(audioStream.track);
2281
+ micRef.current.srcObject = mediaStream;
2282
+ micRef.current.play()["catch"](function (error) {
2283
+ return console.error('micRef.current.play() failed', error);
2284
+ });
2285
+ } else {
2286
+ micRef.current.srcObject = null;
2287
+ }
2288
+ }
2289
+ }, [micStream, screenShareAudioStream, type]);
2290
+ return /*#__PURE__*/React__default.createElement("audio", {
2291
+ ref: micRef,
2292
+ autoPlay: true,
2293
+ playsInline: true,
2294
+ muted: isLocal
2295
+ });
2296
+ };
2031
2297
 
2032
2298
  Object.defineProperty(exports, 'CameraDeviceInfo', {
2033
2299
  enumerable: true,
@@ -2047,9 +2313,11 @@ Object.defineProperty(exports, 'MicrophoneDeviceInfo', {
2047
2313
  return jsSdk.MicrophoneDeviceInfo;
2048
2314
  }
2049
2315
  });
2316
+ exports.AudioPlayer = AudioPlayer;
2050
2317
  exports.Constants = Constants;
2051
2318
  exports.MeetingConsumer = MeetingConsumer;
2052
2319
  exports.MeetingProvider = MeetingProvider;
2320
+ exports.VideoPlayer = VideoPlayer;
2053
2321
  exports.createCameraVideoTrack = createCameraVideoTrack;
2054
2322
  exports.createMicrophoneAudioTrack = createMicrophoneAudioTrack;
2055
2323
  exports.createScreenShareVideoTrack = createScreenShareVideoTrack;
@@ -2063,4 +2331,5 @@ exports.useParticipant = useParticipant;
2063
2331
  exports.usePubSub = usePubSub;
2064
2332
  exports.useTranscription = useTranscription;
2065
2333
  exports.useWhiteboard = useWhiteboard;
2334
+ exports.withAdaptiveObservers = withAdaptiveObservers;
2066
2335
  //# sourceMappingURL=index.js.map