@plusscommunities/pluss-core-app 1.1.5 → 1.2.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/package.json
CHANGED
|
@@ -26,11 +26,10 @@ export const reactionActions = {
|
|
|
26
26
|
},
|
|
27
27
|
});
|
|
28
28
|
},
|
|
29
|
-
addComment: (entityId, entityType,
|
|
29
|
+
addComment: (entityId, entityType, site, comment, image) => {
|
|
30
30
|
const data = {
|
|
31
31
|
entityId,
|
|
32
32
|
entityType,
|
|
33
|
-
entityName,
|
|
34
33
|
site,
|
|
35
34
|
comment,
|
|
36
35
|
};
|
|
@@ -96,7 +96,7 @@ class CommentReply extends Component {
|
|
|
96
96
|
this.props.commentSection.getWrappedInstance().startedAddingComment();
|
|
97
97
|
}
|
|
98
98
|
reactionActions
|
|
99
|
-
.addComment(this.props.entityId, this.props.entityType, this.props.
|
|
99
|
+
.addComment(this.props.entityId, this.props.entityType, this.props.site, text, image)
|
|
100
100
|
.then(res => {
|
|
101
101
|
if (this.props.commentSection) {
|
|
102
102
|
this.props.commentSection.getWrappedInstance().commentAdded(res.data);
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import React, { Component } from 'react';
|
|
2
|
+
import { View, StyleSheet, Dimensions } from 'react-native';
|
|
3
|
+
import YoutubePlayer, { getYoutubeMeta } from 'react-native-youtube-iframe';
|
|
4
|
+
// import { Vimeo } from 'react-native-vimeo-iframe';
|
|
5
|
+
import WebView from 'react-native-webview';
|
|
6
|
+
import { Video } from 'expo-av';
|
|
7
|
+
import { Spinner } from '../../../../src/components/common';
|
|
8
|
+
|
|
9
|
+
const SCREEN_HEIGHT = Dimensions.get('window').height;
|
|
10
|
+
const SCREEN_WIDTH = Dimensions.get('window').width;
|
|
11
|
+
const EXPO_VIDEO_PROPS = { rate: 1, isMuted: false, volume: 1, shouldPlay: true };
|
|
12
|
+
const RETRY_RECOVER = 30000;
|
|
13
|
+
const RETRY_LOADING = 10000;
|
|
14
|
+
|
|
15
|
+
class MediaPlayer extends Component {
|
|
16
|
+
constructor(props) {
|
|
17
|
+
super(props);
|
|
18
|
+
this.state = {
|
|
19
|
+
isUrlLink: true,
|
|
20
|
+
isYoutube: false,
|
|
21
|
+
forceWebview: false,
|
|
22
|
+
heightFactor: 0.565,
|
|
23
|
+
playbackLoaded: false,
|
|
24
|
+
playbackBuffering: false,
|
|
25
|
+
playbackPlaying: false,
|
|
26
|
+
};
|
|
27
|
+
this.youtubePlayer = null;
|
|
28
|
+
this.videoPlayer = null;
|
|
29
|
+
this.checkStreamLoaded = null;
|
|
30
|
+
this.retryLoading = false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
componentDidMount() {
|
|
34
|
+
this.setupForLiveStreaming();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
componentWillUnmount() {
|
|
38
|
+
if (this.checkStreamLoaded) clearInterval(this.checkStreamLoaded);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
getYoutubeVideoId = url => {
|
|
42
|
+
url = url.replace(/(>|<)/gi, '').split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
|
|
43
|
+
if (url[2] !== undefined) {
|
|
44
|
+
const ids = url[2].split(/[^0-9a-z_\-]/i);
|
|
45
|
+
return ids[0];
|
|
46
|
+
} else {
|
|
47
|
+
return '';
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
setupForLiveStreaming = async () => {
|
|
52
|
+
// Extract live stream info
|
|
53
|
+
const { streamUrl } = this.props.streamInfo;
|
|
54
|
+
const isUrlLink = streamUrl.startsWith('http');
|
|
55
|
+
const isYoutube = streamUrl.includes('youtube.com/watch?v=') || streamUrl.includes('youtu.be/');
|
|
56
|
+
this.setState({ isUrlLink, isYoutube });
|
|
57
|
+
|
|
58
|
+
// if (isYoutube) {
|
|
59
|
+
// const metadata = await getYoutubeMeta(this.getYoutubeVideoId(streamUrl));
|
|
60
|
+
// this.setState({ heightFactor: metadata.height / metadata.width });
|
|
61
|
+
// console.log('youtube metadata', metadata);
|
|
62
|
+
// }
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
getStreamPlaybackUrl = () => {
|
|
66
|
+
// return 'https://stream.mux.com/nflNhyFQMlrSt00II01Hjh2BLSW009PH1tl023pdpJ01s1vc.m3u8';
|
|
67
|
+
return `https://stream.mux.com/${this.props.streamInfo.playbackId}.m3u8`;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
checkReloadStream = (wait = RETRY_LOADING, force = false) => {
|
|
71
|
+
if (!force && this.retryLoading) return;
|
|
72
|
+
|
|
73
|
+
console.log(`Check loading in ${wait} milliseconds...`);
|
|
74
|
+
this.retryLoading = true;
|
|
75
|
+
setTimeout(async () => {
|
|
76
|
+
const { playbackLoaded, playbackBuffering } = this.state;
|
|
77
|
+
try {
|
|
78
|
+
if (playbackLoaded === false || playbackBuffering === true) {
|
|
79
|
+
console.log('Reloading started');
|
|
80
|
+
await this.videoPlayer.loadAsync(
|
|
81
|
+
{ uri: this.getStreamPlaybackUrl(), overrideFileExtensionAndroid: 'm3u8' },
|
|
82
|
+
EXPO_VIDEO_PROPS,
|
|
83
|
+
false,
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
console.log('Already loaded - not reloading');
|
|
87
|
+
}
|
|
88
|
+
this.retryLoading = false;
|
|
89
|
+
} catch {}
|
|
90
|
+
}, wait);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
onStreamLoadStart = () => {
|
|
94
|
+
console.log('Stream load started');
|
|
95
|
+
this.checkStreamLoaded = setInterval(() => {
|
|
96
|
+
const { playbackLoaded } = this.state;
|
|
97
|
+
if (playbackLoaded === false) {
|
|
98
|
+
console.log('Stream loading failed unexpectedly');
|
|
99
|
+
this.checkReloadStream(1000, true);
|
|
100
|
+
} else {
|
|
101
|
+
clearInterval(this.checkStreamLoaded);
|
|
102
|
+
}
|
|
103
|
+
}, RETRY_RECOVER);
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
onStreamLoaded = status => {
|
|
107
|
+
console.log(`Stream loaded - isLoaded:${status.isLoaded}, isBuffering:${status.isBuffering}, isPlaying:${status.isPlaying}`);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
onStreamError = error => {
|
|
111
|
+
console.log('Stream error', error);
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
onStreamStatusUpdate = status => {
|
|
115
|
+
this.setState(
|
|
116
|
+
{
|
|
117
|
+
playbackLoaded: status.isLoaded,
|
|
118
|
+
playbackBuffering: status.isBuffering,
|
|
119
|
+
playbackPlaying: status.isPlaying,
|
|
120
|
+
},
|
|
121
|
+
() => {
|
|
122
|
+
const { playbackLoaded, playbackBuffering, playbackPlaying, shouldPlay } = this.state;
|
|
123
|
+
// console.log(`Status updated - isLoaded:${playbackLoaded}, isBuffering:${playbackBuffering}, isPlaying:${playbackPlaying}`);
|
|
124
|
+
if (playbackLoaded === false && playbackBuffering === undefined && playbackPlaying === undefined) {
|
|
125
|
+
this.checkReloadStream();
|
|
126
|
+
} else if (playbackLoaded === true && playbackBuffering === true) {
|
|
127
|
+
this.checkReloadStream(RETRY_RECOVER);
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
onYoutubeError = e => {
|
|
134
|
+
// console.log('onYoutubeError', e);
|
|
135
|
+
this.setState({ forceWebview: true });
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
onYoutubeReady = () => {
|
|
139
|
+
// console.log('onYoutubeReady');
|
|
140
|
+
this.setState({ playbackLoaded: true });
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
getYoutubePlayer = (youtubeId, width, height) => (
|
|
144
|
+
<YoutubePlayer
|
|
145
|
+
ref={ref => (this.youtubePlayer = ref)}
|
|
146
|
+
height={height}
|
|
147
|
+
width={width}
|
|
148
|
+
videoId={youtubeId}
|
|
149
|
+
play
|
|
150
|
+
// onChangeState={event => console.log('onChangeState', event)}
|
|
151
|
+
onReady={this.onYoutubeReady}
|
|
152
|
+
onError={this.onYoutubeError}
|
|
153
|
+
// onPlaybackQualityChange={q => console.log('onPlaybackQualityChange', q)}
|
|
154
|
+
volume={50}
|
|
155
|
+
playbackRate={1}
|
|
156
|
+
playerParams={{
|
|
157
|
+
cc_lang_pref: 'us',
|
|
158
|
+
showClosedCaptions: true,
|
|
159
|
+
}}
|
|
160
|
+
/>
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
getWebviewPlayer = embedUrl => (
|
|
164
|
+
<WebView
|
|
165
|
+
startInLoadingState
|
|
166
|
+
javaScriptEnabled
|
|
167
|
+
scrollEnabled={false}
|
|
168
|
+
automaticallyAdjustContentInsets={false}
|
|
169
|
+
mediaPlaybackRequiresUserAction
|
|
170
|
+
style={styles.webView}
|
|
171
|
+
source={{ uri: embedUrl }}
|
|
172
|
+
/>
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
getVideoPlayer = (embedUrl, width, height) => (
|
|
176
|
+
<Video
|
|
177
|
+
ref={vp => {
|
|
178
|
+
this.videoPlayer = vp;
|
|
179
|
+
}}
|
|
180
|
+
source={{ uri: embedUrl }}
|
|
181
|
+
{...EXPO_VIDEO_PROPS}
|
|
182
|
+
resizeMode={Video.RESIZE_MODE_CONTAIN}
|
|
183
|
+
useNativeControls
|
|
184
|
+
style={{ width, height }}
|
|
185
|
+
onLoadStart={this.onStreamLoadStart}
|
|
186
|
+
onLoad={this.onStreamLoaded}
|
|
187
|
+
onError={this.onStreamError}
|
|
188
|
+
onPlaybackStatusUpdate={this.onStreamStatusUpdate}
|
|
189
|
+
/>
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
render() {
|
|
193
|
+
let width, height;
|
|
194
|
+
const { landscape, streamInfo } = this.props;
|
|
195
|
+
if (landscape) {
|
|
196
|
+
width = SCREEN_HEIGHT;
|
|
197
|
+
height = SCREEN_WIDTH;
|
|
198
|
+
} else {
|
|
199
|
+
width = SCREEN_WIDTH;
|
|
200
|
+
height = SCREEN_WIDTH * this.state.heightFactor;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const { isUrlLink, isYoutube, forceWebview, playbackLoaded, playbackBuffering } = this.state;
|
|
204
|
+
const { playbackId, streamUrl } = streamInfo;
|
|
205
|
+
let embedUrl, player;
|
|
206
|
+
if (isYoutube && !forceWebview) {
|
|
207
|
+
const youtubeId = this.getYoutubeVideoId(streamUrl);
|
|
208
|
+
embedUrl = youtubeId ? `https://www.youtube.com/embed/${youtubeId}` : streamUrl;
|
|
209
|
+
player = this.getYoutubePlayer(youtubeId, width, height);
|
|
210
|
+
} else if (isUrlLink) {
|
|
211
|
+
embedUrl = streamUrl;
|
|
212
|
+
player = this.getWebviewPlayer(embedUrl);
|
|
213
|
+
} else if (playbackId) {
|
|
214
|
+
embedUrl = this.getStreamPlaybackUrl();
|
|
215
|
+
player = this.getVideoPlayer(embedUrl, width, height);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// console.log('Streaming:', embedUrl, 'landscape', landscape, 'playbackLoaded', playbackLoaded, 'playbackBuffering', playbackBuffering);
|
|
219
|
+
return (
|
|
220
|
+
<View style={[styles.container, !isUrlLink && { alignItems: 'center' }, { width, height }]}>
|
|
221
|
+
{player}
|
|
222
|
+
{(!playbackLoaded || playbackBuffering) && (
|
|
223
|
+
<View style={styles.loadingContainer}>
|
|
224
|
+
<Spinner color={'#fff'} />
|
|
225
|
+
</View>
|
|
226
|
+
)}
|
|
227
|
+
</View>
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const styles = StyleSheet.create({
|
|
233
|
+
container: {
|
|
234
|
+
backgroundColor: '#000',
|
|
235
|
+
},
|
|
236
|
+
webView: {
|
|
237
|
+
flex: 1,
|
|
238
|
+
},
|
|
239
|
+
loadingContainer: {
|
|
240
|
+
position: 'absolute',
|
|
241
|
+
top: 50,
|
|
242
|
+
left: 0,
|
|
243
|
+
right: 0,
|
|
244
|
+
bottom: 50,
|
|
245
|
+
justifyContent: 'center',
|
|
246
|
+
alignItems: 'center',
|
|
247
|
+
},
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
export default MediaPlayer;
|
package/src/components/index.js
CHANGED
|
@@ -47,3 +47,4 @@ export { default as UserListing } from './UserListing';
|
|
|
47
47
|
export { default as PlussChat } from './PlussChat';
|
|
48
48
|
export { default as PositionedImage } from './PositionedImage';
|
|
49
49
|
export { default as FormattedText } from './FormattedText';
|
|
50
|
+
export { default as MediaPlayer } from './MediaPlayer';
|