Skip to content

Commit

Permalink
lint errors fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Liubov Danilina committed Jan 12, 2024
1 parent bc10cf0 commit 4df68f2
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 44 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: ['module:react-native-dotenv']
plugins: ['module:react-native-dotenv'],
};
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';

import {
registerGlobals
} from 'react-native-webrtc';
import {registerGlobals} from 'react-native-webrtc';

// This registers the shim WebRTC data structures, like RTCPeerConnection as global variables so the SDK can find them anywhere.

Check warning on line 11 in index.js

View workflow job for this annotation

GitHub Actions / Run-Checks

Trailing spaces not allowed

Check failure on line 11 in index.js

View workflow job for this annotation

GitHub Actions / Run-Checks

Delete `································································································································`
registerGlobals();
Expand Down
33 changes: 21 additions & 12 deletions src/components/Multiview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
TouchableHighlight,
FlatList,
Platform,
AppState
AppState,
} from 'react-native';
import React, {useEffect, useRef} from 'react';
import { useNavigation } from '@react-navigation/native';
import {RTCView} from 'react-native-webrtc';
import myStyles from '../../styles/styles.js';

Expand All @@ -18,7 +17,7 @@ import {Logger as MillicastLogger} from '@millicast/sdk';
import {useSelector, useDispatch} from 'react-redux';

window.Logger = MillicastLogger;
Logger.setLevel(MillicastLogger.DEBUG);
window.Logger.setLevel(MillicastLogger.DEBUG);

const amountCols = Platform.isTV ? 2 : 1;

Expand All @@ -27,9 +26,11 @@ export default function Multiview({navigation, route}) {
const sourceIds = useSelector(state => state.viewerReducer.sourceIds);
const playing = useSelector(state => state.viewerReducer.playing);
const millicastView = useSelector(state => state.viewerReducer.millicastView);
const selectedSource = useSelector(state => state.viewerReducer.selectedSource);
const selectedSource = useSelector(
state => state.viewerReducer.selectedSource,
);
const dispatch = useDispatch();

const streamsRef = useRef(null);
const selectedSourceRef = useRef(null);
const millicastViewRef = useRef(null);
Expand All @@ -39,7 +40,9 @@ export default function Multiview({navigation, route}) {
millicastViewRef.current = millicastView;

const addRemoteTrack = async sourceId => {
const isAlreadyProjected = streams.some(stream => stream.sourceId === sourceId);
const isAlreadyProjected = streams.some(
stream => stream.sourceId === sourceId,
);
if (!isAlreadyProjected) {
const mediaStream = new MediaStream();

Check failure on line 47 in src/components/Multiview.js

View workflow job for this annotation

GitHub Actions / Run-Checks

'MediaStream' is not defined
const transceiver = await millicastView.addRemoteTrack('video', [
Expand All @@ -61,11 +64,15 @@ export default function Multiview({navigation, route}) {
};

const navigateSingleView = async (url = null, mid = null) => {
dispatch({ type: 'viewer/setSelectedSource', payload: { url, mid } });
dispatch({type: 'viewer/setSelectedSource', payload: {url, mid}});

try {
const listVideoMids = streamsRef.current.map(track => track.videoMid).filter(x => (x != '0') && (x != mid));
const streamAux = streamsRef.current.filter(stream => !listVideoMids.includes(stream.videoMid))
const listVideoMids = streamsRef.current
.map(track => track.videoMid)
.filter(x => x != '0' && x != mid);

Check warning on line 72 in src/components/Multiview.js

View workflow job for this annotation

GitHub Actions / Run-Checks

Expected '!==' and instead saw '!='

Check warning on line 72 in src/components/Multiview.js

View workflow job for this annotation

GitHub Actions / Run-Checks

Expected '!==' and instead saw '!='
const streamAux = streamsRef.current.filter(
stream => !listVideoMids.includes(stream.videoMid),
);

await millicastViewRef.current.unproject(listVideoMids);

Expand All @@ -75,7 +82,7 @@ export default function Multiview({navigation, route}) {
}

navigation.navigate('Viewer Main');
}
};

useEffect(() => {
// componentWillMount
Expand All @@ -93,7 +100,7 @@ export default function Multiview({navigation, route}) {
}
};
initializeMultiview();

const subscription = AppState.addEventListener('change', nextAppState => {
if (nextAppState === 'background') {
navigation.navigate('Viewer Main');
Expand Down Expand Up @@ -156,7 +163,9 @@ export default function Multiview({navigation, route}) {
hasTVPreferredFocus
style={{padding: 10, bottom: 150, borderRadius: 6}}
underlayColor="#AA33FF"
onPress={() => navigateSingleView(item.stream.toURL(), item.videoMid)}>
onPress={() =>
navigateSingleView(item.stream.toURL(), item.videoMid)
}>
<Text style={{color: 'white'}}>
{!item.sourceId ? 'Main' : String(item.sourceId)}
</Text>
Expand Down
22 changes: 15 additions & 7 deletions src/components/Publisher.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
View,
Text,
TouchableOpacity,
AppState
AppState,
} from 'react-native';
import React, {useEffect, useRef, useState} from 'react';
import {RTCView} from 'react-native-webrtc';
Expand All @@ -18,7 +18,7 @@ import {mediaDevices} from 'react-native-webrtc';
import {useDispatch, useSelector} from 'react-redux';

window.Logger = MillicastLogger;
Logger.setLevel(MillicastLogger.DEBUG);
window.Logger.setLevel(MillicastLogger.DEBUG);

export const PublisherMain = ({navigation}) => {
const [intervalId, setIntervalId] = useState(null);
Expand All @@ -28,22 +28,30 @@ export const PublisherMain = ({navigation}) => {

const mediaStream = useSelector(state => state.publisherReducer.mediaStream);
const playing = useSelector(state => state.publisherReducer.playing);
const videoEnabled = useSelector(state => state.publisherReducer.videoEnabled);
const audioEnabled = useSelector(state => state.publisherReducer.audioEnabled);
const videoEnabled = useSelector(
state => state.publisherReducer.videoEnabled,
);
const audioEnabled = useSelector(
state => state.publisherReducer.audioEnabled,
);
const codec = useSelector(state => state.publisherReducer.codec);
const mirror = useSelector(state => state.publisherReducer.mirror);
const userCount = useSelector(state => state.publisherReducer.userCount);
const timePlaying = useSelector(state => state.publisherReducer.timePlaying);
const streamName = useSelector(state => state.publisherReducer.streamName);
const publishingToken = useSelector(state => state.publisherReducer.publishingToken);
const millicastPublish = useSelector(state => state.publisherReducer.millicastPublish);
const publishingToken = useSelector(
state => state.publisherReducer.publishingToken,
);
const millicastPublish = useSelector(
state => state.publisherReducer.millicastPublish,
);
const dispatch = useDispatch();

const playingRef = useRef(null);
const millicastPublishRef = useRef(null);
const mediaStreamRef = useRef(null);
const intervalIdRef = useRef(null);

playingRef.current = playing;
millicastPublishRef.current = millicastPublish;
mediaStreamRef.current = mediaStream;
Expand Down
36 changes: 20 additions & 16 deletions src/components/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Text,
SafeAreaView,
TouchableHighlight,
AppState
AppState,
} from 'react-native';
import {RTCView} from 'react-native-webrtc';
import {
Expand All @@ -21,7 +21,7 @@ import Multiview from './Multiview';
import {useSelector, useDispatch} from 'react-redux';

window.Logger = MillicastLogger;
Logger.setLevel(MillicastLogger.DEBUG);
window.Logger.setLevel(MillicastLogger.DEBUG);

function ViewerMain({navigation}) {
const appState = useRef(AppState.currentState);
Expand All @@ -32,18 +32,23 @@ function ViewerMain({navigation}) {
const playing = useSelector(state => state.viewerReducer.playing);
const streams = useSelector(state => state.viewerReducer.streams);
const sourceIds = useSelector(state => state.viewerReducer.sourceIds);
const selectedSource = useSelector(state => state.viewerReducer.selectedSource);
const selectedSource = useSelector(
state => state.viewerReducer.selectedSource,
);
const millicastView = useSelector(state => state.viewerReducer.millicastView);
const dispatch = useDispatch();

const playingRef = useRef(null);
const millicastViewRef = useRef(null);

playingRef.current = playing;
millicastViewRef.current = millicastView;

useEffect(() => {
const subscription = AppState.addEventListener('change', handleAppStateChange);
const subscription = AppState.addEventListener(
'change',
handleAppStateChange,
);

return () => {
subscription.remove();
Expand All @@ -53,19 +58,22 @@ function ViewerMain({navigation}) {
};
}, []);

Check failure on line 59 in src/components/Viewer.js

View workflow job for this annotation

GitHub Actions / Run-Checks

React Hook useEffect has missing dependencies: 'handleAppStateChange' and 'stopStream'. Either include them or remove the dependency array

const handleAppStateChange = (nextAppState) => {
const handleAppStateChange = nextAppState => {
appState.current = nextAppState;
if (playingRef.current) {
stopStream();
}
}
};

const stopStream = async () => {
await millicastViewRef.current.stop();
dispatch({type: 'viewer/setPlaying', payload: false});
dispatch({type: 'viewer/setIsMediaSet', payload: true});
dispatch({type: 'viewer/setStreams', payload: []});
dispatch({type: 'viewer/setSelectedSource', payload: {url: null, mid: null}});
dispatch({
type: 'viewer/setSelectedSource',
payload: {url: null, mid: null},
});
};

const subscribe = async () => {
Expand Down Expand Up @@ -149,10 +157,7 @@ function ViewerMain({navigation}) {
streams?.[0] ? (
<RTCView
key={selectedSource.mid ?? 'main'}
streamURL={
selectedSource.url ??
streams?.[0]?.stream?.toURL()
}
streamURL={selectedSource.url ?? streams?.[0]?.stream?.toURL()}
style={myStyles.video}
objectFit="contain"
/>
Expand All @@ -175,8 +180,7 @@ function ViewerMain({navigation}) {
{playing ? 'Pause' : 'Play'}
</Text>
</TouchableHighlight>
{
playing &&
{playing && (
<TouchableHighlight
hasTVPreferredFocus
tvParallaxProperties={{magnification: 1.5}}
Expand All @@ -186,7 +190,7 @@ function ViewerMain({navigation}) {
type: 'viewer/setSelectedSource',
payload: {
url: null,
mid: null
mid: null,
},
});
navigation.navigate('Multiview');
Expand All @@ -195,7 +199,7 @@ function ViewerMain({navigation}) {
{playing ? 'Multiview' : null}
</Text>
</TouchableHighlight>
}
)}
</View>
</View>
</>
Expand Down
6 changes: 3 additions & 3 deletions src/store/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createStore } from 'redux';
import reducer from './reducers/index'
import {createStore} from 'redux';
import reducer from './reducers/index';

const store = createStore(reducer)
const store = createStore(reducer);

export default store;
4 changes: 2 additions & 2 deletions src/store/reducers/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const initialState = {
isMediaSet: true,
selectedSource: {
url: null,
mid: null
mid: null,
},
muted: false,
multiView: false,
Expand Down Expand Up @@ -105,7 +105,7 @@ const viewerReducer = (state = initialState, action) => {
streams: [...state.streams, action.payload],
};
case 'viewer/removeStream':
const streams = state.streams.filter(stream => stream !== action.payload)
const streams = state.streams.filter(stream => stream !== action.payload);
return {
...state,
streams: [...streams],
Expand Down

0 comments on commit 4df68f2

Please sign in to comment.