From 4df68f23f54c87ea50bba8f86b774092ed529923 Mon Sep 17 00:00:00 2001 From: Liubov Danilina Date: Fri, 12 Jan 2024 12:35:39 +1100 Subject: [PATCH] lint errors fixed --- .vscode/settings.json | 5 +++++ babel.config.js | 2 +- index.js | 4 +--- src/components/Multiview.js | 33 +++++++++++++++++++++------------ src/components/Publisher.js | 22 +++++++++++++++------- src/components/Viewer.js | 36 ++++++++++++++++++++---------------- src/store/index.js | 6 +++--- src/store/reducers/viewer.js | 4 ++-- 8 files changed, 68 insertions(+), 44 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..dc8891d --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "editor.codeActionsOnSave": { + "source.fixAll.eslint": true + } +} \ No newline at end of file diff --git a/babel.config.js b/babel.config.js index ab13f03..0bfc727 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,4 +1,4 @@ module.exports = { presets: ['module:metro-react-native-babel-preset'], - plugins: ['module:react-native-dotenv'] + plugins: ['module:react-native-dotenv'], }; diff --git a/index.js b/index.js index f27c840..7c4d1de 100644 --- a/index.js +++ b/index.js @@ -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. registerGlobals(); diff --git a/src/components/Multiview.js b/src/components/Multiview.js index deac4a6..8510cbd 100644 --- a/src/components/Multiview.js +++ b/src/components/Multiview.js @@ -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'; @@ -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; @@ -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); @@ -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(); const transceiver = await millicastView.addRemoteTrack('video', [ @@ -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); + const streamAux = streamsRef.current.filter( + stream => !listVideoMids.includes(stream.videoMid), + ); await millicastViewRef.current.unproject(listVideoMids); @@ -75,7 +82,7 @@ export default function Multiview({navigation, route}) { } navigation.navigate('Viewer Main'); - } + }; useEffect(() => { // componentWillMount @@ -93,7 +100,7 @@ export default function Multiview({navigation, route}) { } }; initializeMultiview(); - + const subscription = AppState.addEventListener('change', nextAppState => { if (nextAppState === 'background') { navigation.navigate('Viewer Main'); @@ -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) + }> {!item.sourceId ? 'Main' : String(item.sourceId)} diff --git a/src/components/Publisher.js b/src/components/Publisher.js index 8cfe68f..423600b 100644 --- a/src/components/Publisher.js +++ b/src/components/Publisher.js @@ -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'; @@ -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); @@ -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; diff --git a/src/components/Viewer.js b/src/components/Viewer.js index 876f315..bf3c4a4 100644 --- a/src/components/Viewer.js +++ b/src/components/Viewer.js @@ -5,7 +5,7 @@ import { Text, SafeAreaView, TouchableHighlight, - AppState + AppState, } from 'react-native'; import {RTCView} from 'react-native-webrtc'; import { @@ -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); @@ -32,10 +32,12 @@ 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); @@ -43,7 +45,10 @@ function ViewerMain({navigation}) { millicastViewRef.current = millicastView; useEffect(() => { - const subscription = AppState.addEventListener('change', handleAppStateChange); + const subscription = AppState.addEventListener( + 'change', + handleAppStateChange, + ); return () => { subscription.remove(); @@ -53,19 +58,22 @@ function ViewerMain({navigation}) { }; }, []); - 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 () => { @@ -149,10 +157,7 @@ function ViewerMain({navigation}) { streams?.[0] ? ( @@ -175,8 +180,7 @@ function ViewerMain({navigation}) { {playing ? 'Pause' : 'Play'} - { - playing && + {playing && ( - } + )} diff --git a/src/store/index.js b/src/store/index.js index 318a42b..b70393c 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -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; diff --git a/src/store/reducers/viewer.js b/src/store/reducers/viewer.js index b5108c7..ec225b4 100644 --- a/src/store/reducers/viewer.js +++ b/src/store/reducers/viewer.js @@ -9,7 +9,7 @@ const initialState = { isMediaSet: true, selectedSource: { url: null, - mid: null + mid: null, }, muted: false, multiView: false, @@ -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],