@@ -56,6 +56,10 @@ export type SessionConnectOptions = {
5656 enabled ?: boolean ;
5757 publishOptions ?: TrackPublishOptions ;
5858 } ;
59+ screenShare ?: {
60+ enabled ?: boolean ;
61+ publishOptions ?: TrackPublishOptions ;
62+ } ;
5963 } ;
6064
6165 /** Options for Room.connect(.., .., opts) */
@@ -94,6 +98,7 @@ type SessionStateConnecting = SessionStateCommon & {
9498 local : {
9599 cameraTrack : undefined ;
96100 microphoneTrack : undefined ;
101+ screenShareTrack : undefined ;
97102 } ;
98103} ;
99104
@@ -107,6 +112,7 @@ type SessionStateConnected = SessionStateCommon & {
107112 local : {
108113 cameraTrack ?: TrackReference ;
109114 microphoneTrack ?: TrackReference ;
115+ screenShareTrack ?: TrackReference ;
110116 } ;
111117} ;
112118
@@ -117,6 +123,7 @@ type SessionStateDisconnected = SessionStateCommon & {
117123 local : {
118124 cameraTrack : undefined ;
119125 microphoneTrack : undefined ;
126+ screenShareTrack : undefined ;
120127 } ;
121128} ;
122129
@@ -379,7 +386,7 @@ export function useSession(
379386 participant : localParticipant ,
380387 publication : cameraPublication ,
381388 } ;
382- } , [ localParticipant , cameraPublication , cameraPublication ?. isMuted ] ) ;
389+ } , [ localParticipant , cameraPublication ] ) ;
383390 const microphonePublication = localParticipant . getTrackPublication ( Track . Source . Microphone ) ;
384391 const localMicrophone = React . useMemo ( ( ) => {
385392 if ( ! microphonePublication ) {
@@ -390,7 +397,18 @@ export function useSession(
390397 participant : localParticipant ,
391398 publication : microphonePublication ,
392399 } ;
393- } , [ localParticipant , microphonePublication , microphonePublication ?. isMuted ] ) ;
400+ } , [ localParticipant , microphonePublication ] ) ;
401+ const screenSharePublication = localParticipant . getTrackPublication ( Track . Source . ScreenShare ) ;
402+ const localScreenShare = React . useMemo ( ( ) => {
403+ if ( ! screenSharePublication ) {
404+ return undefined ;
405+ }
406+ return {
407+ source : Track . Source . ScreenShare ,
408+ participant : localParticipant ,
409+ publication : screenSharePublication ,
410+ } ;
411+ } , [ localParticipant , screenSharePublication ] ) ;
394412
395413 const {
396414 agentTimeoutFailureReason,
@@ -447,6 +465,7 @@ export function useSession(
447465 local : {
448466 cameraTrack : undefined ,
449467 microphoneTrack : undefined ,
468+ screenShareTrack : undefined ,
450469 } ,
451470 } ;
452471
@@ -462,6 +481,7 @@ export function useSession(
462481 local : {
463482 cameraTrack : localCamera ,
464483 microphoneTrack : localMicrophone ,
484+ screenShareTrack : localScreenShare ,
465485 } ,
466486 } ;
467487
@@ -475,6 +495,7 @@ export function useSession(
475495 local : {
476496 cameraTrack : undefined ,
477497 microphoneTrack : undefined ,
498+ screenShareTrack : undefined ,
478499 } ,
479500 } ;
480501 }
@@ -566,6 +587,13 @@ export function useSession(
566587 tracks . camera ?. publishOptions ?? { } ,
567588 )
568589 : Promise . resolve ( ) ,
590+ tracks . screenShare ?. enabled
591+ ? room . localParticipant . setScreenShareEnabled (
592+ true ,
593+ undefined ,
594+ tracks . screenShare ?. publishOptions ?? { } ,
595+ )
596+ : Promise . resolve ( ) ,
569597 ] ) ;
570598
571599 await waitUntilConnected ( signal ) ;
0 commit comments