@@ -7,7 +7,7 @@ import { CopyToClipboardButton } from "../components/CopyButton";
7
7
import { useServerSdk } from "../components/ServerSdkContext" ;
8
8
import { useLogging } from "../components/useLogging" ;
9
9
import { useConnectionToasts } from "../components/useConnectionToasts" ;
10
- import { showToastError } from "../components/Toasts" ;
10
+ import { showToastError , showToastInfo } from "../components/Toasts" ;
11
11
import { SignalingUrl , TrackEncoding } from "@jellyfish-dev/react-client-sdk" ;
12
12
import { useStore } from "./RoomsContext" ;
13
13
import { getBooleanValue } from "../utils/localStorageUtils" ;
@@ -20,6 +20,7 @@ import { checkJSON } from "./StreamingSettingsPanel";
20
20
import { atomFamily , atomWithStorage } from "jotai/utils" ;
21
21
import { useSetAtom } from "jotai" ;
22
22
import { TrackMetadata } from "../jellyfish.types" ;
23
+ import { ComponentOptionsHLSSubscribeModeEnum } from "../server-sdk" ;
23
24
24
25
type ClientProps = {
25
26
roomId : string ;
@@ -30,6 +31,7 @@ type ClientProps = {
30
31
remove : ( roomId : string ) => void ;
31
32
setToken : ( token : string ) => void ;
32
33
removeToken : ( ) => void ;
34
+ hlsMode ?: ComponentOptionsHLSSubscribeModeEnum ;
33
35
} ;
34
36
35
37
export const createDefaultTrackMetadata = ( type : string ) =>
@@ -64,7 +66,23 @@ export const trackMetadataAtomFamily = atomFamily((clientId) =>
64
66
atomWithStorage < Record < TrackId , TrackMetadata > | null > ( `track-metadata-${ clientId } ` , null ) ,
65
67
) ;
66
68
67
- export const Client = ( { roomId, peerId, token, id, refetchIfNeeded, remove, removeToken, setToken } : ClientProps ) => {
69
+ const prepareHlsButtonMessage = ( hlsMode ?: ComponentOptionsHLSSubscribeModeEnum ) : string | null => {
70
+ if ( hlsMode === undefined ) return "There is no HLS component in this room" ;
71
+ if ( hlsMode === "auto" ) return "HLS is in automatic subscription mode" ;
72
+ else return null ;
73
+ } ;
74
+
75
+ export const Client = ( {
76
+ roomId,
77
+ peerId,
78
+ token,
79
+ id,
80
+ refetchIfNeeded,
81
+ remove,
82
+ removeToken,
83
+ setToken,
84
+ hlsMode,
85
+ } : ClientProps ) => {
68
86
const { state, dispatch } = useStore ( ) ;
69
87
const client = state . rooms [ roomId ] . peers [ peerId ] . client ;
70
88
const tracks = state . rooms [ roomId ] . peers [ peerId ] . tracks || [ ] ;
@@ -81,7 +99,7 @@ export const Client = ({ roomId, peerId, token, id, refetchIfNeeded, remove, rem
81
99
82
100
const api = client . useSelector ( ( snapshot ) => snapshot . connectivity . api ) ;
83
101
const jellyfishClient = client . useSelector ( ( snapshot ) => snapshot . connectivity . client ) ;
84
- const { signalingHost, signalingPath, signalingProtocol } = useServerSdk ( ) ;
102
+ const { signalingHost, signalingPath, signalingProtocol, hlsApi } = useServerSdk ( ) ;
85
103
const [ showClientState , setShowClientState ] = useLocalStorageState ( `show-client-state-json-${ peerId } ` ) ;
86
104
const [ attachClientMetadata , setAttachClientMetadata ] = useLocalStorageState ( `attach-client-metadata-${ peerId } ` ) ;
87
105
const [ showMetadataEditor , setShowMetadataEditor ] = useLocalStorageState ( `show-metadata-editor-${ peerId } ` ) ;
@@ -228,6 +246,8 @@ export const Client = ({ roomId, peerId, token, id, refetchIfNeeded, remove, rem
228
246
if ( ! trackId ) throw Error ( "Adding track error!" ) ;
229
247
} ;
230
248
249
+ const hlsMessage = prepareHlsButtonMessage ( hlsMode ) ;
250
+
231
251
return (
232
252
< div className = "flex flex-col gap-1 mx-1" >
233
253
< div className = "card w-150 bg-base-100 shadow-xl indicator" >
@@ -243,7 +263,7 @@ export const Client = ({ roomId, peerId, token, id, refetchIfNeeded, remove, rem
243
263
< div className = "flex flex-row justify-between gap-2 items-center" >
244
264
< h1 className = "card-title relative" >
245
265
< div className = "z-10" >
246
- Client : < span className = "text-xs" > { peerId } </ span >
266
+ Peer : < span className = "text-xs" > { peerId } </ span >
247
267
</ div >
248
268
< div className = "tooltip tooltip-top tooltip-primary absolute -ml-3 -mt-1 " data-tip = { fullState ?. status } >
249
269
< BadgeStatus status = { fullState ?. status } />
@@ -382,6 +402,27 @@ export const Client = ({ roomId, peerId, token, id, refetchIfNeeded, remove, rem
382
402
/>
383
403
< span className = "text ml-2" > Show metadata editor</ span >
384
404
</ label >
405
+ < div className = "tooltip tooltip-info z-10" data-tip = { hlsMessage } >
406
+ < button
407
+ className = "btn btn-sm btn-warning"
408
+ disabled = { hlsMode !== "manual" }
409
+ onClick = { ( ) => {
410
+ hlsApi
411
+ ?. subscribeHlsTo ( roomId , {
412
+ origins : [ peerId ] ,
413
+ } )
414
+ . then ( ( ) => {
415
+ showToastInfo ( `Subscribed to all tracks of the user ${ peerId } ` ) ;
416
+ } )
417
+ . catch ( ( e ) => {
418
+ console . error ( e ) ;
419
+ showToastError ( `Subscribing peer ${ peerId } failed` ) ;
420
+ } ) ;
421
+ } }
422
+ >
423
+ Add to hls
424
+ </ button >
425
+ </ div >
385
426
</ div >
386
427
< div className = "flex flex-col gap-2" >
387
428
{ showMetadataEditor && (
0 commit comments