@livekit/react-native 2.1.1 → 2.3.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/README.md +15 -6
- package/android/build.gradle +1 -1
- package/android/gradle/wrapper/gradle-wrapper.properties +3 -1
- package/android/gradlew +29 -14
- package/android/gradlew.bat +19 -16
- package/android/src/main/java/com/livekit/reactnative/LiveKitReactNative.kt +14 -1
- package/android/src/main/java/com/livekit/reactnative/LivekitReactNativeModule.kt +10 -0
- package/android/src/main/java/com/livekit/reactnative/video/SimulcastVideoEncoderFactoryWrapper.kt +2 -2
- package/android/src/main/java/org/webrtc/audio/WebRtcAudioTrackHelper.kt +20 -0
- package/lib/commonjs/audio/AudioManager.js +4 -27
- package/lib/commonjs/audio/AudioManager.js.map +1 -1
- package/lib/commonjs/audio/AudioSession.js +55 -23
- package/lib/commonjs/audio/AudioSession.js.map +1 -1
- package/lib/commonjs/components/LiveKitRoom.js +3 -6
- package/lib/commonjs/components/LiveKitRoom.js.map +1 -1
- package/lib/commonjs/components/VideoTrack.js +30 -66
- package/lib/commonjs/components/VideoTrack.js.map +1 -1
- package/lib/commonjs/components/VideoView.js +32 -63
- package/lib/commonjs/components/VideoView.js.map +1 -1
- package/lib/commonjs/components/ViewPortDetector.js +15 -62
- package/lib/commonjs/components/ViewPortDetector.js.map +1 -1
- package/lib/commonjs/hooks.js +6 -63
- package/lib/commonjs/hooks.js.map +1 -1
- package/lib/commonjs/index.js +10 -85
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/logger.js +4 -14
- package/lib/commonjs/logger.js.map +1 -1
- package/lib/commonjs/polyfills/EncoderDecoderTogether.min.js +105 -0
- package/lib/commonjs/polyfills/EncoderDecoderTogether.min.js.map +1 -0
- package/lib/commonjs/useParticipant.js +5 -13
- package/lib/commonjs/useParticipant.js.map +1 -1
- package/lib/commonjs/useRoom.js +17 -33
- package/lib/commonjs/useRoom.js.map +1 -1
- package/lib/module/audio/AudioManager.js +3 -17
- package/lib/module/audio/AudioManager.js.map +1 -1
- package/lib/module/audio/AudioSession.js +54 -16
- package/lib/module/audio/AudioSession.js.map +1 -1
- package/lib/module/components/LiveKitRoom.js +1 -0
- package/lib/module/components/LiveKitRoom.js.map +1 -1
- package/lib/module/components/VideoTrack.js +18 -44
- package/lib/module/components/VideoTrack.js.map +1 -1
- package/lib/module/components/VideoView.js +18 -42
- package/lib/module/components/VideoView.js.map +1 -1
- package/lib/module/components/ViewPortDetector.js +13 -54
- package/lib/module/components/ViewPortDetector.js.map +1 -1
- package/lib/module/hooks.js +1 -2
- package/lib/module/hooks.js.map +1 -1
- package/lib/module/index.js +6 -24
- package/lib/module/index.js.map +1 -1
- package/lib/module/logger.js +2 -6
- package/lib/module/logger.js.map +1 -1
- package/lib/module/polyfills/EncoderDecoderTogether.min.js +105 -0
- package/lib/module/polyfills/EncoderDecoderTogether.min.js.map +1 -0
- package/lib/module/useParticipant.js +5 -11
- package/lib/module/useParticipant.js.map +1 -1
- package/lib/module/useRoom.js +17 -30
- package/lib/module/useRoom.js.map +1 -1
- package/lib/typescript/babel.config.d.ts +1 -0
- package/lib/typescript/docs/assets/icons.d.ts +0 -0
- package/lib/typescript/docs/assets/main.d.ts +0 -0
- package/lib/typescript/docs/assets/navigation.d.ts +0 -0
- package/lib/typescript/docs/assets/search.d.ts +0 -0
- package/lib/typescript/lib/commonjs/audio/AudioManager.d.ts +10 -0
- package/lib/typescript/lib/commonjs/audio/AudioSession.d.ts +33 -0
- package/lib/typescript/lib/commonjs/components/LiveKitRoom.d.ts +20 -0
- package/lib/typescript/lib/commonjs/components/VideoTrack.d.ts +8 -0
- package/lib/typescript/lib/commonjs/components/VideoView.d.ts +14 -0
- package/lib/typescript/lib/commonjs/components/ViewPortDetector.d.ts +30 -0
- package/lib/typescript/lib/commonjs/hooks.d.ts +29 -0
- package/lib/typescript/lib/commonjs/index.d.ts +10 -0
- package/lib/typescript/lib/commonjs/logger.d.ts +8 -0
- package/lib/typescript/lib/commonjs/useParticipant.d.ts +14 -0
- package/lib/typescript/lib/commonjs/useRoom.d.ts +16 -0
- package/lib/typescript/lib/module/audio/AudioManager.d.ts +9 -0
- package/lib/typescript/lib/module/audio/AudioSession.d.ts +31 -0
- package/lib/typescript/lib/module/components/LiveKitRoom.d.ts +22 -0
- package/lib/typescript/lib/module/components/VideoTrack.d.ts +9 -0
- package/lib/typescript/lib/module/components/VideoView.d.ts +9 -0
- package/lib/typescript/lib/module/components/ViewPortDetector.d.ts +29 -0
- package/lib/typescript/lib/module/hooks.d.ts +1 -0
- package/lib/typescript/lib/module/index.d.ts +18 -0
- package/lib/typescript/lib/module/logger.d.ts +8 -0
- package/lib/typescript/lib/module/polyfills/EncoderDecoderTogether.min.d.ts +0 -0
- package/lib/typescript/lib/module/useParticipant.d.ts +13 -0
- package/lib/typescript/lib/module/useRoom.d.ts +15 -0
- package/lib/typescript/scripts/bootstrap.d.ts +1 -0
- package/lib/typescript/{audio → src/audio}/AudioSession.d.ts +7 -9
- package/lib/typescript/{components → src/components}/LiveKitRoom.d.ts +1 -1
- package/lib/typescript/{components → src/components}/VideoTrack.d.ts +2 -2
- package/lib/typescript/{components → src/components}/VideoView.d.ts +3 -3
- package/lib/typescript/{components → src/components}/ViewPortDetector.d.ts +3 -3
- package/lib/typescript/src/hooks.d.ts +3 -0
- package/lib/typescript/src/index.d.ts +20 -0
- package/lib/typescript/{logger.d.ts → src/logger.d.ts} +2 -2
- package/lib/typescript/src/polyfills/EncoderDecoderTogether.min.d.ts +0 -0
- package/lib/typescript/{useRoom.d.ts → src/useRoom.d.ts} +1 -1
- package/package.json +22 -19
- package/src/audio/AudioSession.ts +0 -2
- package/src/components/LiveKitRoom.tsx +1 -1
- package/src/components/VideoTrack.tsx +7 -2
- package/src/components/VideoView.tsx +8 -3
- package/src/components/ViewPortDetector.tsx +4 -4
- package/src/hooks.ts +12 -9
- package/src/index.tsx +11 -9
- package/src/polyfills/EncoderDecoderTogether.min.js +6 -0
- package/src/useRoom.ts +1 -1
- package/lib/typescript/hooks.d.ts +0 -2
- package/lib/typescript/index.d.ts +0 -19
- /package/lib/typescript/{audio → src/audio}/AudioManager.d.ts +0 -0
- /package/lib/typescript/{useParticipant.d.ts → src/useParticipant.d.ts} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
function _defineProperty(
|
|
2
|
-
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
4
|
import * as React from 'react';
|
|
4
5
|
import { StyleSheet, View } from 'react-native';
|
|
5
6
|
import { LocalVideoTrack, TrackEvent } from 'livekit-client';
|
|
@@ -7,21 +8,17 @@ import { RTCView } from '@livekit/react-native-webrtc';
|
|
|
7
8
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
8
9
|
import { RemoteVideoTrack } from 'livekit-client';
|
|
9
10
|
import ViewPortDetector from './ViewPortDetector';
|
|
10
|
-
export const VideoTrack =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
zOrder,
|
|
18
|
-
mirror
|
|
19
|
-
} = _ref;
|
|
11
|
+
export const VideoTrack = ({
|
|
12
|
+
style = {},
|
|
13
|
+
trackRef,
|
|
14
|
+
objectFit = 'cover',
|
|
15
|
+
zOrder,
|
|
16
|
+
mirror
|
|
17
|
+
}) => {
|
|
20
18
|
const [elementInfo] = useState(() => {
|
|
21
19
|
var _trackRef$publication;
|
|
22
|
-
|
|
23
20
|
let info = new VideoTrackElementInfo();
|
|
24
|
-
info.id = trackRef === null || trackRef === void 0
|
|
21
|
+
info.id = trackRef === null || trackRef === void 0 || (_trackRef$publication = trackRef.publication) === null || _trackRef$publication === void 0 ? void 0 : _trackRef$publication.trackSid;
|
|
25
22
|
return info;
|
|
26
23
|
});
|
|
27
24
|
const layoutOnChange = useCallback(event => elementInfo.onLayout(event), [elementInfo]);
|
|
@@ -33,12 +30,10 @@ export const VideoTrack = _ref => {
|
|
|
33
30
|
const [mediaStream, setMediaStream] = useState(videoTrack === null || videoTrack === void 0 ? void 0 : videoTrack.mediaStream);
|
|
34
31
|
useEffect(() => {
|
|
35
32
|
setMediaStream(videoTrack === null || videoTrack === void 0 ? void 0 : videoTrack.mediaStream);
|
|
36
|
-
|
|
37
33
|
if (videoTrack instanceof LocalVideoTrack) {
|
|
38
34
|
const onRestarted = track => {
|
|
39
35
|
setMediaStream(track === null || track === void 0 ? void 0 : track.mediaStream);
|
|
40
36
|
};
|
|
41
|
-
|
|
42
37
|
videoTrack.on(TrackEvent.Restarted, onRestarted);
|
|
43
38
|
return () => {
|
|
44
39
|
videoTrack.off(TrackEvent.Restarted, onRestarted);
|
|
@@ -49,16 +44,17 @@ export const VideoTrack = _ref => {
|
|
|
49
44
|
}, [videoTrack]);
|
|
50
45
|
useEffect(() => {
|
|
51
46
|
if (videoTrack instanceof RemoteVideoTrack && videoTrack.isAdaptiveStream) {
|
|
52
|
-
videoTrack === null || videoTrack === void 0
|
|
47
|
+
videoTrack === null || videoTrack === void 0 || videoTrack.observeElementInfo(elementInfo);
|
|
53
48
|
return () => {
|
|
54
|
-
videoTrack === null || videoTrack === void 0
|
|
49
|
+
videoTrack === null || videoTrack === void 0 || videoTrack.stopObservingElementInfo(elementInfo);
|
|
55
50
|
};
|
|
56
51
|
} else {
|
|
57
52
|
return () => {};
|
|
58
53
|
}
|
|
59
54
|
}, [videoTrack, elementInfo]);
|
|
60
55
|
return /*#__PURE__*/React.createElement(View, {
|
|
61
|
-
style: {
|
|
56
|
+
style: {
|
|
57
|
+
...style,
|
|
62
58
|
...styles.container
|
|
63
59
|
},
|
|
64
60
|
onLayout: layoutOnChange
|
|
@@ -69,7 +65,7 @@ export const VideoTrack = _ref => {
|
|
|
69
65
|
propKey: videoTrack
|
|
70
66
|
}, /*#__PURE__*/React.createElement(RTCView, {
|
|
71
67
|
style: styles.videoTrack,
|
|
72
|
-
streamURL: (
|
|
68
|
+
streamURL: (mediaStream === null || mediaStream === void 0 ? void 0 : mediaStream.toURL()) ?? '',
|
|
73
69
|
objectFit: objectFit,
|
|
74
70
|
zOrder: zOrder,
|
|
75
71
|
mirror: mirror
|
|
@@ -82,44 +78,28 @@ const styles = StyleSheet.create({
|
|
|
82
78
|
width: '100%'
|
|
83
79
|
}
|
|
84
80
|
});
|
|
85
|
-
|
|
86
81
|
class VideoTrackElementInfo {
|
|
87
82
|
constructor() {
|
|
88
83
|
_defineProperty(this, "element", {});
|
|
89
|
-
|
|
90
84
|
_defineProperty(this, "something", void 0);
|
|
91
|
-
|
|
92
85
|
_defineProperty(this, "id", void 0);
|
|
93
|
-
|
|
94
86
|
_defineProperty(this, "_width", 0);
|
|
95
|
-
|
|
96
87
|
_defineProperty(this, "_height", 0);
|
|
97
|
-
|
|
98
88
|
_defineProperty(this, "_observing", false);
|
|
99
|
-
|
|
100
89
|
_defineProperty(this, "visible", true);
|
|
101
|
-
|
|
102
90
|
_defineProperty(this, "visibilityChangedAt", void 0);
|
|
103
|
-
|
|
104
91
|
_defineProperty(this, "pictureInPicture", false);
|
|
105
|
-
|
|
106
92
|
_defineProperty(this, "handleResize", void 0);
|
|
107
|
-
|
|
108
93
|
_defineProperty(this, "handleVisibilityChanged", void 0);
|
|
109
|
-
|
|
110
94
|
_defineProperty(this, "width", () => this._width);
|
|
111
|
-
|
|
112
95
|
_defineProperty(this, "height", () => this._height);
|
|
113
96
|
}
|
|
114
|
-
|
|
115
97
|
observe() {
|
|
116
98
|
this._observing = true;
|
|
117
99
|
}
|
|
118
|
-
|
|
119
100
|
stopObserving() {
|
|
120
101
|
this._observing = false;
|
|
121
102
|
}
|
|
122
|
-
|
|
123
103
|
onLayout(event) {
|
|
124
104
|
let {
|
|
125
105
|
width,
|
|
@@ -127,26 +107,20 @@ class VideoTrackElementInfo {
|
|
|
127
107
|
} = event.nativeEvent.layout;
|
|
128
108
|
this._width = width;
|
|
129
109
|
this._height = height;
|
|
130
|
-
|
|
131
110
|
if (this._observing) {
|
|
132
111
|
var _this$handleResize;
|
|
133
|
-
|
|
134
|
-
(_this$handleResize = this.handleResize) === null || _this$handleResize === void 0 ? void 0 : _this$handleResize.call(this);
|
|
112
|
+
(_this$handleResize = this.handleResize) === null || _this$handleResize === void 0 || _this$handleResize.call(this);
|
|
135
113
|
}
|
|
136
114
|
}
|
|
137
|
-
|
|
138
115
|
onVisibility(isVisible) {
|
|
139
116
|
if (this.visible !== isVisible) {
|
|
140
117
|
this.visible = isVisible;
|
|
141
118
|
this.visibilityChangedAt = Date.now();
|
|
142
|
-
|
|
143
119
|
if (this._observing) {
|
|
144
120
|
var _this$handleVisibilit;
|
|
145
|
-
|
|
146
|
-
(_this$handleVisibilit = this.handleVisibilityChanged) === null || _this$handleVisibilit === void 0 ? void 0 : _this$handleVisibilit.call(this);
|
|
121
|
+
(_this$handleVisibilit = this.handleVisibilityChanged) === null || _this$handleVisibilit === void 0 || _this$handleVisibilit.call(this);
|
|
147
122
|
}
|
|
148
123
|
}
|
|
149
124
|
}
|
|
150
|
-
|
|
151
125
|
}
|
|
152
126
|
//# sourceMappingURL=VideoTrack.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["React","StyleSheet","View","LocalVideoTrack","TrackEvent","RTCView","useCallback","useEffect","useMemo","useState","RemoteVideoTrack","ViewPortDetector","VideoTrack","style","trackRef","objectFit","zOrder","mirror","elementInfo","_trackRef$publication","info","VideoTrackElementInfo","id","publication","trackSid","layoutOnChange","event","onLayout","visibilityOnChange","isVisible","onVisibility","videoTrack","track","shouldObserveVisibility","isAdaptiveStream","mediaStream","setMediaStream","onRestarted","on","Restarted","off","observeElementInfo","stopObservingElementInfo","createElement","styles","container","onChange","disabled","propKey","streamURL","toURL","create","flex","width","constructor","_defineProperty","_width","_height","observe","_observing","stopObserving","height","nativeEvent","layout","_this$handleResize","handleResize","call","visible","visibilityChangedAt","Date","now","_this$handleVisibilit","handleVisibilityChanged"],"sources":["VideoTrack.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n type LayoutChangeEvent,\n StyleSheet,\n View,\n type ViewStyle,\n} from 'react-native';\nimport {\n type ElementInfo,\n LocalVideoTrack,\n Track,\n TrackEvent,\n} from 'livekit-client';\nimport { RTCView } from '@livekit/react-native-webrtc';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { RemoteVideoTrack } from 'livekit-client';\nimport ViewPortDetector from './ViewPortDetector';\nimport type { TrackReference } from '@livekit/components-react';\n\nexport type VideoTrackProps = {\n trackRef: TrackReference | undefined;\n style?: ViewStyle;\n objectFit?: 'cover' | 'contain' | undefined;\n mirror?: boolean;\n zOrder?: number;\n};\n\nexport const VideoTrack = ({\n style = {},\n trackRef,\n objectFit = 'cover',\n zOrder,\n mirror,\n}: VideoTrackProps) => {\n const [elementInfo] = useState(() => {\n let info = new VideoTrackElementInfo();\n info.id = trackRef?.publication?.trackSid;\n return info;\n });\n\n const layoutOnChange = useCallback(\n (event: LayoutChangeEvent) => elementInfo.onLayout(event),\n [elementInfo]\n );\n const visibilityOnChange = useCallback(\n (isVisible: boolean) => elementInfo.onVisibility(isVisible),\n [elementInfo]\n );\n\n const videoTrack = trackRef?.publication.track;\n\n const shouldObserveVisibility = useMemo(() => {\n return (\n videoTrack instanceof RemoteVideoTrack && videoTrack.isAdaptiveStream\n );\n }, [videoTrack]);\n\n const [mediaStream, setMediaStream] = useState(videoTrack?.mediaStream);\n useEffect(() => {\n setMediaStream(videoTrack?.mediaStream);\n if (videoTrack instanceof LocalVideoTrack) {\n const onRestarted = (track: Track | null) => {\n setMediaStream(track?.mediaStream);\n };\n videoTrack.on(TrackEvent.Restarted, onRestarted);\n\n return () => {\n videoTrack.off(TrackEvent.Restarted, onRestarted);\n };\n } else {\n return () => {};\n }\n }, [videoTrack]);\n\n useEffect(() => {\n if (videoTrack instanceof RemoteVideoTrack && videoTrack.isAdaptiveStream) {\n videoTrack?.observeElementInfo(elementInfo);\n return () => {\n videoTrack?.stopObservingElementInfo(elementInfo);\n };\n } else {\n return () => {};\n }\n }, [videoTrack, elementInfo]);\n\n return (\n <View style={{ ...style, ...styles.container }} onLayout={layoutOnChange}>\n <ViewPortDetector\n onChange={visibilityOnChange}\n style={styles.videoTrack}\n disabled={!shouldObserveVisibility}\n propKey={videoTrack}\n >\n <RTCView\n style={styles.videoTrack}\n streamURL={mediaStream?.toURL() ?? ''}\n objectFit={objectFit}\n zOrder={zOrder}\n mirror={mirror}\n />\n </ViewPortDetector>\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: {},\n videoTrack: {\n flex: 1,\n width: '100%',\n },\n});\n\nclass VideoTrackElementInfo implements ElementInfo {\n element: object = {};\n something?: any;\n id?: string;\n _width = 0;\n _height = 0;\n _observing = false;\n visible: boolean = true;\n visibilityChangedAt: number | undefined;\n pictureInPicture = false;\n handleResize?: (() => void) | undefined;\n handleVisibilityChanged?: (() => void) | undefined;\n width = () => this._width;\n height = () => this._height;\n\n observe(): void {\n this._observing = true;\n }\n stopObserving(): void {\n this._observing = false;\n }\n\n onLayout(event: LayoutChangeEvent) {\n let { width, height } = event.nativeEvent.layout;\n this._width = width;\n this._height = height;\n\n if (this._observing) {\n this.handleResize?.();\n }\n }\n onVisibility(isVisible: boolean) {\n if (this.visible !== isVisible) {\n this.visible = isVisible;\n this.visibilityChangedAt = Date.now();\n if (this._observing) {\n this.handleVisibilityChanged?.();\n }\n }\n }\n}\n"],"mappings":";;;AAAA,OAAO,KAAKA,KAAK,MAA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P,MAAM,GAAGH,KAAK;IACnB,IAAI,CAACI,OAAO,GAAGI,MAAM;IAErB,IAAI,IAAI,CAACF,UAAU,EAAE;MAAA,IAAAK,kBAAA;MACnB,CAAAA,kBAAA,OAAI,CAACC,YAAY,cAAAD,kBAAA,eAAjBA,kBAAA,CAAAE,IAAA,KAAoB,CAAC;IACvB;EACF;EACApC,YAAYA,CAACD,SAAkB,EAAE;IAC/B,IAAI,IAAI,CAACsC,OAAO,KAAKtC,SAAS,EAAE;MAC9B,IAAI,CAACsC,OAAO,GAAGtC,SAAS;MACxB,IAAI,CAACuC,mBAAmB,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC;MACrC,IAAI,IAAI,CAACX,UAAU,EAAE;QAAA,IAAAY,qBAAA;QACnB,CAAAA,qBAAA,OAAI,CAACC,uBAAuB,cAAAD,qBAAA,eAA5BA,qBAAA,CAAAL,IAAA,KAA+B,CAAC;MAClC;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
function _defineProperty(
|
|
2
|
-
|
|
1
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
3
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
3
4
|
import * as React from 'react';
|
|
4
5
|
import { StyleSheet, View } from 'react-native';
|
|
5
6
|
import { LocalVideoTrack, TrackEvent } from 'livekit-client';
|
|
@@ -7,6 +8,7 @@ import { RTCView } from '@livekit/react-native-webrtc';
|
|
|
7
8
|
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
8
9
|
import { RemoteVideoTrack } from 'livekit-client';
|
|
9
10
|
import ViewPortDetector from './ViewPortDetector';
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
* @deprecated use `VideoTrack` and `VideoTrackProps` instead.
|
|
12
14
|
*/
|
|
@@ -14,16 +16,13 @@ import ViewPortDetector from './ViewPortDetector';
|
|
|
14
16
|
/**
|
|
15
17
|
* @deprecated use `VideoTrack` and `VideoTrackProps` instead.
|
|
16
18
|
*/
|
|
17
|
-
export const VideoView =
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
zOrder,
|
|
25
|
-
mirror
|
|
26
|
-
} = _ref;
|
|
19
|
+
export const VideoView = ({
|
|
20
|
+
style = {},
|
|
21
|
+
videoTrack,
|
|
22
|
+
objectFit = 'cover',
|
|
23
|
+
zOrder,
|
|
24
|
+
mirror
|
|
25
|
+
}) => {
|
|
27
26
|
const [elementInfo] = useState(() => {
|
|
28
27
|
let info = new VideoViewElementInfo();
|
|
29
28
|
info.id = videoTrack === null || videoTrack === void 0 ? void 0 : videoTrack.sid;
|
|
@@ -38,12 +37,10 @@ export const VideoView = _ref => {
|
|
|
38
37
|
const [mediaStream, setMediaStream] = useState(videoTrack === null || videoTrack === void 0 ? void 0 : videoTrack.mediaStream);
|
|
39
38
|
useEffect(() => {
|
|
40
39
|
setMediaStream(videoTrack === null || videoTrack === void 0 ? void 0 : videoTrack.mediaStream);
|
|
41
|
-
|
|
42
40
|
if (videoTrack instanceof LocalVideoTrack) {
|
|
43
41
|
const onRestarted = track => {
|
|
44
42
|
setMediaStream(track === null || track === void 0 ? void 0 : track.mediaStream);
|
|
45
43
|
};
|
|
46
|
-
|
|
47
44
|
videoTrack.on(TrackEvent.Restarted, onRestarted);
|
|
48
45
|
return () => {
|
|
49
46
|
videoTrack.off(TrackEvent.Restarted, onRestarted);
|
|
@@ -54,16 +51,17 @@ export const VideoView = _ref => {
|
|
|
54
51
|
}, [videoTrack]);
|
|
55
52
|
useEffect(() => {
|
|
56
53
|
if (videoTrack instanceof RemoteVideoTrack && videoTrack.isAdaptiveStream) {
|
|
57
|
-
videoTrack === null || videoTrack === void 0
|
|
54
|
+
videoTrack === null || videoTrack === void 0 || videoTrack.observeElementInfo(elementInfo);
|
|
58
55
|
return () => {
|
|
59
|
-
videoTrack === null || videoTrack === void 0
|
|
56
|
+
videoTrack === null || videoTrack === void 0 || videoTrack.stopObservingElementInfo(elementInfo);
|
|
60
57
|
};
|
|
61
58
|
} else {
|
|
62
59
|
return () => {};
|
|
63
60
|
}
|
|
64
61
|
}, [videoTrack, elementInfo]);
|
|
65
62
|
return /*#__PURE__*/React.createElement(View, {
|
|
66
|
-
style: {
|
|
63
|
+
style: {
|
|
64
|
+
...style,
|
|
67
65
|
...styles.container
|
|
68
66
|
},
|
|
69
67
|
onLayout: layoutOnChange
|
|
@@ -74,7 +72,7 @@ export const VideoView = _ref => {
|
|
|
74
72
|
propKey: videoTrack
|
|
75
73
|
}, /*#__PURE__*/React.createElement(RTCView, {
|
|
76
74
|
style: styles.videoView,
|
|
77
|
-
streamURL: (
|
|
75
|
+
streamURL: (mediaStream === null || mediaStream === void 0 ? void 0 : mediaStream.toURL()) ?? '',
|
|
78
76
|
objectFit: objectFit,
|
|
79
77
|
zOrder: zOrder,
|
|
80
78
|
mirror: mirror
|
|
@@ -87,44 +85,28 @@ const styles = StyleSheet.create({
|
|
|
87
85
|
width: '100%'
|
|
88
86
|
}
|
|
89
87
|
});
|
|
90
|
-
|
|
91
88
|
class VideoViewElementInfo {
|
|
92
89
|
constructor() {
|
|
93
90
|
_defineProperty(this, "element", {});
|
|
94
|
-
|
|
95
91
|
_defineProperty(this, "something", void 0);
|
|
96
|
-
|
|
97
92
|
_defineProperty(this, "id", void 0);
|
|
98
|
-
|
|
99
93
|
_defineProperty(this, "_width", 0);
|
|
100
|
-
|
|
101
94
|
_defineProperty(this, "_height", 0);
|
|
102
|
-
|
|
103
95
|
_defineProperty(this, "_observing", false);
|
|
104
|
-
|
|
105
96
|
_defineProperty(this, "visible", true);
|
|
106
|
-
|
|
107
97
|
_defineProperty(this, "visibilityChangedAt", void 0);
|
|
108
|
-
|
|
109
98
|
_defineProperty(this, "pictureInPicture", false);
|
|
110
|
-
|
|
111
99
|
_defineProperty(this, "handleResize", void 0);
|
|
112
|
-
|
|
113
100
|
_defineProperty(this, "handleVisibilityChanged", void 0);
|
|
114
|
-
|
|
115
101
|
_defineProperty(this, "width", () => this._width);
|
|
116
|
-
|
|
117
102
|
_defineProperty(this, "height", () => this._height);
|
|
118
103
|
}
|
|
119
|
-
|
|
120
104
|
observe() {
|
|
121
105
|
this._observing = true;
|
|
122
106
|
}
|
|
123
|
-
|
|
124
107
|
stopObserving() {
|
|
125
108
|
this._observing = false;
|
|
126
109
|
}
|
|
127
|
-
|
|
128
110
|
onLayout(event) {
|
|
129
111
|
let {
|
|
130
112
|
width,
|
|
@@ -132,26 +114,20 @@ class VideoViewElementInfo {
|
|
|
132
114
|
} = event.nativeEvent.layout;
|
|
133
115
|
this._width = width;
|
|
134
116
|
this._height = height;
|
|
135
|
-
|
|
136
117
|
if (this._observing) {
|
|
137
118
|
var _this$handleResize;
|
|
138
|
-
|
|
139
|
-
(_this$handleResize = this.handleResize) === null || _this$handleResize === void 0 ? void 0 : _this$handleResize.call(this);
|
|
119
|
+
(_this$handleResize = this.handleResize) === null || _this$handleResize === void 0 || _this$handleResize.call(this);
|
|
140
120
|
}
|
|
141
121
|
}
|
|
142
|
-
|
|
143
122
|
onVisibility(isVisible) {
|
|
144
123
|
if (this.visible !== isVisible) {
|
|
145
124
|
this.visible = isVisible;
|
|
146
125
|
this.visibilityChangedAt = Date.now();
|
|
147
|
-
|
|
148
126
|
if (this._observing) {
|
|
149
127
|
var _this$handleVisibilit;
|
|
150
|
-
|
|
151
|
-
(_this$handleVisibilit = this.handleVisibilityChanged) === null || _this$handleVisibilit === void 0 ? void 0 : _this$handleVisibilit.call(this);
|
|
128
|
+
(_this$handleVisibilit = this.handleVisibilityChanged) === null || _this$handleVisibilit === void 0 || _this$handleVisibilit.call(this);
|
|
152
129
|
}
|
|
153
130
|
}
|
|
154
131
|
}
|
|
155
|
-
|
|
156
132
|
}
|
|
157
133
|
//# sourceMappingURL=VideoView.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["React","StyleSheet","View","LocalVideoTrack","TrackEvent","RTCView","useCallback","useEffect","useMemo","useState","RemoteVideoTrack","ViewPortDetector","VideoView","style","videoTrack","objectFit","zOrder","mirror","elementInfo","info","VideoViewElementInfo","id","sid","something","layoutOnChange","event","onLayout","visibilityOnChange","isVisible","onVisibility","shouldObserveVisibility","isAdaptiveStream","mediaStream","setMediaStream","onRestarted","track","on","Restarted","off","observeElementInfo","stopObservingElementInfo","createElement","styles","container","onChange","videoView","disabled","propKey","streamURL","toURL","create","flex","width","constructor","_defineProperty","_width","_height","observe","_observing","stopObserving","height","nativeEvent","layout","_this$handleResize","handleResize","call","visible","visibilityChangedAt","Date","now","_this$handleVisibilit","handleVisibilityChanged"],"sources":["VideoView.tsx"],"sourcesContent":["import * as React from 'react';\n\nimport {\n type LayoutChangeEvent,\n StyleSheet,\n View,\n type ViewStyle,\n} from 'react-native';\nimport {\n type ElementInfo,\n LocalVideoTrack,\n Track,\n TrackEvent,\n type VideoTrack,\n} from 'livekit-client';\nimport { RTCView } from '@livekit/react-native-webrtc';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { RemoteVideoTrack } from 'livekit-client';\nimport ViewPortDetector from './ViewPortDetector';\n\n/**\n * @deprecated use `VideoTrack` and `VideoTrackProps` instead.\n */\nexport type Props = {\n videoTrack?: VideoTrack | undefined;\n style?: ViewStyle;\n objectFit?: 'cover' | 'contain' | undefined;\n mirror?: boolean;\n zOrder?: number;\n};\n\n/**\n * @deprecated use `VideoTrack` and `VideoTrackProps` instead.\n */\nexport const VideoView = ({\n style = {},\n videoTrack,\n objectFit = 'cover',\n zOrder,\n mirror,\n}: Props) => {\n const [elementInfo] = useState(() => {\n let info = new VideoViewElementInfo();\n info.id = videoTrack?.sid;\n info.something = videoTrack;\n return info;\n });\n\n const layoutOnChange = useCallback(\n (event: LayoutChangeEvent) => elementInfo.onLayout(event),\n [elementInfo]\n );\n const visibilityOnChange = useCallback(\n (isVisible: boolean) => elementInfo.onVisibility(isVisible),\n [elementInfo]\n );\n const shouldObserveVisibility = useMemo(() => {\n return (\n videoTrack instanceof RemoteVideoTrack && videoTrack.isAdaptiveStream\n );\n }, [videoTrack]);\n\n const [mediaStream, setMediaStream] = useState(videoTrack?.mediaStream);\n useEffect(() => {\n setMediaStream(videoTrack?.mediaStream);\n if (videoTrack instanceof LocalVideoTrack) {\n const onRestarted = (track: Track | null) => {\n setMediaStream(track?.mediaStream);\n };\n videoTrack.on(TrackEvent.Restarted, onRestarted);\n\n return () => {\n videoTrack.off(TrackEvent.Restarted, onRestarted);\n };\n } else {\n return () => {};\n }\n }, [videoTrack]);\n\n useEffect(() => {\n if (videoTrack instanceof RemoteVideoTrack && videoTrack.isAdaptiveStream) {\n videoTrack?.observeElementInfo(elementInfo);\n return () => {\n videoTrack?.stopObservingElementInfo(elementInfo);\n };\n } else {\n return () => {};\n }\n }, [videoTrack, elementInfo]);\n\n return (\n <View style={{ ...style, ...styles.container }} onLayout={layoutOnChange}>\n <ViewPortDetector\n onChange={visibilityOnChange}\n style={styles.videoView}\n disabled={!shouldObserveVisibility}\n propKey={videoTrack}\n >\n <RTCView\n style={styles.videoView}\n streamURL={mediaStream?.toURL() ?? ''}\n objectFit={objectFit}\n zOrder={zOrder}\n mirror={mirror}\n />\n </ViewPortDetector>\n </View>\n );\n};\n\nconst styles = StyleSheet.create({\n container: {},\n videoView: {\n flex: 1,\n width: '100%',\n },\n});\n\nclass VideoViewElementInfo implements ElementInfo {\n element: object = {};\n something?: any;\n id?: string;\n _width = 0;\n _height = 0;\n _observing = false;\n visible: boolean = true;\n visibilityChangedAt: number | undefined;\n pictureInPicture = false;\n handleResize?: (() => void) | undefined;\n handleVisibilityChanged?: (() => void) | undefined;\n width = () => this._width;\n height = () => this._height;\n\n observe(): void {\n this._observing = true;\n }\n stopObserving(): void {\n this._observing = false;\n }\n\n onLayout(event: LayoutChangeEvent) {\n let { width, height } = event.nativeEvent.layout;\n this._width = width;\n this._height = height;\n\n if (this._observing) {\n this.handleResize?.();\n }\n }\n onVisibility(isVisible: boolean) {\n if (this.visible !== isVisible) {\n this.visible = isVisible;\n this.visibilityChangedAt = Date.now();\n if (this._observing) {\n this.handleVisibilityChanged?.();\n }\n }\n }\n}\n"],"mappings":";;;AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAE9B,SAEEC,UAAU,EACVC,IAAI,QAEC,cAAc;AACrB,SAEEC,eAAe,EAEfC,UAAU,QAEL,gBAAgB;AACvB,SAASC,OAAO,QAAQ,8BAA8B;AACtD,SAASC,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACjE,SAASC,gBAAgB,QAAQ,gBAAgB;AACjD,OAAOC,gBAAgB,MAAM,oBAAoB;;AAEjD;AACA;AACA;;AASA;AACA;AACA;AACA,OAAO,MAAMC,SAAS,GAAGA,CAAC;EACxBC,KAAK,GAAG,CAAC,CAAC;EACVC,UAAU;EACVC,SAAS,GAAG,OAAO;EACnBC,MAAM;EACNC;AACK,CAAC,KAAK;EACX,MAAM,CAACC,WAAW,CAAC,GAAGT,QAAQ,CAAC,MAAM;IACnC,IAAIU,IAAI,GAAG,IAAIC,oBAAoB,CAAC,CAAC;IACrCD,IAAI,CAACE,EAAE,GAAGP,UAAU,aAAVA,UAAU,uBAAVA,UAAU,CAAEQ,GAAG;IACzBH,IAAI,CAACI,SAAS,GAAGT,UAAU;IAC3B,OAAOK,IAAI;EACb,CAAC,CAAC;EAEF,MAAMK,cAAc,GAAGlB,WAAW,CAC/BmB,KAAwB,IAAKP,WAAW,CAACQ,Q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hB,MAAM,IAAI,CAACC,MAAM;IAAAD,eAAA,iBAChB,MAAM,IAAI,CAACE,OAAO;EAAA;EAE3BC,OAAOA,CAAA,EAAS;IACd,IAAI,CAACC,UAAU,GAAG,IAAI;EACxB;EACAC,aAAaA,CAAA,EAAS;IACpB,IAAI,CAACD,UAAU,GAAG,KAAK;EACzB;EAEAhC,QAAQA,CAACD,KAAwB,EAAE;IACjC,IAAI;MAAE2B,KAAK;MAAEQ;IAAO,CAAC,GAAGnC,KAAK,CAACoC,WAAW,CAACC,MAAM;IAChD,IAAI,CAACP,MAAM,GAAGH,KAAK;IACnB,IAAI,CAACI,OAAO,GAAGI,MAAM;IAErB,IAAI,IAAI,CAACF,UAAU,EAAE;MAAA,IAAAK,kBAAA;MACnB,CAAAA,kBAAA,OAAI,CAACC,YAAY,cAAAD,kBAAA,eAAjBA,kBAAA,CAAAE,IAAA,KAAoB,CAAC;IACvB;EACF;EACApC,YAAYA,CAACD,SAAkB,EAAE;IAC/B,IAAI,IAAI,CAACsC,OAAO,KAAKtC,SAAS,EAAE;MAC9B,IAAI,CAACsC,OAAO,GAAGtC,SAAS;MACxB,IAAI,CAACuC,mBAAmB,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC;MACrC,IAAI,IAAI,CAACX,UAAU,EAAE;QAAA,IAAAY,qBAAA;QACnB,CAAAA,qBAAA,OAAI,CAACC,uBAAuB,cAAAD,qBAAA,eAA5BA,qBAAA,CAAAL,IAAA,KAA+B,CAAC;MAClC;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -1,171 +1,133 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
function _extends() { _extends = Object.assign
|
|
4
|
-
|
|
5
|
-
function
|
|
6
|
-
|
|
3
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
import React, { Component } from 'react';
|
|
8
8
|
import { AppState, View } from 'react-native';
|
|
9
9
|
const DEFAULT_DELAY = 1000;
|
|
10
|
-
|
|
11
10
|
class TimeoutHandler {
|
|
12
11
|
constructor() {
|
|
13
12
|
_defineProperty(this, "handlerRef", {
|
|
14
13
|
id: -1
|
|
15
14
|
});
|
|
16
15
|
}
|
|
17
|
-
|
|
18
16
|
get handler() {
|
|
19
17
|
return this.handlerRef.id;
|
|
20
18
|
}
|
|
21
|
-
|
|
22
19
|
set handler(n) {
|
|
23
20
|
this.handlerRef.id = n;
|
|
24
21
|
}
|
|
25
|
-
|
|
26
22
|
clear() {
|
|
27
23
|
clearTimeout(this.handlerRef.id);
|
|
28
24
|
}
|
|
29
|
-
|
|
30
25
|
}
|
|
31
|
-
|
|
32
|
-
function setIntervalWithTimeout(callback, intervalMs) {
|
|
33
|
-
let handleWrapper = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new TimeoutHandler();
|
|
26
|
+
function setIntervalWithTimeout(callback, intervalMs, handleWrapper = new TimeoutHandler()) {
|
|
34
27
|
let cleared = false;
|
|
35
|
-
|
|
36
28
|
const timeout = () => {
|
|
37
29
|
handleWrapper.handler = setTimeout(() => {
|
|
38
30
|
callback(() => {
|
|
39
31
|
cleared = true;
|
|
40
32
|
handleWrapper.clear();
|
|
41
33
|
});
|
|
42
|
-
|
|
43
34
|
if (!cleared) {
|
|
44
35
|
timeout();
|
|
45
36
|
}
|
|
46
37
|
}, intervalMs);
|
|
47
38
|
};
|
|
48
|
-
|
|
49
39
|
timeout();
|
|
50
40
|
return handleWrapper;
|
|
51
41
|
}
|
|
42
|
+
|
|
52
43
|
/**
|
|
53
44
|
* Detects when this is in the viewport and visible.
|
|
54
45
|
*
|
|
55
46
|
* Will not fire visibility changes for zero width/height components.
|
|
56
47
|
*/
|
|
57
|
-
|
|
58
|
-
|
|
59
48
|
export default class ViewPortDetector extends Component {
|
|
60
49
|
constructor(props) {
|
|
61
50
|
super(props);
|
|
62
|
-
|
|
63
51
|
_defineProperty(this, "lastValue", null);
|
|
64
|
-
|
|
65
52
|
_defineProperty(this, "interval", null);
|
|
66
|
-
|
|
67
53
|
_defineProperty(this, "view", null);
|
|
68
|
-
|
|
69
54
|
_defineProperty(this, "lastAppStateActive", false);
|
|
70
|
-
|
|
71
55
|
_defineProperty(this, "appStateSubscription", null);
|
|
72
|
-
|
|
73
56
|
_defineProperty(this, "hasValidTimeout", (disabled, delay) => {
|
|
74
|
-
let disabledValue = disabled
|
|
75
|
-
let delayValue = delay
|
|
57
|
+
let disabledValue = disabled ?? false;
|
|
58
|
+
let delayValue = delay ?? DEFAULT_DELAY;
|
|
76
59
|
return AppState.currentState === 'active' && !disabledValue && delayValue > 0;
|
|
77
60
|
});
|
|
78
|
-
|
|
79
61
|
_defineProperty(this, "handleAppStateChange", nextAppState => {
|
|
80
62
|
let nextAppStateActive = nextAppState === 'active';
|
|
81
|
-
|
|
82
63
|
if (this.lastAppStateActive !== nextAppStateActive) {
|
|
83
64
|
this.checkVisibility();
|
|
84
65
|
}
|
|
85
|
-
|
|
86
66
|
this.lastAppStateActive = nextAppStateActive;
|
|
87
|
-
|
|
88
67
|
if (!this.hasValidTimeout(this.props.disabled, this.props.delay)) {
|
|
89
68
|
this.stopWatching();
|
|
90
69
|
} else {
|
|
91
70
|
this.startWatching();
|
|
92
71
|
}
|
|
93
72
|
});
|
|
94
|
-
|
|
95
73
|
_defineProperty(this, "startWatching", () => {
|
|
96
74
|
if (this.interval) {
|
|
97
75
|
return;
|
|
98
76
|
}
|
|
99
|
-
|
|
100
77
|
this.interval = setIntervalWithTimeout(this.checkVisibility, this.props.delay || DEFAULT_DELAY);
|
|
101
78
|
});
|
|
102
|
-
|
|
103
79
|
_defineProperty(this, "stopWatching", () => {
|
|
104
80
|
var _this$interval;
|
|
105
|
-
|
|
106
|
-
(_this$interval = this.interval) === null || _this$interval === void 0 ? void 0 : _this$interval.clear();
|
|
81
|
+
(_this$interval = this.interval) === null || _this$interval === void 0 || _this$interval.clear();
|
|
107
82
|
this.interval = null;
|
|
108
83
|
});
|
|
109
|
-
|
|
110
84
|
_defineProperty(this, "checkVisibility", () => {
|
|
111
85
|
if (!this.view) {
|
|
112
86
|
return;
|
|
113
87
|
}
|
|
114
|
-
|
|
115
88
|
if (AppState.currentState !== 'active') {
|
|
116
89
|
this.updateVisibility(false);
|
|
117
90
|
return;
|
|
118
91
|
}
|
|
119
|
-
|
|
120
92
|
this.view.measure((_x, _y, width, height, _pageX, _pageY) => {
|
|
121
93
|
this.checkInViewPort(width, height);
|
|
122
94
|
});
|
|
123
95
|
});
|
|
124
|
-
|
|
125
96
|
_defineProperty(this, "checkInViewPort", (width, height) => {
|
|
126
|
-
let isVisible;
|
|
127
|
-
|
|
97
|
+
let isVisible;
|
|
98
|
+
// Not visible if any of these are missing.
|
|
128
99
|
if (!width || !height) {
|
|
129
100
|
isVisible = false;
|
|
130
101
|
} else {
|
|
131
102
|
isVisible = true;
|
|
132
103
|
}
|
|
133
|
-
|
|
134
104
|
this.updateVisibility(isVisible);
|
|
135
105
|
});
|
|
136
|
-
|
|
137
106
|
_defineProperty(this, "updateVisibility", isVisible => {
|
|
138
107
|
if (this.lastValue !== isVisible) {
|
|
139
108
|
var _this$props$onChange, _this$props;
|
|
140
|
-
|
|
141
109
|
this.lastValue = isVisible;
|
|
142
|
-
(_this$props$onChange = (_this$props = this.props).onChange) === null || _this$props$onChange === void 0
|
|
110
|
+
(_this$props$onChange = (_this$props = this.props).onChange) === null || _this$props$onChange === void 0 || _this$props$onChange.call(_this$props, isVisible);
|
|
143
111
|
}
|
|
144
112
|
});
|
|
145
|
-
|
|
146
113
|
this.state = {
|
|
147
114
|
rectTop: 0,
|
|
148
115
|
rectBottom: 0
|
|
149
116
|
};
|
|
150
117
|
}
|
|
151
|
-
|
|
152
118
|
componentDidMount() {
|
|
153
119
|
this.lastAppStateActive = AppState.currentState === 'active';
|
|
154
120
|
this.appStateSubscription = AppState.addEventListener('change', this.handleAppStateChange);
|
|
155
|
-
|
|
156
121
|
if (this.hasValidTimeout(this.props.disabled, this.props.delay)) {
|
|
157
122
|
this.startWatching();
|
|
158
123
|
}
|
|
159
124
|
}
|
|
160
|
-
|
|
161
125
|
componentWillUnmount() {
|
|
162
126
|
var _this$appStateSubscri;
|
|
163
|
-
|
|
164
|
-
(_this$appStateSubscri = this.appStateSubscription) === null || _this$appStateSubscri === void 0 ? void 0 : _this$appStateSubscri.remove();
|
|
127
|
+
(_this$appStateSubscri = this.appStateSubscription) === null || _this$appStateSubscri === void 0 || _this$appStateSubscri.remove();
|
|
165
128
|
this.appStateSubscription = null;
|
|
166
129
|
this.stopWatching();
|
|
167
130
|
}
|
|
168
|
-
|
|
169
131
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
170
132
|
if (!this.hasValidTimeout(nextProps.disabled, nextProps.delay)) {
|
|
171
133
|
this.stopWatching();
|
|
@@ -173,11 +135,9 @@ export default class ViewPortDetector extends Component {
|
|
|
173
135
|
if (this.props.propKey !== nextProps.propKey) {
|
|
174
136
|
this.lastValue = null;
|
|
175
137
|
}
|
|
176
|
-
|
|
177
138
|
this.startWatching();
|
|
178
139
|
}
|
|
179
140
|
}
|
|
180
|
-
|
|
181
141
|
render() {
|
|
182
142
|
return /*#__PURE__*/React.createElement(View, _extends({
|
|
183
143
|
collapsable: false,
|
|
@@ -186,6 +146,5 @@ export default class ViewPortDetector extends Component {
|
|
|
186
146
|
}
|
|
187
147
|
}, this.props), this.props.children);
|
|
188
148
|
}
|
|
189
|
-
|
|
190
149
|
}
|
|
191
150
|
//# sourceMappingURL=ViewPortDetector.js.map
|