11'use client' ;
22
3- import * as React from 'react' ;
3+ import { useState , useEffect , useMemo } from 'react' ;
44import { setLogLevel } from '@livekit/components-core' ;
55import {
66 GridLayout ,
@@ -13,24 +13,24 @@ import {
1313 SessionEvent ,
1414} from '@livekit/components-react' ;
1515import type { NextPage } from 'next' ;
16- import { ControlBarControls } from '@livekit/components-react' ;
1716import { LocalVideoTrack , Track , TrackProcessor , TokenSource , MediaDeviceFailure } from 'livekit-client' ;
1817import { BackgroundBlur } from '@livekit/track-processors' ;
18+ import { generateRandomUserId } from '../lib/helper' ;
1919
2020function Stage ( ) {
2121 const cameraTracks = useTracks ( [ Track . Source . Camera ] ) ;
2222 const screenShareTrackRef = useTracks ( [ Track . Source . ScreenShare ] ) [ 0 ] ;
2323
24- const [ blurEnabled , setBlurEnabled ] = React . useState ( false ) ;
25- const [ processorPending , setProcessorPending ] = React . useState ( false ) ;
24+ const [ blurEnabled , setBlurEnabled ] = useState ( false ) ;
25+ const [ processorPending , setProcessorPending ] = useState ( false ) ;
2626 const { cameraTrack } = useLocalParticipant ( ) ;
27- const [ blur , setBlur ] = React . useState < TrackProcessor < Track . Kind . Video > | undefined > ( ) ;
27+ const [ blur , setBlur ] = useState < TrackProcessor < Track . Kind . Video > | undefined > ( ) ;
2828
29- React . useEffect ( ( ) => {
29+ useEffect ( ( ) => {
3030 setBlur ( BackgroundBlur ( ) ) ;
3131 } , [ ] ) ;
3232
33- React . useEffect ( ( ) => {
33+ useEffect ( ( ) => {
3434 const localCamTrack = cameraTrack ?. track as LocalVideoTrack | undefined ;
3535 if ( localCamTrack ) {
3636 setProcessorPending ( true ) ;
@@ -66,11 +66,14 @@ function Stage() {
6666}
6767
6868const ProcessorsExample : NextPage = ( ) => {
69- const params = typeof window !== 'undefined' ? new URLSearchParams ( location . search ) : null ;
69+ const params = useMemo (
70+ ( ) => ( typeof window !== 'undefined' ? new URLSearchParams ( location . search ) : null ) ,
71+ [ ] ,
72+ ) ;
7073 const roomName = params ?. get ( 'room' ) ?? 'test-room' ;
71- const userIdentity = params ?. get ( 'user' ) ?? 'test-identity' ;
74+ const [ userIdentity ] = useState ( ( ) => params ?. get ( 'user' ) ?? generateRandomUserId ( ) ) ;
7275
73- const tokenSource = React . useMemo ( ( ) => {
76+ const tokenSource = useMemo ( ( ) => {
7477 return TokenSource . endpoint ( process . env . NEXT_PUBLIC_LK_TOKEN_ENDPOINT ! ) ;
7578 } , [ ] ) ;
7679
@@ -80,7 +83,7 @@ const ProcessorsExample: NextPage = () => {
8083 participantName : userIdentity ,
8184 } ) ;
8285
83- React . useEffect ( ( ) => {
86+ useEffect ( ( ) => {
8487 session . start ( {
8588 tracks : {
8689 camera : { enabled : true } ,
@@ -97,7 +100,7 @@ const ProcessorsExample: NextPage = () => {
97100 // eslint-disable-next-line react-hooks/exhaustive-deps
98101 } , [ session . start , session . end ] ) ;
99102
100- React . useEffect ( ( ) => {
103+ useEffect ( ( ) => {
101104 const handleMediaDevicesError = ( error : Error ) => {
102105 const failure = MediaDeviceFailure . getFailure ( error ) ;
103106 console . error ( failure ) ;
0 commit comments