Skip to content
This repository was archived by the owner on Jul 17, 2024. It is now read-only.

Commit 6e14466

Browse files
committed
Remove console.logs
1 parent 5bf1f62 commit 6e14466

File tree

5 files changed

+7
-170
lines changed

5 files changed

+7
-170
lines changed

assets/package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/src/features/devices/LocalPeerMediaContext.tsx

+4-133
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,13 @@ import EmptyVideoWorker from "./emptyVideoWorker.ts?worker";
1313

1414
export type LocalPeerContext = {
1515
video: UseCameraResult<TrackMetadata>;
16-
// audio: UseMicrophoneResult<TrackMetadata>;
17-
// screenShare: UseScreenShareResult<TrackMetadata>;
18-
// camera: MembraneStreaming;
1916
init: () => void;
2017
blur: boolean;
2118
setBlur: (status: boolean, restart: boolean) => void;
2219
setDevice: (cameraId: string | null, microphoneId: string | null, blur: boolean) => void;
2320
toggleCamera: (value: boolean) => void,
2421
toggleMicrophone: (value: boolean) => void,
25-
restartMicrophone: () => void;
22+
restartDevices: () => void;
2623
};
2724

2825
const LocalPeerMediaContext = React.createContext<LocalPeerContext | undefined>(undefined);
@@ -79,7 +76,6 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
7976
const blurRef = useRef<boolean>(false);
8077

8178
const [stream, setStream] = useState<MediaStream | null>(null);
82-
// obecnie nadawany stram - może to być ciemność, może to być blur, może to być kamerka
8379
const streamRef = useRef<MediaStream | null>(null);
8480
const metadataActiveRef = useRef<boolean>(true);
8581

@@ -92,40 +88,22 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
9288
const offscreenCanvasRef = useRef<OffscreenCanvas | null>(null);
9389
const remoteTrackIdRef = useRef<string | null>(null);
9490

95-
// if user start or stop camera during it's decision is reflected in this variables
9691
const cameraIntentionRef = useRef<boolean>(true);
9792
const microphoneIntentionRef = useRef<boolean>(true);
9893
const lastCameraIdRef = useRef<null | string>(null);
9994

100-
// useEffect(() => {
101-
// const a = setInterval(() => {
102-
// console.log({ lastCameraIdRef: lastCameraIdRef.current, cameraIntention: cameraIntentionRef.current });
103-
// }, 3000);
104-
//
105-
// return () => {
106-
// clearInterval(a);
107-
// };
108-
// }, []);
109-
11095
const broadcastedStreamRef = useRef<MediaStream | null>(null);
11196

11297
const changeMediaStream = useCallback(async (stream: MediaStream | null, track: MediaStreamTrack | null, blur: boolean, metadataActive: boolean) => {
113-
console.log({ stream, track, blur, metadataActive });
11498
metadataActiveRef.current = metadataActive;
11599

116100
if (processor.current && !blur) {
117-
console.log("Destroying processor");
118101
processor.current.destroy();
119102
processor.current = null;
120103
}
121104

122105
if (blur && stream) {
123-
console.log({ name: "Handle blur", blur, stream });
124-
if (processor.current && streamRef.current?.id === stream.id) {
125-
console.log("Ignoring blur");
126-
} else {
127-
console.log("Disabling old processor and creating new one");
128-
106+
if (!(processor.current && streamRef.current?.id === stream.id)) {
129107
processor?.current?.destroy();
130108
processor.current = null;
131109
processor.current = new BlurProcessor(stream);
@@ -136,9 +114,7 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
136114
streamRef.current = processor.current?.stream || null;
137115
trackRef.current = processor.current?.track || null;
138116
}
139-
140117
} else {
141-
console.log("Set stream and track");
142118
setStream(stream || null);
143119
setTrack(track || null);
144120

@@ -148,7 +124,6 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
148124

149125
if (client.getSnapshot().status === "joined") {
150126
if (!remoteTrackIdRef.current && streamRef.current && trackRef.current) {
151-
console.log("Adding track");
152127
const mediaStream = new MediaStream();
153128
mediaStream.addTrack(trackRef.current);
154129

@@ -163,8 +138,6 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
163138
selectBandwidthLimit("camera", simulcastEnabled)
164139
);
165140
} else if (remoteTrackIdRef.current && trackRef.current) {
166-
console.log("Replacing track");
167-
168141
// todo add setter as an alternative to setting whole object
169142
broadcastedStreamRef.current?.removeTrack(broadcastedStreamRef.current?.getVideoTracks()[0]);
170143
broadcastedStreamRef.current?.addTrack(trackRef.current);
@@ -173,15 +146,9 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
173146
const newMetadata: TrackMetadata = { active: metadataActive, type: "camera" };
174147

175148
await client.replaceTrack(remoteTrackIdRef.current, trackRef.current, newMetadata);
176-
// todo ...
177-
// await client.updateTrackMetadata(remoteTrackIdRef.current, newMetadata);
178149
} else if (remoteTrackIdRef.current && !stream) {
179-
console.log("Removing track");
180-
181150
await client.removeTrack(remoteTrackIdRef.current);
182151
remoteTrackIdRef.current = null;
183-
} else {
184-
console.log("Skipping track");
185152
}
186153
}
187154
}, [setStream, setTrack]);
@@ -198,7 +165,6 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
198165

199166
const snapshot = client.getSnapshot();
200167

201-
console.log({ name: "managerInitialized", event });
202168
const cameraId = snapshot?.media?.video?.media?.deviceInfo?.deviceId || null;
203169

204170
if (cameraId) {
@@ -236,68 +202,30 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
236202
const stream = snapshot.devices.camera.stream;
237203
const track = snapshot.devices.camera.track;
238204

239-
console.log({
240-
name: "joinedHandler - method start",
241-
cameraIntentionRef: cameraIntentionRef.current,
242-
lastCameraIdRef: lastCameraIdRef.current
243-
});
244-
245205
if (cameraIntentionRef.current && !remoteTrackIdRef.current && stream && track) {
246-
console.log("First visit");
247-
248206
await changeMediaStream(stream, track, blurRef.current, metadataActiveRef.current);
249207
} else if (cameraIntentionRef.current && lastCameraIdRef.current) {
250-
console.log("Rejoin");
251-
console.log("joinedHandler - start device if user wants it");
252208
await snapshot.deviceManager.start({ videoDeviceId: lastCameraIdRef.current });
253-
} else {
254-
console.log("joinedHandler - skipped");
255209
}
256210

257211
const microphoneTrack = snapshot.devices.microphone.track;
258212

259213
if (microphoneIntentionRef.current && !microphoneTrack) {
260-
console.log("Restarting microphone");
261214
await snapshot.deviceManager.start({ audioDeviceId: true });
262215
}
263-
264-
// if (stream && track) {
265-
// // naiwnie zakłądam zę jest tylko kamera a nie czarne ekran lub rozmycie
266-
// const cameraId = snapshot?.media?.video?.media?.deviceInfo?.deviceId || null;
267-
// console.log({ name: "setting camera id - joinedHandler", cameraId, stream, track });
268-
//
269-
// lastCameraIdRef.current = cameraId;
270-
//
271-
// await changeMediaStream(stream, track, blurRef.current, !!snapshot.media?.video?.media?.stream);
272-
// } else if (cameraIntentionRef.current && lastCameraIdRef.current) {
273-
// // todo:
274-
// // we need another method that starts the last stopped one
275-
// console.log("Jest intencja uruchomionej kamery");
276-
// await snapshot.deviceManager.start({ videoDeviceId: lastCameraIdRef.current });
277-
// }
278216
};
279217

280218
const deviceReady: ClientEvents<PeerMetadata, TrackMetadata>["deviceReady"] = async (event, client) => {
281219
const snapshot = client.getSnapshot();
282220

283-
console.log({ name: "Device ready", event });
284-
285221
const cameraId = snapshot.media?.video?.media?.deviceInfo?.deviceId;
286222
if (event.trackType === "video" && event.mediaDeviceType === "userMedia" && cameraId) {
287-
// todo remove? what about autost
288-
// cameraIntentionRef.current = true;
289-
290-
console.log({ name: "setting camera id - device ready", cameraId });
291223
lastCameraIdRef.current = cameraId;
292-
// if (event.trackType === "audio") {
293-
// // microphoneIntentionRef.current = true;
294-
// }
295224

296225
const stream = snapshot?.media?.video?.media?.stream;
297226
const track = snapshot?.media?.video?.media?.track;
298227

299228
if (snapshot.status === "joined" && event.trackType === "video" && stream && track) {
300-
// why is there remoteTrackIdRef.current?
301229
workerRef.current?.postMessage({ action: "stop" }, []); // todo what is the second parameter
302230
await changeMediaStream(stream, track, blurRef.current, track.enabled);
303231
}
@@ -307,44 +235,30 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
307235
const devicesReady: ClientEvents<PeerMetadata, TrackMetadata>["devicesReady"] = async (event, client) => {
308236
const snapshot = client.getSnapshot();
309237

310-
console.log({ name: "devicesReady", event });
311238
const cameraId = snapshot?.media?.video?.media?.deviceInfo?.deviceId || null;
312239

313240
if (cameraId) {
314241
lastCameraIdRef.current = cameraId;
315242
}
316243

317244
if (event.video.restarted && event.video?.media?.stream) {
318-
console.log({ name: "devicesReady -> changeMediaStream", cameraId });
319245
lastCameraIdRef.current = cameraId;
320246

321247
await changeMediaStream(event.video?.media?.stream || null, event.video?.media?.track || null, blurRef.current, true);
322248
}
323249
};
324250

325251
const deviceStopped: ClientEvents<PeerMetadata, TrackMetadata>["deviceStopped"] = async (event, client) => {
326-
console.log({ name: "device stopped", event });
327-
328252
const snapshot = client.getSnapshot();
329253

330-
if (event.trackType === "video" && event.mediaDeviceType === "userMedia") {
331-
// todo to nie jest prawda, intencja na stop jest wtedy gdy użytkownik to wciśnie
332-
// cameraIntentionRef.current = false;
333-
}
334-
if (event.trackType === "audio" && event.mediaDeviceType === "userMedia") {
335-
// microphoneIntentionRef.current = false;
336-
}
337-
338254
if (snapshot.status !== "joined" && event.trackType === "video" && event.mediaDeviceType === "userMedia") {
339-
// w poczeklani trzeba wynullować tracki
340255
setStream(null);
341256
setTrack(null);
342257

343258
streamRef.current = null;
344259
trackRef.current = null;
345260
}
346261
if (snapshot.status === "joined" && event.trackType === "video" && event.mediaDeviceType === "userMedia" && trackRef.current && remoteTrackIdRef.current) {
347-
// jeżeli jesteśmy połączeni to trzeba podmienić na blackscreen
348262
if (!workerRef.current) {
349263
workerRef.current = new EmptyVideoWorker();
350264
const canvasElement = document.createElement("canvas");
@@ -383,66 +297,31 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
383297
}
384298
};
385299

386-
const localTrackMetadataChanged: ClientEvents<PeerMetadata, TrackMetadata>["localTrackMetadataChanged"] = async (event, client) => {
387-
const snapshot = client.getSnapshot();
388-
389-
console.log({ name: "localTrackMetadataChanged", event, client, snapshot });
390-
};
391-
392-
const disconnectRequested: ClientEvents<PeerMetadata, TrackMetadata>["disconnectRequested"] = async (event, client) => {
393-
const snapshot = client.getSnapshot();
394-
395-
console.log({ name: "disconnectRequested", event, client, snapshot });
396-
};
397-
398-
const authSuccess: ClientEvents<PeerMetadata, TrackMetadata>["authSuccess"] = async (client) => {
399-
console.log({ name: "authSuccess", client });
400-
};
401-
402-
const socketOpen: ClientEvents<PeerMetadata, TrackMetadata>["socketOpen"] = async (client) => {
403-
console.log({ name: "socketOpen", client });
404-
};
405-
406300
const disconnected: ClientEvents<PeerMetadata, TrackMetadata>["disconnected"] = async (client) => {
407301
const snapshot = client.getSnapshot();
408302

409-
console.log({ name: "disconnected", client, snapshot });
410303
remoteTrackIdRef.current = null;
411304

412305
if (snapshot.devices.microphone.stream) snapshot.devices.microphone.stop();
413306
if (snapshot.devices.camera.stream) snapshot.devices.camera.stop();
414307
if (snapshot.devices.screenShare.stream) snapshot.devices.screenShare.stop();
415308
};
416309

417-
const devicesStarted: ClientEvents<PeerMetadata, TrackMetadata>["devicesStarted"] = async (event, client) => {
418-
console.log({ name: "devicesStarted", event, client });
419-
};
420-
421310

422311
client.on("joined", joinedHandler);
423-
client.on("localTrackMetadataChanged", localTrackMetadataChanged);
424312
client.on("managerInitialized", managerInitialized);
425313
client.on("deviceReady", deviceReady);
426314
client.on("devicesReady", devicesReady);
427315
client.on("deviceStopped", deviceStopped);
428-
client.on("disconnectRequested", disconnectRequested);
429-
client.on("socketOpen", socketOpen);
430-
client.on("authSuccess", authSuccess);
431316
client.on("disconnected", disconnected);
432-
client.on("devicesStarted", devicesStarted);
433317

434318
return () => {
435319
client.removeListener("joined", joinedHandler);
436-
client.removeListener("localTrackMetadataChanged", localTrackMetadataChanged);
437320
client.removeListener("managerInitialized", managerInitialized);
438321
client.removeListener("deviceReady", deviceReady);
439322
client.removeListener("devicesReady", devicesReady);
440323
client.removeListener("deviceStopped", deviceStopped);
441-
client.removeListener("disconnectRequested", disconnectRequested);
442-
client.removeListener("socketOpen", socketOpen);
443-
client.removeListener("authSuccess", authSuccess);
444324
client.removeListener("disconnected", disconnected);
445-
client.removeListener("devicesStarted", devicesStarted);
446325

447326
};
448327
}, [simulcast.status]);
@@ -475,10 +354,6 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
475354
mediaStatus: video.mediaStatus
476355
}), [stream, track]);
477356

478-
useEffect(() => {
479-
console.log({ newVideo, stream, track });
480-
}, [newVideo, stream, track]);
481-
482357
const microphone = useMicrophone();
483358

484359
const setDevice = useCallback(async (cameraId: string | null, microphoneId: string | null, blur: boolean) => {
@@ -504,7 +379,6 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
504379
}, [video]);
505380

506381
const toggleCamera = useCallback((value: boolean) => {
507-
console.log({ name: "Toggle camera", value });
508382
cameraIntentionRef.current = value;
509383

510384
if (value) {
@@ -516,7 +390,6 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
516390
}, []);
517391

518392
const toggleMicrophone = useCallback((value: boolean) => {
519-
console.log({ name: "Toggle microphone", value });
520393
microphoneIntentionRef.current = value;
521394
if (value) {
522395
microphone.start();
@@ -525,15 +398,13 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
525398
}
526399
}, []);
527400

528-
const restartMicrophone = useCallback(() => {
401+
const restartDevices = useCallback(() => {
529402
const micStatus = client.getSnapshot().media?.audio?.mediaStatus;
530403
if (managerInitializedRef.current && microphoneIntentionRef.current && micStatus === "OK") {
531-
console.log("Restarting mic!");
532404
toggleMicrophone(true);
533405
}
534406
const camStatus = client.getSnapshot().media?.video?.mediaStatus;
535407
if (managerInitializedRef.current && cameraIntentionRef.current && camStatus === "OK") {
536-
console.log("Restarting camStatus!");
537408
toggleCamera(true);
538409
}
539410
}, [toggleMicrophone, toggleCamera]);
@@ -548,7 +419,7 @@ export const LocalPeerMediaProvider = ({ children }: Props) => {
548419
setDevice,
549420
toggleCamera,
550421
toggleMicrophone,
551-
restartMicrophone
422+
restartDevices
552423
}}
553424
>
554425
{children}

assets/src/features/devices/MediaSettingsModal.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ export const MediaSettingsModal: React.FC = () => {
4444
cancelClassName="!text-additional-red-100"
4545
onConfirm={() => {
4646
setDevice(videoInput, audioInput, blurInput);
47-
console.log({ blurInput, videoInput, audioInput });
4847
setOpen(false);
4948
}}
5049
onCancel={handleClose}

assets/src/features/home-page/components/HomePageVideoTile.tsx

+2-13
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,12 @@ type HomePageVideoTileProps = {
1818

1919
const HomePageVideoTile: FC<HomePageVideoTileProps> = ({ displayName }) => {
2020
const microphone = useMicrophone();
21-
// todo add loading to device manager
22-
// const video = useCamera();
23-
const { video, toggleCamera, toggleMicrophone, restartMicrophone } = useLocalPeer();
21+
const { video, toggleCamera, toggleMicrophone, restartDevices } = useLocalPeer();
2422
const initials = computeInitials(displayName);
2523
const { setOpen } = useModal();
2624

2725
useEffect(() => {
28-
console.log({ video });
29-
// restartMicrophone();
30-
}, [video]);
31-
32-
useEffect(() => {
33-
// if (microphone.mediaStatus === "Requesting") {
34-
// console.warn("Replacing!");
35-
// }
36-
// console.log({ mediaStatus: microphone.mediaStatus });
37-
restartMicrophone();
26+
restartDevices();
3827
}, []);
3928

4029
return (

0 commit comments

Comments
 (0)