@stream-io/video-react-native-sdk 1.15.1 → 1.16.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 (60) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/commonjs/components/Call/Lobby/Lobby.js +0 -4
  3. package/dist/commonjs/components/Call/Lobby/Lobby.js.map +1 -1
  4. package/dist/commonjs/components/Call/RingingCallContent/OutgoingCall.js +0 -4
  5. package/dist/commonjs/components/Call/RingingCallContent/OutgoingCall.js.map +1 -1
  6. package/dist/commonjs/contexts/index.js +0 -11
  7. package/dist/commonjs/contexts/index.js.map +1 -1
  8. package/dist/commonjs/hooks/index.js +0 -11
  9. package/dist/commonjs/hooks/index.js.map +1 -1
  10. package/dist/commonjs/providers/StreamVideo.js +1 -2
  11. package/dist/commonjs/providers/StreamVideo.js.map +1 -1
  12. package/dist/commonjs/version.js +1 -1
  13. package/dist/module/components/Call/Lobby/Lobby.js +0 -4
  14. package/dist/module/components/Call/Lobby/Lobby.js.map +1 -1
  15. package/dist/module/components/Call/RingingCallContent/OutgoingCall.js +0 -4
  16. package/dist/module/components/Call/RingingCallContent/OutgoingCall.js.map +1 -1
  17. package/dist/module/contexts/index.js +0 -1
  18. package/dist/module/contexts/index.js.map +1 -1
  19. package/dist/module/hooks/index.js +0 -1
  20. package/dist/module/hooks/index.js.map +1 -1
  21. package/dist/module/providers/StreamVideo.js +1 -2
  22. package/dist/module/providers/StreamVideo.js.map +1 -1
  23. package/dist/module/version.js +1 -1
  24. package/dist/typescript/components/Call/Lobby/Lobby.d.ts.map +1 -1
  25. package/dist/typescript/components/Call/RingingCallContent/OutgoingCall.d.ts.map +1 -1
  26. package/dist/typescript/contexts/index.d.ts +0 -1
  27. package/dist/typescript/contexts/index.d.ts.map +1 -1
  28. package/dist/typescript/hooks/index.d.ts +0 -1
  29. package/dist/typescript/hooks/index.d.ts.map +1 -1
  30. package/dist/typescript/providers/StreamVideo.d.ts.map +1 -1
  31. package/dist/typescript/version.d.ts +1 -1
  32. package/expo-config-plugin/dist/withAppDelegate.js +1 -1
  33. package/package.json +3 -3
  34. package/src/components/Call/Lobby/Lobby.tsx +0 -5
  35. package/src/components/Call/RingingCallContent/OutgoingCall.tsx +0 -5
  36. package/src/contexts/index.ts +0 -1
  37. package/src/hooks/index.ts +0 -1
  38. package/src/providers/StreamVideo.tsx +4 -7
  39. package/src/version.ts +1 -1
  40. package/dist/commonjs/contexts/StreamVideoContext.js +0 -110
  41. package/dist/commonjs/contexts/StreamVideoContext.js.map +0 -1
  42. package/dist/commonjs/hooks/internal/useCallMediaStreamCleanup.js +0 -31
  43. package/dist/commonjs/hooks/internal/useCallMediaStreamCleanup.js.map +0 -1
  44. package/dist/commonjs/hooks/useApplyDefaultMediaStreamSettings.js +0 -52
  45. package/dist/commonjs/hooks/useApplyDefaultMediaStreamSettings.js.map +0 -1
  46. package/dist/module/contexts/StreamVideoContext.js +0 -101
  47. package/dist/module/contexts/StreamVideoContext.js.map +0 -1
  48. package/dist/module/hooks/internal/useCallMediaStreamCleanup.js +0 -25
  49. package/dist/module/hooks/internal/useCallMediaStreamCleanup.js.map +0 -1
  50. package/dist/module/hooks/useApplyDefaultMediaStreamSettings.js +0 -46
  51. package/dist/module/hooks/useApplyDefaultMediaStreamSettings.js.map +0 -1
  52. package/dist/typescript/contexts/StreamVideoContext.d.ts +0 -20
  53. package/dist/typescript/contexts/StreamVideoContext.d.ts.map +0 -1
  54. package/dist/typescript/hooks/internal/useCallMediaStreamCleanup.d.ts +0 -6
  55. package/dist/typescript/hooks/internal/useCallMediaStreamCleanup.d.ts.map +0 -1
  56. package/dist/typescript/hooks/useApplyDefaultMediaStreamSettings.d.ts +0 -5
  57. package/dist/typescript/hooks/useApplyDefaultMediaStreamSettings.d.ts.map +0 -1
  58. package/src/contexts/StreamVideoContext.tsx +0 -147
  59. package/src/hooks/internal/useCallMediaStreamCleanup.ts +0 -38
  60. package/src/hooks/useApplyDefaultMediaStreamSettings.tsx +0 -42
@@ -4,7 +4,6 @@ import {
4
4
  StreamVideoProvider,
5
5
  } from '@stream-io/video-react-bindings';
6
6
  import React, { type PropsWithChildren, useEffect } from 'react';
7
- import { StreamVideoStoreProvider } from '../contexts/StreamVideoContext';
8
7
  import NetInfo from '@react-native-community/netinfo';
9
8
  import { usePushRegisterEffect } from '../hooks';
10
9
  import { translations } from '../translations';
@@ -61,12 +60,10 @@ export const StreamVideo = (
61
60
  i18nInstance={i18nInstance}
62
61
  >
63
62
  <StreamTheme style={style}>
64
- <StreamVideoStoreProvider>
65
- <ScreenshotIosContextProvider>
66
- <PushRegister />
67
- {children}
68
- </ScreenshotIosContextProvider>
69
- </StreamVideoStoreProvider>
63
+ <ScreenshotIosContextProvider>
64
+ <PushRegister />
65
+ {children}
66
+ </ScreenshotIosContextProvider>
70
67
  </StreamTheme>
71
68
  </StreamVideoProvider>
72
69
  );
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.15.1';
1
+ export const version = '1.16.1';
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useStreamVideoStoreValue = exports.useStreamVideoStoreSetState = exports.StreamVideoStoreProvider = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
9
- /**
10
- * Creates a Atomic store context with a provider and hooks to access the store
11
- * Atomic means that each value in the store updates state separately using useStoreValue hook
12
- * Extremely minimalistic implementation of Jotai's store context
13
- * @param initialState - the initial state of the store
14
- * @returns - {Provider, useStoreValue, useStoreSetState}
15
- */
16
- function createStoreContext(initialState) {
17
- // returns unsubscribe function
18
-
19
- function useStoreData() {
20
- const storeRef = (0, _react.useRef)(initialState);
21
- const getSnapshot = (0, _react.useRef)(() => storeRef.current).current;
22
- const subscribersRef = (0, _react.useRef)([]);
23
- const setState = (0, _react.useRef)(partialStateOrFunc => {
24
- if (typeof partialStateOrFunc === 'function') {
25
- const value = partialStateOrFunc(storeRef.current);
26
- storeRef.current = {
27
- ...storeRef.current,
28
- ...value
29
- };
30
- } else {
31
- storeRef.current = {
32
- ...storeRef.current,
33
- ...partialStateOrFunc
34
- };
35
- }
36
- subscribersRef.current.forEach(callback => callback());
37
- }).current;
38
- const subscribe = (0, _react.useRef)(callback => {
39
- subscribersRef.current.push(callback);
40
- return () => subscribersRef.current.filter(cb => cb !== callback);
41
- }).current;
42
- return {
43
- getSnapshot,
44
- setState,
45
- subscribe
46
- };
47
- }
48
- const StoreContext = /*#__PURE__*/(0, _react.createContext)(null);
49
- function Provider(props) {
50
- const value = useStoreData();
51
- return /*#__PURE__*/_react.default.createElement(StoreContext.Provider, {
52
- value: value
53
- }, props.children);
54
- }
55
-
56
- /**
57
- * @param selector
58
- * @returns
59
- *
60
- * @category Client State
61
- */
62
- function useStoreValue(selector) {
63
- const store = (0, _react.useContext)(StoreContext);
64
- if (!store) {
65
- throw new Error('Store not found');
66
- }
67
- const [state, setState] = (0, _react.useState)(selector(store.getSnapshot()));
68
- (0, _react.useEffect)(() => store.subscribe(() => setState(selector(store.getSnapshot()))), [selector, store]);
69
- return state;
70
- }
71
-
72
- /**
73
- *
74
- * @returns
75
- *
76
- * @category Client State
77
- */
78
- function useStoreSetState() {
79
- const store = (0, _react.useContext)(StoreContext);
80
- if (!store) {
81
- throw new Error('Store not found');
82
- }
83
- return store.setState;
84
- }
85
- return {
86
- Provider,
87
- useStoreValue,
88
- useStoreSetState
89
- };
90
- }
91
-
92
- /**
93
- * Exclude types from documentation site, but we should still add doc comments
94
- * @internal
95
- */
96
-
97
- const {
98
- Provider: StreamVideoStoreProvider,
99
- useStoreValue: useStreamVideoStoreValue,
100
- useStoreSetState: useStreamVideoStoreSetState
101
- } = createStoreContext({
102
- videoDevices: [],
103
- audioDevices: [],
104
- currentVideoDevice: undefined,
105
- currentAudioDevice: undefined
106
- });
107
- exports.useStreamVideoStoreSetState = useStreamVideoStoreSetState;
108
- exports.useStreamVideoStoreValue = useStreamVideoStoreValue;
109
- exports.StreamVideoStoreProvider = StreamVideoStoreProvider;
110
- //# sourceMappingURL=StreamVideoContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","createStoreContext","initialState","useStoreData","storeRef","useRef","getSnapshot","current","subscribersRef","setState","partialStateOrFunc","value","forEach","callback","subscribe","push","filter","cb","StoreContext","createContext","Provider","props","createElement","children","useStoreValue","selector","store","useContext","Error","state","useState","useEffect","useStoreSetState","StreamVideoStoreProvider","useStreamVideoStoreValue","useStreamVideoStoreSetState","videoDevices","audioDevices","currentVideoDevice","undefined","currentAudioDevice","exports"],"sourceRoot":"../../../src","sources":["contexts/StreamVideoContext.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAMe,SAAAD,wBAAAE,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAJ,uBAAA,YAAAA,CAAAE,CAAA,EAAAC,CAAA,SAAAA,CAAA,IAAAD,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBA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,KAAK,CAACpB,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EACpE,CAACmB,QAAQ,EAAEC,KAAK,CAClB,CAAC;IAED,OAAOG,KAAK;EACd;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,SAASG,gBAAgBA,CAAA,EAAG;IAC1B,MAAMN,KAAK,GAAG,IAAAC,iBAAU,EAACT,YAAY,CAAC;IACtC,IAAI,CAACQ,KAAK,EAAE;MACV,MAAM,IAAIE,KAAK,CAAC,iBAAiB,CAAC;IACpC;IACA,OAAOF,KAAK,CAACjB,QAAQ;EACvB;EAEA,OAAO;IACLW,QAAQ;IACRI,aAAa;IACbQ;EACF,CAAC;AACH;;AAUA;AACA;AACA;AACA;;AAQO,MAAM;EACXZ,QAAQ,EAAEa,wBAAwB;EAClCT,aAAa,EAAEU,wBAAwB;EACvCF,gBAAgB,EAAEG;AACpB,CAAC,GAAGlC,kBAAkB,CAAsB;EAC1CmC,YAAY,EAAE,EAAE;EAChBC,YAAY,EAAE,EAAE;EAChBC,kBAAkB,EAAEC,SAAS;EAC7BC,kBAAkB,EAAED;AACtB,CAAC,CAAC;AAACE,OAAA,CAAAN,2BAAA,GAAAA,2BAAA;AAAAM,OAAA,CAAAP,wBAAA,GAAAA,wBAAA;AAAAO,OAAA,CAAAR,wBAAA,GAAAA,wBAAA","ignoreList":[]}
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useCallMediaStreamCleanup = void 0;
7
- var _videoClient = require("@stream-io/video-client");
8
- var _videoReactBindings = require("@stream-io/video-react-bindings");
9
- var _react = require("react");
10
- /**
11
- * This hook is meant to be used in Lobby view or equivalent.
12
- * It will cleanup the media stream on unmount if call is not meant to be joined.
13
- */
14
- const useCallMediaStreamCleanup = () => {
15
- const call = (0, _videoReactBindings.useCall)();
16
- // keeping a reference of call to handle cleanup media stream only on unmount
17
- const callRef = (0, _react.useRef)(call);
18
- callRef.current = call;
19
- (0, _react.useEffect)(() => {
20
- return () => {
21
- const mediaStream = callRef.current?.camera.state.mediaStream;
22
- if (mediaStream && !(callRef.current?.state.callingState === _videoClient.CallingState.JOINED || callRef.current?.state.callingState === _videoClient.CallingState.JOINING)) {
23
- (0, _videoClient.getLogger)(['useCallMediaStreamCleanup'])('debug', 'Cleaning up camera media stream');
24
- // we cleanup media stream only if call is not joined or joining
25
- (0, _videoClient.disposeOfMediaStream)(mediaStream);
26
- }
27
- };
28
- }, []);
29
- };
30
- exports.useCallMediaStreamCleanup = useCallMediaStreamCleanup;
31
- //# sourceMappingURL=useCallMediaStreamCleanup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_videoClient","require","_videoReactBindings","_react","useCallMediaStreamCleanup","call","useCall","callRef","useRef","current","useEffect","mediaStream","camera","state","callingState","CallingState","JOINED","JOINING","getLogger","disposeOfMediaStream","exports"],"sourceRoot":"../../../../src","sources":["hooks/internal/useCallMediaStreamCleanup.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAKA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA;AACA;AACA;AACA;AACO,MAAMG,yBAAyB,GAAGA,CAAA,KAAM;EAC7C,MAAMC,IAAI,GAAG,IAAAC,2BAAO,EAAC,CAAC;EACtB;EACA,MAAMC,OAAO,GAAG,IAAAC,aAAM,EAACH,IAAI,CAAC;EAC5BE,OAAO,CAACE,OAAO,GAAGJ,IAAI;EAEtB,IAAAK,gBAAS,EAAC,MAAM;IACd,OAAO,MAAM;MACX,MAAMC,WAAW,GAAGJ,OAAO,CAACE,OAAO,EAAEG,MAAM,CAACC,KAAK,CAACF,WAAW;MAC7D,IACEA,WAAW,IACX,EACEJ,OAAO,CAACE,OAAO,EAAEI,KAAK,CAACC,YAAY,KAAKC,yBAAY,CAACC,MAAM,IAC3DT,OAAO,CAACE,OAAO,EAAEI,KAAK,CAACC,YAAY,KAAKC,yBAAY,CAACE,OAAO,CAC7D,EACD;QACA,IAAAC,sBAAS,EAAC,CAAC,2BAA2B,CAAC,CAAC,CACtC,OAAO,EACP,iCACF,CAAC;QACD;QACA,IAAAC,iCAAoB,EAACR,WAAW,CAAC;MACnC;IACF,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;AACR,CAAC;AAACS,OAAA,CAAAhB,yBAAA,GAAAA,yBAAA","ignoreList":[]}
@@ -1,52 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useApplyDefaultMediaStreamSettings = void 0;
7
- var _videoReactBindings = require("@stream-io/video-react-bindings");
8
- var _react = require("react");
9
- /**
10
- * Hook when used applies the default call media stream audio/video settings.
11
- */
12
- const useApplyDefaultMediaStreamSettings = () => {
13
- const {
14
- useCallSettings
15
- } = (0, _videoReactBindings.useCallStateHooks)();
16
- const settings = useCallSettings();
17
- const call = (0, _videoReactBindings.useCall)();
18
-
19
- /*
20
- * This is the object is used to track the initial audio/video enablement
21
- * Uses backend settings or the Prop to set initial audio/video enabled
22
- * Backend settings is applied only if the prop was undefined -- meaning user did not provide any value
23
- * Memoization is needed to avoid unnecessary useEffect triggers
24
- */
25
- const {
26
- initialAudioEnabled,
27
- initialVideoEnabled
28
- } = (0, _react.useMemo)(() => {
29
- return {
30
- initialAudioEnabled: settings?.audio.mic_default_on,
31
- initialVideoEnabled: settings?.video.camera_default_on
32
- };
33
- }, [settings?.audio.mic_default_on, settings?.video.camera_default_on]);
34
- (0, _react.useEffect)(() => {
35
- if (initialAudioEnabled !== undefined) {
36
- if (initialAudioEnabled) {
37
- call?.microphone.enable();
38
- } else {
39
- call?.microphone.disable();
40
- }
41
- }
42
- if (initialVideoEnabled !== undefined) {
43
- if (initialVideoEnabled) {
44
- call?.camera.enable();
45
- } else {
46
- call?.camera.disable();
47
- }
48
- }
49
- }, [call, initialAudioEnabled, initialVideoEnabled]);
50
- };
51
- exports.useApplyDefaultMediaStreamSettings = useApplyDefaultMediaStreamSettings;
52
- //# sourceMappingURL=useApplyDefaultMediaStreamSettings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_videoReactBindings","require","_react","useApplyDefaultMediaStreamSettings","useCallSettings","useCallStateHooks","settings","call","useCall","initialAudioEnabled","initialVideoEnabled","useMemo","audio","mic_default_on","video","camera_default_on","useEffect","undefined","microphone","enable","disable","camera","exports"],"sourceRoot":"../../../src","sources":["hooks/useApplyDefaultMediaStreamSettings.tsx"],"mappings":";;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACO,MAAME,kCAAkC,GAAGA,CAAA,KAAM;EACtD,MAAM;IAAEC;EAAgB,CAAC,GAAG,IAAAC,qCAAiB,EAAC,CAAC;EAC/C,MAAMC,QAAQ,GAAGF,eAAe,CAAC,CAAC;EAClC,MAAMG,IAAI,GAAG,IAAAC,2BAAO,EAAC,CAAC;;EAEtB;AACF;AACA;AACA;AACA;AACA;EACE,MAAM;IAAEC,mBAAmB;IAAEC;EAAoB,CAAC,GAAG,IAAAC,cAAO,EAAC,MAAM;IACjE,OAAO;MACLF,mBAAmB,EAAEH,QAAQ,EAAEM,KAAK,CAACC,cAAc;MACnDH,mBAAmB,EAAEJ,QAAQ,EAAEQ,KAAK,CAACC;IACvC,CAAC;EACH,CAAC,EAAE,CAACT,QAAQ,EAAEM,KAAK,CAACC,cAAc,EAAEP,QAAQ,EAAEQ,KAAK,CAACC,iBAAiB,CAAC,CAAC;EAEvE,IAAAC,gBAAS,EAAC,MAAM;IACd,IAAIP,mBAAmB,KAAKQ,SAAS,EAAE;MACrC,IAAIR,mBAAmB,EAAE;QACvBF,IAAI,EAAEW,UAAU,CAACC,MAAM,CAAC,CAAC;MAC3B,CAAC,MAAM;QACLZ,IAAI,EAAEW,UAAU,CAACE,OAAO,CAAC,CAAC;MAC5B;IACF;IAEA,IAAIV,mBAAmB,KAAKO,SAAS,EAAE;MACrC,IAAIP,mBAAmB,EAAE;QACvBH,IAAI,EAAEc,MAAM,CAACF,MAAM,CAAC,CAAC;MACvB,CAAC,MAAM;QACLZ,IAAI,EAAEc,MAAM,CAACD,OAAO,CAAC,CAAC;MACxB;IACF;EACF,CAAC,EAAE,CAACb,IAAI,EAAEE,mBAAmB,EAAEC,mBAAmB,CAAC,CAAC;AACtD,CAAC;AAACY,OAAA,CAAAnB,kCAAA,GAAAA,kCAAA","ignoreList":[]}
@@ -1,101 +0,0 @@
1
- import React, { createContext, useContext, useEffect, useRef, useState } from 'react';
2
-
3
- /**
4
- * Creates a Atomic store context with a provider and hooks to access the store
5
- * Atomic means that each value in the store updates state separately using useStoreValue hook
6
- * Extremely minimalistic implementation of Jotai's store context
7
- * @param initialState - the initial state of the store
8
- * @returns - {Provider, useStoreValue, useStoreSetState}
9
- */
10
- function createStoreContext(initialState) {
11
- // returns unsubscribe function
12
-
13
- function useStoreData() {
14
- const storeRef = useRef(initialState);
15
- const getSnapshot = useRef(() => storeRef.current).current;
16
- const subscribersRef = useRef([]);
17
- const setState = useRef(partialStateOrFunc => {
18
- if (typeof partialStateOrFunc === 'function') {
19
- const value = partialStateOrFunc(storeRef.current);
20
- storeRef.current = {
21
- ...storeRef.current,
22
- ...value
23
- };
24
- } else {
25
- storeRef.current = {
26
- ...storeRef.current,
27
- ...partialStateOrFunc
28
- };
29
- }
30
- subscribersRef.current.forEach(callback => callback());
31
- }).current;
32
- const subscribe = useRef(callback => {
33
- subscribersRef.current.push(callback);
34
- return () => subscribersRef.current.filter(cb => cb !== callback);
35
- }).current;
36
- return {
37
- getSnapshot,
38
- setState,
39
- subscribe
40
- };
41
- }
42
- const StoreContext = /*#__PURE__*/createContext(null);
43
- function Provider(props) {
44
- const value = useStoreData();
45
- return /*#__PURE__*/React.createElement(StoreContext.Provider, {
46
- value: value
47
- }, props.children);
48
- }
49
-
50
- /**
51
- * @param selector
52
- * @returns
53
- *
54
- * @category Client State
55
- */
56
- function useStoreValue(selector) {
57
- const store = useContext(StoreContext);
58
- if (!store) {
59
- throw new Error('Store not found');
60
- }
61
- const [state, setState] = useState(selector(store.getSnapshot()));
62
- useEffect(() => store.subscribe(() => setState(selector(store.getSnapshot()))), [selector, store]);
63
- return state;
64
- }
65
-
66
- /**
67
- *
68
- * @returns
69
- *
70
- * @category Client State
71
- */
72
- function useStoreSetState() {
73
- const store = useContext(StoreContext);
74
- if (!store) {
75
- throw new Error('Store not found');
76
- }
77
- return store.setState;
78
- }
79
- return {
80
- Provider,
81
- useStoreValue,
82
- useStoreSetState
83
- };
84
- }
85
-
86
- /**
87
- * Exclude types from documentation site, but we should still add doc comments
88
- * @internal
89
- */
90
-
91
- export const {
92
- Provider: StreamVideoStoreProvider,
93
- useStoreValue: useStreamVideoStoreValue,
94
- useStoreSetState: useStreamVideoStoreSetState
95
- } = createStoreContext({
96
- videoDevices: [],
97
- audioDevices: [],
98
- currentVideoDevice: undefined,
99
- currentAudioDevice: undefined
100
- });
101
- //# sourceMappingURL=StreamVideoContext.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","createContext","useContext","useEffect","useRef","useState","createStoreContext","initialState","useStoreData","storeRef","getSnapshot","current","subscribersRef","setState","partialStateOrFunc","value","forEach","callback","subscribe","push","filter","cb","StoreContext","Provider","props","createElement","children","useStoreValue","selector","store","Error","state","useStoreSetState","StreamVideoStoreProvider","useStreamVideoStoreValue","useStreamVideoStoreSetState","videoDevices","audioDevices","currentVideoDevice","undefined","currentAudioDevice"],"sourceRoot":"../../../src","sources":["contexts/StreamVideoContext.tsx"],"mappings":"AAAA,OAAOA,KAAK,IACVC,aAAa,EACbC,UAAU,EACVC,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,OAAO;;AAEd;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,kBAAkBA,CAA2BC,YAAuB,EAAE;EAO7E;;EAGA,SAASC,YAAYA,CAAA,EAInB;IACA,MAAMC,QAAQ,GAAGL,MAAM,CAAYG,YAAY,CAAC;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ACpBC,QAA8C,EAC9B;IAChB,MAAMC,KAAK,GAAG3B,UAAU,CAACoB,YAAY,CAAC;IACtC,IAAI,CAACO,KAAK,EAAE;MACV,MAAM,IAAIC,KAAK,CAAC,iBAAiB,CAAC;IACpC;IAEA,MAAM,CAACC,KAAK,EAAElB,QAAQ,CAAC,GAAGR,QAAQ,CAACuB,QAAQ,CAACC,KAAK,CAACnB,WAAW,CAAC,CAAC,CAAC,CAAC;IACjEP,SAAS,CACP,MAAM0B,KAAK,CAACX,SAAS,CAAC,MAAML,QAAQ,CAACe,QAAQ,CAACC,KAAK,CAACnB,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,EACpE,CAACkB,QAAQ,EAAEC,KAAK,CAClB,CAAC;IAED,OAAOE,KAAK;EACd;;EAEA;AACF;AACA;AACA;AACA;AACA;EACE,SAASC,gBAAgBA,CAAA,EAAG;IAC1B,MAAMH,KAAK,GAAG3B,UAAU,CAACoB,YAAY,CAAC;IACtC,IAAI,CAACO,KAAK,EAAE;MACV,MAAM,IAAIC,KAAK,CAAC,iBAAiB,CAAC;IACpC;IACA,OAAOD,KAAK,CAAChB,QAAQ;EACvB;EAEA,OAAO;IACLU,QAAQ;IACRI,aAAa;IACbK;EACF,CAAC;AACH;;AAUA;AACA;AACA;AACA;;AAQA,OAAO,MAAM;EACXT,QAAQ,EAAEU,wBAAwB;EAClCN,aAAa,EAAEO,wBAAwB;EACvCF,gBAAgB,EAAEG;AACpB,CAAC,GAAG7B,kBAAkB,CAAsB;EAC1C8B,YAAY,EAAE,EAAE;EAChBC,YAAY,EAAE,EAAE;EAChBC,kBAAkB,EAAEC,SAAS;EAC7BC,kBAAkB,EAAED;AACtB,CAAC,CAAC","ignoreList":[]}
@@ -1,25 +0,0 @@
1
- import { CallingState, disposeOfMediaStream, getLogger } from '@stream-io/video-client';
2
- import { useCall } from '@stream-io/video-react-bindings';
3
- import { useEffect, useRef } from 'react';
4
-
5
- /**
6
- * This hook is meant to be used in Lobby view or equivalent.
7
- * It will cleanup the media stream on unmount if call is not meant to be joined.
8
- */
9
- export const useCallMediaStreamCleanup = () => {
10
- const call = useCall();
11
- // keeping a reference of call to handle cleanup media stream only on unmount
12
- const callRef = useRef(call);
13
- callRef.current = call;
14
- useEffect(() => {
15
- return () => {
16
- const mediaStream = callRef.current?.camera.state.mediaStream;
17
- if (mediaStream && !(callRef.current?.state.callingState === CallingState.JOINED || callRef.current?.state.callingState === CallingState.JOINING)) {
18
- getLogger(['useCallMediaStreamCleanup'])('debug', 'Cleaning up camera media stream');
19
- // we cleanup media stream only if call is not joined or joining
20
- disposeOfMediaStream(mediaStream);
21
- }
22
- };
23
- }, []);
24
- };
25
- //# sourceMappingURL=useCallMediaStreamCleanup.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["CallingState","disposeOfMediaStream","getLogger","useCall","useEffect","useRef","useCallMediaStreamCleanup","call","callRef","current","mediaStream","camera","state","callingState","JOINED","JOINING"],"sourceRoot":"../../../../src","sources":["hooks/internal/useCallMediaStreamCleanup.ts"],"mappings":"AAAA,SACEA,YAAY,EACZC,oBAAoB,EACpBC,SAAS,QACJ,yBAAyB;AAChC,SAASC,OAAO,QAAQ,iCAAiC;AACzD,SAASC,SAAS,EAAEC,MAAM,QAAQ,OAAO;;AAEzC;AACA;AACA;AACA;AACA,OAAO,MAAMC,yBAAyB,GAAGA,CAAA,KAAM;EAC7C,MAAMC,IAAI,GAAGJ,OAAO,CAAC,CAAC;EACtB;EACA,MAAMK,OAAO,GAAGH,MAAM,CAACE,IAAI,CAAC;EAC5BC,OAAO,CAACC,OAAO,GAAGF,IAAI;EAEtBH,SAAS,CAAC,MAAM;IACd,OAAO,MAAM;MACX,MAAMM,WAAW,GAAGF,OAAO,CAACC,OAAO,EAAEE,MAAM,CAACC,KAAK,CAACF,WAAW;MAC7D,IACEA,WAAW,IACX,EACEF,OAAO,CAACC,OAAO,EAAEG,KAAK,CAACC,YAAY,KAAKb,YAAY,CAACc,MAAM,IAC3DN,OAAO,CAACC,OAAO,EAAEG,KAAK,CAACC,YAAY,KAAKb,YAAY,CAACe,OAAO,CAC7D,EACD;QACAb,SAAS,CAAC,CAAC,2BAA2B,CAAC,CAAC,CACtC,OAAO,EACP,iCACF,CAAC;QACD;QACAD,oBAAoB,CAACS,WAAW,CAAC;MACnC;IACF,CAAC;EACH,CAAC,EAAE,EAAE,CAAC;AACR,CAAC","ignoreList":[]}
@@ -1,46 +0,0 @@
1
- import { useCall, useCallStateHooks } from '@stream-io/video-react-bindings';
2
- import { useEffect, useMemo } from 'react';
3
-
4
- /**
5
- * Hook when used applies the default call media stream audio/video settings.
6
- */
7
- export const useApplyDefaultMediaStreamSettings = () => {
8
- const {
9
- useCallSettings
10
- } = useCallStateHooks();
11
- const settings = useCallSettings();
12
- const call = useCall();
13
-
14
- /*
15
- * This is the object is used to track the initial audio/video enablement
16
- * Uses backend settings or the Prop to set initial audio/video enabled
17
- * Backend settings is applied only if the prop was undefined -- meaning user did not provide any value
18
- * Memoization is needed to avoid unnecessary useEffect triggers
19
- */
20
- const {
21
- initialAudioEnabled,
22
- initialVideoEnabled
23
- } = useMemo(() => {
24
- return {
25
- initialAudioEnabled: settings?.audio.mic_default_on,
26
- initialVideoEnabled: settings?.video.camera_default_on
27
- };
28
- }, [settings?.audio.mic_default_on, settings?.video.camera_default_on]);
29
- useEffect(() => {
30
- if (initialAudioEnabled !== undefined) {
31
- if (initialAudioEnabled) {
32
- call?.microphone.enable();
33
- } else {
34
- call?.microphone.disable();
35
- }
36
- }
37
- if (initialVideoEnabled !== undefined) {
38
- if (initialVideoEnabled) {
39
- call?.camera.enable();
40
- } else {
41
- call?.camera.disable();
42
- }
43
- }
44
- }, [call, initialAudioEnabled, initialVideoEnabled]);
45
- };
46
- //# sourceMappingURL=useApplyDefaultMediaStreamSettings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["useCall","useCallStateHooks","useEffect","useMemo","useApplyDefaultMediaStreamSettings","useCallSettings","settings","call","initialAudioEnabled","initialVideoEnabled","audio","mic_default_on","video","camera_default_on","undefined","microphone","enable","disable","camera"],"sourceRoot":"../../../src","sources":["hooks/useApplyDefaultMediaStreamSettings.tsx"],"mappings":"AAAA,SAASA,OAAO,EAAEC,iBAAiB,QAAQ,iCAAiC;AAC5E,SAASC,SAAS,EAAEC,OAAO,QAAQ,OAAO;;AAE1C;AACA;AACA;AACA,OAAO,MAAMC,kCAAkC,GAAGA,CAAA,KAAM;EACtD,MAAM;IAAEC;EAAgB,CAAC,GAAGJ,iBAAiB,CAAC,CAAC;EAC/C,MAAMK,QAAQ,GAAGD,eAAe,CAAC,CAAC;EAClC,MAAME,IAAI,GAAGP,OAAO,CAAC,CAAC;;EAEtB;AACF;AACA;AACA;AACA;AACA;EACE,MAAM;IAAEQ,mBAAmB;IAAEC;EAAoB,CAAC,GAAGN,OAAO,CAAC,MAAM;IACjE,OAAO;MACLK,mBAAmB,EAAEF,QAAQ,EAAEI,KAAK,CAACC,cAAc;MACnDF,mBAAmB,EAAEH,QAAQ,EAAEM,KAAK,CAACC;IACvC,CAAC;EACH,CAAC,EAAE,CAACP,QAAQ,EAAEI,KAAK,CAACC,cAAc,EAAEL,QAAQ,EAAEM,KAAK,CAACC,iBAAiB,CAAC,CAAC;EAEvEX,SAAS,CAAC,MAAM;IACd,IAAIM,mBAAmB,KAAKM,SAAS,EAAE;MACrC,IAAIN,mBAAmB,EAAE;QACvBD,IAAI,EAAEQ,UAAU,CAACC,MAAM,CAAC,CAAC;MAC3B,CAAC,MAAM;QACLT,IAAI,EAAEQ,UAAU,CAACE,OAAO,CAAC,CAAC;MAC5B;IACF;IAEA,IAAIR,mBAAmB,KAAKK,SAAS,EAAE;MACrC,IAAIL,mBAAmB,EAAE;QACvBF,IAAI,EAAEW,MAAM,CAACF,MAAM,CAAC,CAAC;MACvB,CAAC,MAAM;QACLT,IAAI,EAAEW,MAAM,CAACD,OAAO,CAAC,CAAC;MACxB;IACF;EACF,CAAC,EAAE,CAACV,IAAI,EAAEC,mBAAmB,EAAEC,mBAAmB,CAAC,CAAC;AACtD,CAAC","ignoreList":[]}
@@ -1,20 +0,0 @@
1
- import React from 'react';
2
- export type MediaDeviceInfo = {
3
- deviceId: string;
4
- facing?: 'environment' | 'front';
5
- groupId: string;
6
- kind: 'videoinput' | 'audioinput';
7
- label: string;
8
- };
9
- /**
10
- * Exclude types from documentation site, but we should still add doc comments
11
- * @internal
12
- */
13
- export interface SDKStreamVideoStore {
14
- currentAudioDevice?: MediaDeviceInfo;
15
- currentVideoDevice?: MediaDeviceInfo;
16
- audioDevices: MediaDeviceInfo[];
17
- videoDevices: MediaDeviceInfo[];
18
- }
19
- export declare const StreamVideoStoreProvider: (props: React.PropsWithChildren<{}>) => React.JSX.Element, useStreamVideoStoreValue: <SelectorOutput extends MediaDeviceInfo | MediaDeviceInfo[] | undefined>(selector: (store: SDKStreamVideoStore) => SelectorOutput) => SelectorOutput, useStreamVideoStoreSetState: () => (partialStateOrFunc: Partial<SDKStreamVideoStore> | ((prevState: SDKStreamVideoStore) => Partial<SDKStreamVideoStore>)) => void;
20
- //# sourceMappingURL=StreamVideoContext.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StreamVideoContext.d.ts","sourceRoot":"","sources":["../../../src/contexts/StreamVideoContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAMN,MAAM,OAAO,CAAC;AAgHf,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,YAAY,GAAG,YAAY,CAAC;IAClC,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,kBAAkB,CAAC,EAAE,eAAe,CAAC;IACrC,kBAAkB,CAAC,EAAE,eAAe,CAAC;IACrC,YAAY,EAAE,eAAe,EAAE,CAAC;IAChC,YAAY,EAAE,eAAe,EAAE,CAAC;CACjC;AAED,eAAO,MACK,wBAAwB,UAzET,KAAK,CAAC,iBAAiB,CAAC,EAAE,CAAC,wBA0ErC,wBAAwB,GA3DhB,cAAc,uIA4DnB,2BAA2B,mIAxHxC,IA8HL,CAAC"}
@@ -1,6 +0,0 @@
1
- /**
2
- * This hook is meant to be used in Lobby view or equivalent.
3
- * It will cleanup the media stream on unmount if call is not meant to be joined.
4
- */
5
- export declare const useCallMediaStreamCleanup: () => void;
6
- //# sourceMappingURL=useCallMediaStreamCleanup.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useCallMediaStreamCleanup.d.ts","sourceRoot":"","sources":["../../../../src/hooks/internal/useCallMediaStreamCleanup.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,eAAO,MAAM,yBAAyB,YAyBrC,CAAC"}
@@ -1,5 +0,0 @@
1
- /**
2
- * Hook when used applies the default call media stream audio/video settings.
3
- */
4
- export declare const useApplyDefaultMediaStreamSettings: () => void;
5
- //# sourceMappingURL=useApplyDefaultMediaStreamSettings.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useApplyDefaultMediaStreamSettings.d.ts","sourceRoot":"","sources":["../../../src/hooks/useApplyDefaultMediaStreamSettings.tsx"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,kCAAkC,YAmC9C,CAAC"}
@@ -1,147 +0,0 @@
1
- import React, {
2
- createContext,
3
- useContext,
4
- useEffect,
5
- useRef,
6
- useState,
7
- } from 'react';
8
-
9
- /**
10
- * Creates a Atomic store context with a provider and hooks to access the store
11
- * Atomic means that each value in the store updates state separately using useStoreValue hook
12
- * Extremely minimalistic implementation of Jotai's store context
13
- * @param initialState - the initial state of the store
14
- * @returns - {Provider, useStoreValue, useStoreSetState}
15
- */
16
- function createStoreContext<StoreType extends object>(initialState: StoreType) {
17
- type SetStateFuncType = (
18
- partialStateOrFunc:
19
- | Partial<StoreType>
20
- | ((prevState: StoreType) => Partial<StoreType>),
21
- ) => void;
22
-
23
- // returns unsubscribe function
24
- type SubscribeFunc = (callback: () => void) => () => void;
25
-
26
- function useStoreData(): {
27
- getSnapshot: () => StoreType;
28
- setState: SetStateFuncType;
29
- subscribe: SubscribeFunc;
30
- } {
31
- const storeRef = useRef<StoreType>(initialState);
32
-
33
- const getSnapshot = useRef(() => storeRef.current).current;
34
-
35
- const subscribersRef = useRef<(() => void)[]>([]);
36
-
37
- const setState = useRef<SetStateFuncType>((partialStateOrFunc) => {
38
- if (typeof partialStateOrFunc === 'function') {
39
- const value = partialStateOrFunc(storeRef.current);
40
- storeRef.current = {
41
- ...storeRef.current,
42
- ...value,
43
- };
44
- } else {
45
- storeRef.current = { ...storeRef.current, ...partialStateOrFunc };
46
- }
47
- subscribersRef.current.forEach((callback) => callback());
48
- }).current;
49
-
50
- const subscribe = useRef((callback: () => void) => {
51
- subscribersRef.current.push(callback);
52
- return () => subscribersRef.current.filter((cb) => cb !== callback);
53
- }).current;
54
-
55
- return {
56
- getSnapshot,
57
- setState,
58
- subscribe,
59
- };
60
- }
61
-
62
- type HookReturnType = ReturnType<typeof useStoreData>;
63
-
64
- const StoreContext = createContext<HookReturnType | null>(null);
65
-
66
- function Provider(props: React.PropsWithChildren<{}>) {
67
- const value = useStoreData();
68
- return (
69
- <StoreContext.Provider value={value}>
70
- {props.children}
71
- </StoreContext.Provider>
72
- );
73
- }
74
-
75
- /**
76
- * @param selector
77
- * @returns
78
- *
79
- * @category Client State
80
- */
81
- function useStoreValue<SelectorOutput extends StoreType[keyof StoreType]>(
82
- selector: (store: StoreType) => SelectorOutput,
83
- ): SelectorOutput {
84
- const store = useContext(StoreContext);
85
- if (!store) {
86
- throw new Error('Store not found');
87
- }
88
-
89
- const [state, setState] = useState(selector(store.getSnapshot()));
90
- useEffect(
91
- () => store.subscribe(() => setState(selector(store.getSnapshot()))),
92
- [selector, store],
93
- );
94
-
95
- return state;
96
- }
97
-
98
- /**
99
- *
100
- * @returns
101
- *
102
- * @category Client State
103
- */
104
- function useStoreSetState() {
105
- const store = useContext(StoreContext);
106
- if (!store) {
107
- throw new Error('Store not found');
108
- }
109
- return store.setState;
110
- }
111
-
112
- return {
113
- Provider,
114
- useStoreValue,
115
- useStoreSetState,
116
- };
117
- }
118
-
119
- export type MediaDeviceInfo = {
120
- deviceId: string;
121
- facing?: 'environment' | 'front';
122
- groupId: string;
123
- kind: 'videoinput' | 'audioinput';
124
- label: string;
125
- };
126
-
127
- /**
128
- * Exclude types from documentation site, but we should still add doc comments
129
- * @internal
130
- */
131
- export interface SDKStreamVideoStore {
132
- currentAudioDevice?: MediaDeviceInfo;
133
- currentVideoDevice?: MediaDeviceInfo;
134
- audioDevices: MediaDeviceInfo[];
135
- videoDevices: MediaDeviceInfo[];
136
- }
137
-
138
- export const {
139
- Provider: StreamVideoStoreProvider,
140
- useStoreValue: useStreamVideoStoreValue,
141
- useStoreSetState: useStreamVideoStoreSetState,
142
- } = createStoreContext<SDKStreamVideoStore>({
143
- videoDevices: [],
144
- audioDevices: [],
145
- currentVideoDevice: undefined,
146
- currentAudioDevice: undefined,
147
- });