@@ -19,8 +19,8 @@ export const Chat = () => {
1919 const { rtc, rtcMedia} = useContext ( ServiceContext ) ;
2020
2121 const localRef = useRef ( null ) ;
22+ const localStream = localRef . current ?. srcObject ;
2223 const remoteRef = useRef ( null ) ;
23- const localStream = localRef . current ?. srcObject
2424 const listEndRef = useRef ( null )
2525
2626 const [ connecting , setConnecting ] = useState ( false ) ;
@@ -67,6 +67,14 @@ export const Chat = () => {
6767 } ;
6868
6969 useEffect ( ( ) => {
70+ // navigator.mediaDevices.getUserMedia({
71+ // audio: true, video: {
72+ // width: {min: 160, ideal: 640, max: 1280},
73+ // height: {min: 120, ideal: 360, max: 720}
74+ // }
75+ // }).then(local => {
76+ // localRef.current.srcObject = local;
77+ // }).catch(console.error);
7078 subscriptions . current . push (
7179 ...[
7280 rtc . messages . subscribe ( msg => {
@@ -81,18 +89,21 @@ export const Chat = () => {
8189 subscriptions . current . forEach ( s => s . unsubscribe ( ) ) ;
8290 subscriptions . current . length = 0 ;
8391 }
84- } )
92+ } , [ ] )
8593
8694 useEffect ( ( ) => {
87- navigator . mediaDevices . getUserMedia ( {
88- audio : true , video : {
89- width : { min : 160 , ideal : 640 , max : 1280 } ,
90- height : { min : 120 , ideal : 360 , max : 720 }
91- }
92- } ) . then ( local => {
93- localRef . current . srcObject = local ;
94- } ) . catch ( console . error ) ;
95-
95+ if ( micEnabled === true || camEnabled === true ) {
96+ navigator . mediaDevices . getUserMedia ( {
97+ audio : true , video : {
98+ width : { min : 160 , ideal : 640 , max : 1280 } ,
99+ height : { min : 120 , ideal : 360 , max : 720 }
100+ }
101+ } ) . then ( local => {
102+ localRef . current . srcObject = local ;
103+ } ) . catch ( console . error ) ;
104+ } else {
105+ return
106+ }
96107 } , [ micEnabled , camEnabled ] ) ;
97108
98109 useEffect ( ( ) => {
@@ -156,7 +167,7 @@ export const Chat = () => {
156167 </ Box >
157168 < video height = "500px" ref = { localRef } autoPlay />
158169 </ Stack >
159- </ > : null
170+ </ > : < > </ >
160171 }
161172 < Stack direction = { "column" } width = { "100%" } justifyContent = { "center" } >
162173 {
@@ -214,7 +225,7 @@ export const Chat = () => {
214225 < SendRounded /> } </ IconButton >
215226 </ Stack >
216227 </ Stack >
217- </ > : null
228+ </ > : < > </ >
218229 }
219230 </ Stack >
220231 ) ;
0 commit comments