Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions src/context/service-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
error: string | null;
}

export const ServiceContext = createContext<ServiceContextType>({

Check warning on line 14 in src/context/service-context.tsx

View workflow job for this annotation

GitHub Actions / Lint, Build, and Test (20.x)

Fast refresh only works when a file only exports components. Move your React context(s) to a separate file
mediaService: null,
signalingService: null,
isInitializing: true,
Expand All @@ -27,27 +27,6 @@
const [isInitializing, setIsInitializing] = useState(true);
const [error, setError] = useState<string | null>(null);

// const cleanup = useCallback(() => {
// try {
// // Cleanup media service
// if (mediaService) {
// mediaService.closeAllTransports();
// mediaService.closeAllProducers();
// mediaService.closeAllConsumers();
// }

// // Cleanup signaling service
// if (signalingService) {
// const connection = signalingService.getConnection();
// connection.off('reconnect_failed');
// connection.off('connect_error');
// signalingService.disconnect();
// }
// } catch (error) {
// console.error('Cleanup error:', error);
// }
// }, [mediaService, signalingService]);

useEffect(() => {
const initializeServices = async () => {
setIsInitializing(true);
Expand All @@ -67,7 +46,7 @@
// Initialize media service
const newMediaService = await MediaService.start(newSignalingService);
setMediaService(newMediaService);
console.log('signaling and media service started');

Check warning on line 49 in src/context/service-context.tsx

View workflow job for this annotation

GitHub Actions / Lint, Build, and Test (20.x)

Unexpected console statement
setError(null);
} catch (error) {
console.error('Service initialization error:', error);
Expand Down
1 change: 0 additions & 1 deletion src/hooks/use-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ export const useMedia = () => {

const stopDisplayMedia = useCallback(async () => {
if (!mediaService) throw new Error('MediaService not initialized');
console.log('stopDisplayMedia');
await mediaService.stopDisplayMedia();
if (roomAccess == Access.Allowed) {
closeProducer('screen');
Expand Down
5 changes: 0 additions & 5 deletions src/hooks/use-room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ export const useRoom = () => {
},

[Actions.PeerLeft]: async args => {
console.log('Left room');
const data = ValidationSchema.peerId.parse(args);
peerActions.remove(data.id);
},
Expand All @@ -112,24 +111,20 @@ export const useRoom = () => {
const data = ValidationSchema.createConsumerData.parse(args);
await createConsumer(data);
callback({ status: 'success' });
console.log(Actions.ConsumerCreated, data);
callback({ status: 'success' });
},

[Actions.ConsumerPaused]: async args => {
const data = ValidationSchema.consumerStateData.parse(args);
pauseConsumer(data);
console.log(Actions.ConsumerPaused, data);
},
[Actions.ConsumerResumed]: async args => {
const data = ValidationSchema.consumerStateData.parse(args);
resumeConsumer(data);
console.log(Actions.ConsumerResumed, data);
},
[Actions.ConsumerClosed]: async args => {
const data = ValidationSchema.consumerStateData.parse(args);
closeConsumer(data);
console.log(Actions.ConsumerPaused, data);
},
}),
[closeConsumer, createConsumer, pauseConsumer, peerActions, resumeConsumer]
Expand Down
17 changes: 11 additions & 6 deletions src/providers/room-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ const RoomProvider = ({ children }: { children: ReactNode }) => {
closeAllConsumers,
closeAllTransports,
closeAllProducers,
// produceUserMedia,
produceUserMedia,
} = useMedia();
const reconnectionToastRef = useRef<string | number>(0);

const heartBeatIntervalRef = useRef<NodeJS.Timeout>(null);
const roomAccess = useRoomAccess();
const roomActions = useRoomActions();
const [rejoining, setRejoining] = useState(false);
const [produceLocalMedia, setProduceLocalMedia] = useState(false);
const { joinRoom, leaveRoom, actionHandlers } = useRoom();

useEffect(() => {
Expand Down Expand Up @@ -55,9 +56,9 @@ const RoomProvider = ({ children }: { children: ReactNode }) => {
(async () => {
await joinRoom();
await createWebRtcConnections();
// await produceUserMedia();

// register heartbeat interval
setProduceLocalMedia(true);

heartBeatIntervalRef.current = setInterval(
sendHeartBeat,
HEARTBEAT_INTERVAL
Expand All @@ -82,8 +83,8 @@ const RoomProvider = ({ children }: { children: ReactNode }) => {

await joinRoom(rejoining);
await createWebRtcConnections();
// await produceUserMedia();
setRejoining(false);
setProduceLocalMedia(true);

if (reconnectionToastRef.current)
toast.dismiss(reconnectionToastRef.current);
Expand All @@ -107,8 +108,12 @@ const RoomProvider = ({ children }: { children: ReactNode }) => {
// produce on join
useEffect(() => {
if (roomAccess !== Access.Allowed) return;
if (rejoining) return;
}, [roomAccess, rejoining]);
if (!produceLocalMedia) return;
(async () => {
await produceUserMedia();
setProduceLocalMedia(false);
})();
}, [roomAccess, produceLocalMedia, produceUserMedia]);

useEffect(() => {
if (!signalingService) return;
Expand Down
19 changes: 0 additions & 19 deletions src/services/media-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ class MediaService {
}>({
action: Actions.CreateWebrtcTransports,
});
console.log('createWebRtcTransports', response);
// console.log({ transportsParams })
if (!response)
throw 'Transport not created, - transport params were not recieved';
Expand All @@ -426,7 +425,6 @@ class MediaService {
if (!this.device) {
throw new Error('Device not intialised');
}
console.log('createWebRtcSendTransport', transportParams);
this.sendTransport = this.device.createSendTransport({
id: transportParams.id,
iceParameters: transportParams.iceParameters,
Expand Down Expand Up @@ -462,7 +460,6 @@ class MediaService {
dtlsParameters,
},
});
console.log('connected webrtc transports');
callback();
} catch (error) {
errback(error as Error);
Expand All @@ -485,7 +482,6 @@ class MediaService {
appData,
},
});
console.log('Create Producer, producerId', response?.producerId);
if (!response)
return errback(new Error('ProducerId was not recieved'));
callback({ id: response.producerId });
Expand All @@ -497,16 +493,8 @@ class MediaService {

sendTransport.on('connectionstatechange', state => {
switch (state) {
case 'connecting':
console.log('sendTransport connecting connectionstatechange');
break;
case 'connected':
console.log('sendTransport connected connectionstatechange');
break;
case 'disconnected':
case 'failed':
console.log(' sendTransport Ice disconneted/failed', state);

this.restartICE(sendTransport);
break;
default:
Expand Down Expand Up @@ -536,15 +524,8 @@ class MediaService {

recvTransport.on('connectionstatechange', state => {
switch (state) {
case 'connecting':
console.log('recvTransport connecting connectionstatechange');
break;
case 'connected':
console.log('recvTransport connected connectionstatechange');
break;
case 'disconnected':
case 'failed':
console.log(' recvTransport Ice disconneted/failed', state);
this.restartICE(recvTransport);
break;
default:
Expand Down
Loading