@mrksbnc/livekit-vue 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -0
  3. package/dist/components.cjs +2 -0
  4. package/dist/components.cjs.map +1 -0
  5. package/dist/components.d.ts +1 -0
  6. package/dist/components.mjs +213 -0
  7. package/dist/components.mjs.map +1 -0
  8. package/dist/composables.cjs +2 -0
  9. package/dist/composables.cjs.map +1 -0
  10. package/dist/composables.d.ts +1 -0
  11. package/dist/composables.mjs +913 -0
  12. package/dist/composables.mjs.map +1 -0
  13. package/dist/contexts-BGR-EyiF.mjs +227 -0
  14. package/dist/contexts-BGR-EyiF.mjs.map +1 -0
  15. package/dist/favicon.ico +0 -0
  16. package/dist/index.cjs +2 -0
  17. package/dist/index.cjs.map +1 -0
  18. package/dist/index.css +1 -0
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.mjs +74 -0
  21. package/dist/index.mjs.map +1 -0
  22. package/dist/shared-B72lPzrj.cjs +2 -0
  23. package/dist/shared-B72lPzrj.cjs.map +1 -0
  24. package/dist/shared-Bt-fJtlk.cjs +2 -0
  25. package/dist/shared-Bt-fJtlk.cjs.map +1 -0
  26. package/dist/shared-UqxyWhFA.cjs +2 -0
  27. package/dist/shared-UqxyWhFA.cjs.map +1 -0
  28. package/package.json +78 -0
  29. package/src/App.vue +16 -0
  30. package/src/assets/icons/chevron-down.svg +4 -0
  31. package/src/assets/icons/chevron-up.svg +4 -0
  32. package/src/assets/icons/frown.svg +7 -0
  33. package/src/assets/icons/heart.svg +6 -0
  34. package/src/assets/icons/mic-off.svg +8 -0
  35. package/src/assets/icons/mic.svg +7 -0
  36. package/src/assets/icons/phone-hang-up.svg +9 -0
  37. package/src/assets/icons/share-screen-off.svg +6 -0
  38. package/src/assets/icons/share-screen.svg +7 -0
  39. package/src/assets/icons/smile.svg +7 -0
  40. package/src/assets/icons/thumbs-down.svg +6 -0
  41. package/src/assets/icons/thumbs-up.svg +6 -0
  42. package/src/assets/icons/video-off.svg +5 -0
  43. package/src/assets/icons/video.svg +5 -0
  44. package/src/assets/index.ts +1 -0
  45. package/src/assets/placeholders/participant.svg +8 -0
  46. package/src/components/controls/TrackToggle.vue +27 -0
  47. package/src/components/controls/buttons.ts +5 -0
  48. package/src/components/controls/index.ts +3 -0
  49. package/src/components/controls/track_toggle.ts +13 -0
  50. package/src/components/icons/ParticipantPlaceholderIcon.vue +7 -0
  51. package/src/components/icons/TrackIcon.vue +55 -0
  52. package/src/components/index.ts +3 -0
  53. package/src/components/participant/AudioTrack.vue +17 -0
  54. package/src/components/participant/audio_track.ts +8 -0
  55. package/src/composables/index.ts +89 -0
  56. package/src/composables/private/useObservableState.ts +44 -0
  57. package/src/composables/useAudioPlayback.ts +42 -0
  58. package/src/composables/useClearPinButton.ts +41 -0
  59. package/src/composables/useConnectionQualityIndicator.ts +39 -0
  60. package/src/composables/useConnectionState.ts +21 -0
  61. package/src/composables/useDataChannel.ts +56 -0
  62. package/src/composables/useDisconnectButton.ts +28 -0
  63. package/src/composables/useFacingMode.ts +28 -0
  64. package/src/composables/useFocusToggle.ts +38 -0
  65. package/src/composables/useGridLayout.ts +44 -0
  66. package/src/composables/useIsEncrypted.ts +34 -0
  67. package/src/composables/useIsMuted.ts +56 -0
  68. package/src/composables/useIsRecording.ts +30 -0
  69. package/src/composables/useIsSpeaking.ts +23 -0
  70. package/src/composables/useLiveKitRoom.ts +219 -0
  71. package/src/composables/useLocalParticipant.ts +64 -0
  72. package/src/composables/useParticipantTile.ts +68 -0
  73. package/src/composables/useParticipantTracks.ts +36 -0
  74. package/src/composables/useParticipants.ts +25 -0
  75. package/src/composables/usePersistentUserChoices.ts +64 -0
  76. package/src/composables/usePinnedTracks.ts +16 -0
  77. package/src/composables/useRemoteParticipant.ts +42 -0
  78. package/src/composables/useRemoteParticipants.ts +27 -0
  79. package/src/composables/useRoomInfo.ts +42 -0
  80. package/src/composables/useSortedParticipants.ts +21 -0
  81. package/src/composables/useSpeakingParticipants.ts +22 -0
  82. package/src/composables/useStartAudio.ts +53 -0
  83. package/src/composables/useStartVideo.ts +53 -0
  84. package/src/composables/useToken.ts +40 -0
  85. package/src/composables/useTrack.ts +11 -0
  86. package/src/composables/useTrackByName.ts +11 -0
  87. package/src/composables/useTrackMutedIndicator.ts +34 -0
  88. package/src/composables/useTrackRefBySourceOrName.ts +39 -0
  89. package/src/composables/useTrackSyncTime.ts +32 -0
  90. package/src/composables/useTrackToggle.ts +113 -0
  91. package/src/composables/useTrackVolume.ts +268 -0
  92. package/src/composables/useTracks.ts +122 -0
  93. package/src/composables/useVisualStableUpdate.ts +57 -0
  94. package/src/context/index.ts +6 -0
  95. package/src/context/layout.context.ts +46 -0
  96. package/src/context/participant.context.ts +33 -0
  97. package/src/context/pin.context.ts +50 -0
  98. package/src/context/room.context.ts +31 -0
  99. package/src/context/track_reference.context.ts +29 -0
  100. package/src/context/widget.context.ts +17 -0
  101. package/src/index.css +1 -0
  102. package/src/index.ts +5 -0
  103. package/src/main.ts +6 -0
  104. package/src/types/livekit_room.types.ts +78 -0
  105. package/src/utils/room.utils.ts +9 -0
@@ -0,0 +1,64 @@
1
+ import { useEnsureRoomContext } from '@/context/room.context';
2
+ import { observeParticipantMedia, type ParticipantMedia } from '@livekit/components-core';
3
+ import { useSubscription } from '@vueuse/rxjs';
4
+ import { LocalParticipant, TrackPublication, type Room } from 'livekit-client';
5
+ import { ref, watch, type ShallowRef } from 'vue';
6
+
7
+ export type UseLocalParticipantOptions = {
8
+ room?: Room;
9
+ };
10
+
11
+ export type UseLocalParticipantReturnType = {
12
+ isMicrophoneEnabled: ShallowRef<boolean>;
13
+ isScreenShareEnabled: ShallowRef<boolean>;
14
+ isCameraEnabled: ShallowRef<boolean>;
15
+ microphoneTrack: ShallowRef<TrackPublication | undefined>;
16
+ cameraTrack: ShallowRef<TrackPublication | undefined>;
17
+ lastMicrophoneError: ShallowRef<Error | undefined>;
18
+ lastCameraError: ShallowRef<Error | undefined>;
19
+ localParticipant: ShallowRef<LocalParticipant | undefined>;
20
+ };
21
+
22
+ export function useLocalParticipant(
23
+ options: UseLocalParticipantOptions = {},
24
+ ): UseLocalParticipantReturnType {
25
+ const room = useEnsureRoomContext(options.room);
26
+
27
+ const localParticipant = ref<LocalParticipant | undefined>(room.value?.localParticipant);
28
+ const isMicrophoneEnabled = ref(localParticipant.value?.isMicrophoneEnabled ?? false);
29
+ const isCameraEnabled = ref(localParticipant.value?.isCameraEnabled ?? false);
30
+ const isScreenShareEnabled = ref(localParticipant.value?.isScreenShareEnabled ?? false);
31
+
32
+ const lastMicrophoneError = ref<Error | undefined>(localParticipant.value?.lastMicrophoneError);
33
+ const lastCameraError = ref<Error | undefined>(localParticipant.value?.lastCameraError);
34
+
35
+ const microphoneTrack = ref<TrackPublication | undefined>(undefined);
36
+
37
+ const cameraTrack = ref<TrackPublication | undefined>(undefined);
38
+
39
+ function handleUpdate(media: ParticipantMedia<LocalParticipant>) {
40
+ isCameraEnabled.value = media.isCameraEnabled;
41
+ isMicrophoneEnabled.value = media.isMicrophoneEnabled;
42
+ isScreenShareEnabled.value = media.isScreenShareEnabled;
43
+ cameraTrack.value = media.cameraTrack;
44
+ microphoneTrack.value = media.microphoneTrack;
45
+ lastMicrophoneError.value = media.participant.lastMicrophoneError;
46
+ lastCameraError.value = media.participant.lastCameraError;
47
+ localParticipant.value = media.participant;
48
+ }
49
+
50
+ watch(room, () =>
51
+ useSubscription(observeParticipantMedia(room.value.localParticipant).subscribe(handleUpdate)),
52
+ );
53
+
54
+ return {
55
+ isMicrophoneEnabled,
56
+ isScreenShareEnabled,
57
+ isCameraEnabled,
58
+ microphoneTrack: microphoneTrack as ShallowRef<TrackPublication | undefined>,
59
+ cameraTrack: cameraTrack as ShallowRef<TrackPublication | undefined>,
60
+ lastMicrophoneError,
61
+ lastCameraError,
62
+ localParticipant: localParticipant as ShallowRef<LocalParticipant | undefined>,
63
+ };
64
+ }
@@ -0,0 +1,68 @@
1
+ import { useEnsureTrackRef } from '@/context/track_reference.context';
2
+ import type { ParticipantClickEvent, TrackReferenceOrPlaceholder } from '@livekit/components-core';
3
+ import { Track, TrackPublication } from 'livekit-client';
4
+ import { computed, shallowRef, type HTMLAttributes, type ShallowRef } from 'vue';
5
+ import { useFacingMode } from './useFacingMode';
6
+ import { useIsMuted } from './useIsMuted';
7
+ import { useIsSpeaking } from './useIsSpeaking';
8
+
9
+ export type UseParticipantTileProps = {
10
+ trackRef?: TrackReferenceOrPlaceholder;
11
+ disableSpeakingIndicator?: boolean;
12
+ onParticipantClick?: (event: ParticipantClickEvent) => void;
13
+ htmlProps: HTMLAttributes;
14
+ };
15
+
16
+ export function useParticipantTile(options: UseParticipantTileProps): {
17
+ elementProps: ShallowRef<HTMLAttributes>;
18
+ } {
19
+ const trackReference = useEnsureTrackRef(options.trackRef);
20
+
21
+ const htmlElementAttributes = computed<HTMLAttributes>(() => {
22
+ return {
23
+ class: 'lk-participant-tile',
24
+ onClick: (event: MouseEvent) => {
25
+ options.htmlProps.onClick?.(event);
26
+
27
+ if (typeof options.onParticipantClick === 'function') {
28
+ const track =
29
+ trackReference.value.publication ??
30
+ trackReference.value.participant.getTrackPublication(trackReference.value.source);
31
+
32
+ options.onParticipantClick({ participant: trackReference.value.participant, track });
33
+ }
34
+ },
35
+ };
36
+ });
37
+
38
+ const micTrack = computed<TrackPublication | undefined>(() => {
39
+ return trackReference.value.participant.getTrackPublication(Track.Source.Microphone);
40
+ });
41
+
42
+ const micRef = computed<TrackReferenceOrPlaceholder>(() => {
43
+ const trackRef: TrackReferenceOrPlaceholder = {
44
+ participant: trackReference.value.participant,
45
+ source: Track.Source.Microphone,
46
+ publication: micTrack.value,
47
+ };
48
+
49
+ return trackRef;
50
+ });
51
+
52
+ const isVideoMuted = useIsMuted(trackReference.value);
53
+ const isAudioMuted = useIsMuted(micRef.value);
54
+ const isSpeaking = useIsSpeaking(trackReference.value.participant);
55
+ const facingMode = useFacingMode(trackReference.value);
56
+
57
+ return {
58
+ elementProps: shallowRef({
59
+ 'data-lk-audio-muted': isAudioMuted,
60
+ 'data-lk-video-muted': isVideoMuted,
61
+ 'data-lk-speaking': options.disableSpeakingIndicator === true ? false : isSpeaking,
62
+ 'data-lk-local-participant': trackReference.value.participant.isLocal,
63
+ 'data-lk-source': trackReference.value.source,
64
+ 'data-lk-facing-mode': facingMode,
65
+ ...htmlElementAttributes.value,
66
+ }),
67
+ };
68
+ }
@@ -0,0 +1,36 @@
1
+ import { useMaybeParticipantContext } from '@/context/participant.context';
2
+ import { useRoomContext } from '@/context/room.context';
3
+ import { participantTracksObservable, type TrackReference } from '@livekit/components-core';
4
+ import type { Participant, Track } from 'livekit-client';
5
+ import type { Observable } from 'rxjs';
6
+ import { computed, type ShallowRef } from 'vue';
7
+ import { useObservableState } from './private/useObservableState';
8
+
9
+ export function useParticipantTracks(
10
+ sources: Track.Source[],
11
+ participantIdentity?: string,
12
+ ): ShallowRef<TrackReference[]> {
13
+ const room = useRoomContext();
14
+ const participantContext = useMaybeParticipantContext();
15
+
16
+ const p = computed<Participant | undefined>(() =>
17
+ participantIdentity
18
+ ? room?.value?.getParticipantByIdentity(participantIdentity)
19
+ : participantContext?.value,
20
+ );
21
+
22
+ const observable = computed<Observable<TrackReference[]> | undefined>(() => {
23
+ return p.value
24
+ ? (participantTracksObservable(p.value, { sources }) as unknown as Observable<
25
+ TrackReference[]
26
+ >)
27
+ : undefined;
28
+ });
29
+
30
+ const trackRefs = useObservableState<TrackReference[]>({
31
+ observable: observable.value,
32
+ startWith: [],
33
+ });
34
+
35
+ return trackRefs;
36
+ }
@@ -0,0 +1,25 @@
1
+ import type { LocalParticipant, RemoteParticipant, Room, RoomEvent } from 'livekit-client';
2
+ import { computed, type ShallowRef } from 'vue';
3
+ import { useLocalParticipant } from './useLocalParticipant';
4
+ import { useRemoteParticipants } from './useRemoteParticipants';
5
+
6
+ export type UseParticipantsOptions = {
7
+ updateOnlyOn?: RoomEvent[];
8
+ room?: Room;
9
+ };
10
+
11
+ export function useParticipants(
12
+ options: UseParticipantsOptions = {},
13
+ ): ShallowRef<(RemoteParticipant | LocalParticipant)[]> {
14
+ const remoteParticipants = useRemoteParticipants(options);
15
+ const localParticipant = useLocalParticipant()?.localParticipant;
16
+
17
+ const participants = computed<(RemoteParticipant | LocalParticipant)[]>(() => {
18
+ return [localParticipant.value, ...remoteParticipants.value] as (
19
+ | RemoteParticipant
20
+ | LocalParticipant
21
+ )[];
22
+ });
23
+
24
+ return participants;
25
+ }
@@ -0,0 +1,64 @@
1
+ import { loadUserChoices, saveUserChoices, type LocalUserChoices } from '@livekit/components-core';
2
+ import { ref, watch, type ShallowRef } from 'vue';
3
+
4
+ export type UsePersistentUserChoicesOptions = {
5
+ defaults?: Partial<LocalUserChoices>;
6
+ preventSave?: boolean;
7
+ preventLoad?: boolean;
8
+ };
9
+
10
+ export type UsePersistentUserChoicesReturnType = {
11
+ userChoices: ShallowRef<LocalUserChoices>;
12
+ saveAudioInputEnabled: (enabled: boolean) => void;
13
+ saveVideoInputEnabled: (enabled: boolean) => void;
14
+ saveAudioInputDeviceId: (deviceId: string) => void;
15
+ saveVideoInputDeviceId: (deviceId: string) => void;
16
+ saveUsername: (username: string) => void;
17
+ };
18
+
19
+ export function usePersistentUserChoices(
20
+ options: UsePersistentUserChoicesOptions = {},
21
+ ): UsePersistentUserChoicesReturnType {
22
+ const userChoices = ref<LocalUserChoices>(
23
+ loadUserChoices(options.defaults, options.preventLoad ?? false),
24
+ );
25
+
26
+ function saveAudioInputDeviceId(deviceId: string) {
27
+ userChoices.value = { ...userChoices.value, audioDeviceId: deviceId };
28
+ }
29
+
30
+ function saveVideoInputDeviceId(deviceId: string) {
31
+ userChoices.value = { ...userChoices.value, videoDeviceId: deviceId };
32
+ }
33
+
34
+ function saveAudioInputEnabled(enabled: boolean) {
35
+ userChoices.value = { ...userChoices.value, audioEnabled: enabled };
36
+ }
37
+
38
+ function saveVideoInputEnabled(enabled: boolean) {
39
+ userChoices.value = { ...userChoices.value, videoEnabled: enabled };
40
+ }
41
+
42
+ function saveUsername(username: string) {
43
+ userChoices.value = { ...userChoices.value, username };
44
+ }
45
+
46
+ watch(
47
+ [userChoices, options.preventSave],
48
+ () => {
49
+ saveUserChoices(userChoices.value, options.preventSave ?? false);
50
+ },
51
+ {
52
+ deep: true,
53
+ },
54
+ );
55
+
56
+ return {
57
+ userChoices,
58
+ saveAudioInputEnabled,
59
+ saveVideoInputEnabled,
60
+ saveAudioInputDeviceId,
61
+ saveVideoInputDeviceId,
62
+ saveUsername,
63
+ };
64
+ }
@@ -0,0 +1,16 @@
1
+ import { useEnsureLayoutContext, type LayoutState } from '@/context/layout.context';
2
+ import type { TrackReferenceOrPlaceholder } from '@livekit/components-core';
3
+ import { computed, type ShallowRef } from 'vue';
4
+
5
+ export function usePinnedTracks(context?: LayoutState): ShallowRef<TrackReferenceOrPlaceholder[]> {
6
+ const layoutContext = useEnsureLayoutContext(context);
7
+
8
+ const pinState = computed<TrackReferenceOrPlaceholder[]>(() => {
9
+ if (layoutContext.value?.pin.state !== undefined && layoutContext.value.pin.state.length >= 1) {
10
+ return layoutContext.value.pin.state;
11
+ }
12
+ return [];
13
+ });
14
+
15
+ return pinState;
16
+ }
@@ -0,0 +1,42 @@
1
+ import { useEnsureRoomContext } from '@/context/room.context';
2
+ import {
3
+ connectedParticipantObserver,
4
+ participantByIdentifierObserver,
5
+ type ParticipantIdentifier,
6
+ } from '@livekit/components-core';
7
+ import { useSubscription } from '@vueuse/rxjs';
8
+ import type { Participant, ParticipantEvent, RemoteParticipant, Room } from 'livekit-client';
9
+ import { computed, ref, type Ref, type ShallowRef } from 'vue';
10
+
11
+ export type UseRemoteParticipantOptions = {
12
+ updateOnlyOn?: ParticipantEvent[];
13
+ };
14
+
15
+ export function useRemoteParticipant(
16
+ identityOrIdentifier: string | ParticipantIdentifier,
17
+ options: UseRemoteParticipantOptions = {},
18
+ ): ShallowRef<Participant | undefined> {
19
+ const room: Ref<Room> = useEnsureRoomContext();
20
+ const updateOnlyOn: Ref<ParticipantEvent[]> = ref(options.updateOnlyOn ?? []);
21
+ const participant: Ref<RemoteParticipant | undefined> = ref(undefined);
22
+
23
+ const observable = computed(() => {
24
+ if (typeof identityOrIdentifier === 'string') {
25
+ return connectedParticipantObserver(room.value, identityOrIdentifier, {
26
+ additionalEvents: updateOnlyOn.value,
27
+ });
28
+ } else {
29
+ return participantByIdentifierObserver(room.value, identityOrIdentifier, {
30
+ additionalEvents: updateOnlyOn.value,
31
+ });
32
+ }
33
+ });
34
+
35
+ useSubscription(
36
+ observable.value.subscribe((p) => {
37
+ participant.value = p;
38
+ }),
39
+ );
40
+
41
+ return participant;
42
+ }
@@ -0,0 +1,27 @@
1
+ import { useEnsureRoomContext } from '@/context/room.context';
2
+ import { connectedParticipantsObserver } from '@livekit/components-core';
3
+ import { useSubscription } from '@vueuse/rxjs';
4
+ import type { Participant, Room, RoomEvent } from 'livekit-client';
5
+ import { ref, watch, type ShallowRef } from 'vue';
6
+
7
+ export type UseRemoteParticipantsOptions = {
8
+ updateOnlyOn?: RoomEvent[];
9
+ room?: Room;
10
+ };
11
+
12
+ export function useRemoteParticipants(
13
+ options: UseRemoteParticipantsOptions = {},
14
+ ): ShallowRef<Participant[]> {
15
+ const room = useEnsureRoomContext(options.room);
16
+ const participants = ref<Participant[]>([]);
17
+
18
+ watch([room, options.updateOnlyOn], () => {
19
+ useSubscription(
20
+ connectedParticipantsObserver(room.value, {
21
+ additionalRoomEvents: options.updateOnlyOn,
22
+ }).subscribe((v) => (participants.value = v)),
23
+ );
24
+ });
25
+
26
+ return participants as ShallowRef<Participant[]>;
27
+ }
@@ -0,0 +1,42 @@
1
+ import { useEnsureRoomContext } from '@/context/room.context';
2
+ import { roomInfoObserver } from '@livekit/components-core';
3
+ import { useObservable } from '@vueuse/rxjs';
4
+ import type { Room } from 'livekit-client';
5
+ import type { Observable } from 'rxjs';
6
+ import { toRefs, type ShallowRef } from 'vue';
7
+ import { useObservableState } from './private/useObservableState';
8
+
9
+ export type UseRoomInfoOptions = {
10
+ room?: Room;
11
+ };
12
+
13
+ export type RoomInfo = {
14
+ name: string;
15
+ metadata: string;
16
+ };
17
+
18
+ export function useRoomInfo(options: UseRoomInfoOptions = {}): {
19
+ name: ShallowRef<string>;
20
+ metadata: ShallowRef<string | undefined>;
21
+ } {
22
+ const room = useEnsureRoomContext(options.room);
23
+
24
+ const infoObserver = useObservable(
25
+ roomInfoObserver(room.value) as unknown as Observable<RoomInfo>,
26
+ );
27
+
28
+ const info = useObservableState({
29
+ observable: infoObserver.value as unknown as Observable<RoomInfo>,
30
+ startWith: {
31
+ name: room.value.name,
32
+ metadata: room.value.metadata,
33
+ },
34
+ });
35
+
36
+ const { name, metadata } = toRefs(info.value);
37
+
38
+ return {
39
+ name,
40
+ metadata,
41
+ };
42
+ }
@@ -0,0 +1,21 @@
1
+ import { sortParticipants } from '@livekit/components-core';
2
+ import type { Participant } from 'livekit-client';
3
+ import { ref, watch, type ShallowRef } from 'vue';
4
+ import { useSpeakingParticipants } from './useSpeakingParticipants';
5
+
6
+ export function useSortedParticipants(participants: Array<Participant>): ShallowRef<Participant[]> {
7
+ const activeSpeakers = useSpeakingParticipants();
8
+ const sortedParticipants = ref<Participant[]>(sortParticipants(participants));
9
+
10
+ watch(
11
+ [activeSpeakers, participants],
12
+ () => {
13
+ sortedParticipants.value = sortParticipants(participants);
14
+ },
15
+ {
16
+ deep: true,
17
+ },
18
+ );
19
+
20
+ return sortedParticipants as ShallowRef<Participant[]>;
21
+ }
@@ -0,0 +1,22 @@
1
+ import { useEnsureRoomContext } from '@/context/room.context';
2
+ import { activeSpeakerObserver } from '@livekit/components-core';
3
+ import { useObservable } from '@vueuse/rxjs';
4
+ import type { Participant } from 'livekit-client';
5
+ import type { Observable } from 'rxjs';
6
+ import type { ShallowRef } from 'vue';
7
+ import { useObservableState } from './private/useObservableState';
8
+
9
+ export function useSpeakingParticipants(): ShallowRef<Participant[]> {
10
+ const room = useEnsureRoomContext();
11
+
12
+ const speakerObserver = useObservable(
13
+ activeSpeakerObserver(room.value) as unknown as Observable<Participant[]>,
14
+ );
15
+
16
+ const activeSpeakers = useObservableState({
17
+ observable: speakerObserver.value as unknown as Observable<Participant[]>,
18
+ startWith: room.value.activeSpeakers,
19
+ });
20
+
21
+ return activeSpeakers;
22
+ }
@@ -0,0 +1,53 @@
1
+ import { useEnsureRoomContext } from '@/context/room.context';
2
+ import { setupStartAudio } from '@livekit/components-core';
3
+ import { useObservable } from '@vueuse/rxjs';
4
+ import type { Room } from 'livekit-client';
5
+ import type { Observable } from 'rxjs';
6
+ import { computed, ref, toRefs, type HTMLAttributes, type ShallowRef } from 'vue';
7
+ import { useObservableState } from './private/useObservableState';
8
+
9
+ export type UseStartAudioProps = {
10
+ room?: Room;
11
+ props: HTMLAttributes;
12
+ };
13
+
14
+ export type UseStartAudioReturnType = {
15
+ canPlayAudio: ShallowRef<boolean>;
16
+ elementProps: HTMLAttributes;
17
+ };
18
+
19
+ export function useStartAudio({ room, props }: UseStartAudioProps): UseStartAudioReturnType {
20
+ const roomEnsured = useEnsureRoomContext(room);
21
+
22
+ const setupStartAudioResult = computed(() => setupStartAudio());
23
+
24
+ const { className, roomAudioPlaybackAllowedObservable, handleStartAudioPlayback } = toRefs(
25
+ setupStartAudioResult.value,
26
+ );
27
+
28
+ const observable = useObservable(
29
+ roomAudioPlaybackAllowedObservable.value(roomEnsured.value) as unknown as Observable<{
30
+ canPlayAudio: boolean;
31
+ }>,
32
+ );
33
+
34
+ const canPlayAudioObj = useObservableState({
35
+ observable: observable.value as unknown as Observable<{ canPlayAudio: boolean }>,
36
+ startWith: {
37
+ canPlayAudio: roomEnsured.value.canPlaybackVideo,
38
+ },
39
+ });
40
+
41
+ const canPlayAudio = ref(canPlayAudioObj.value.canPlayAudio);
42
+
43
+ return {
44
+ canPlayAudio,
45
+ elementProps: {
46
+ ...props,
47
+ class: className.value,
48
+ onClick: () => {
49
+ handleStartAudioPlayback.value(roomEnsured.value);
50
+ },
51
+ },
52
+ };
53
+ }
@@ -0,0 +1,53 @@
1
+ import { useEnsureRoomContext } from '@/context/room.context';
2
+ import { setupStartVideo } from '@livekit/components-core';
3
+ import { useObservable } from '@vueuse/rxjs';
4
+ import type { Room } from 'livekit-client';
5
+ import type { Observable } from 'rxjs';
6
+ import { computed, ref, toRefs, type HTMLAttributes, type ShallowRef } from 'vue';
7
+ import { useObservableState } from './private/useObservableState';
8
+
9
+ export type UseStartVideoProps = {
10
+ room?: Room;
11
+ props: HTMLAttributes;
12
+ };
13
+
14
+ export type UseStartVideoReturnType = {
15
+ canPlayVideo: ShallowRef<boolean>;
16
+ elementProps: HTMLAttributes;
17
+ };
18
+
19
+ export function useStartVideo({ room, props }: UseStartVideoProps): UseStartVideoReturnType {
20
+ const roomEnsured = useEnsureRoomContext(room);
21
+
22
+ const setupStartVideoResult = computed<ReturnType<typeof setupStartVideo>>(() =>
23
+ setupStartVideo(),
24
+ );
25
+
26
+ const { className, roomVideoPlaybackAllowedObservable, handleStartVideoPlayback } = toRefs(
27
+ setupStartVideoResult.value,
28
+ );
29
+
30
+ const observable = useObservable(
31
+ roomVideoPlaybackAllowedObservable.value(roomEnsured.value) as unknown as Observable<{
32
+ canPlayVideo: boolean;
33
+ }>,
34
+ );
35
+
36
+ const canPlayVideoObj = useObservableState({
37
+ observable: observable.value as unknown as Observable<{ canPlayVideo: boolean }>,
38
+ startWith: {
39
+ canPlayVideo: roomEnsured.value.canPlaybackVideo,
40
+ },
41
+ });
42
+
43
+ return {
44
+ canPlayVideo: ref(canPlayVideoObj.value.canPlayVideo),
45
+ elementProps: {
46
+ ...props,
47
+ class: className.value,
48
+ onClick: () => {
49
+ handleStartVideoPlayback.value(roomEnsured.value);
50
+ },
51
+ },
52
+ };
53
+ }
@@ -0,0 +1,40 @@
1
+ import { ref, watch, type ShallowRef } from 'vue';
2
+
3
+ export type UserInfo = {
4
+ identity?: string;
5
+ name?: string;
6
+ metadata?: string;
7
+ };
8
+
9
+ export type UseTokenOptions = {
10
+ userInfo?: UserInfo;
11
+ };
12
+
13
+ export function useToken(
14
+ tokenEndpoint: string | undefined,
15
+ roomName: string,
16
+ options: UseTokenOptions = {},
17
+ ): ShallowRef<string | undefined> {
18
+ const token = ref<string | undefined>(undefined);
19
+
20
+ async function fetchToken() {
21
+ console.debug('fetching token');
22
+
23
+ const params = new URLSearchParams({ ...options.userInfo, roomName });
24
+ const res = await fetch(`${tokenEndpoint}?${params.toString()}`);
25
+
26
+ if (!res.ok) {
27
+ console.error(
28
+ `Could not fetch token. Server responded with status ${res.status}: ${res.statusText}`,
29
+ );
30
+ return;
31
+ }
32
+
33
+ const { accessToken } = await res.json();
34
+ token.value = accessToken;
35
+ }
36
+
37
+ watch([tokenEndpoint, roomName, options.userInfo], fetchToken);
38
+
39
+ return token;
40
+ }
@@ -0,0 +1,11 @@
1
+ import { useEnsureParticipant } from '@/context/participant.context';
2
+ import type { Participant, Track } from 'livekit-client';
3
+ import { useTrackRefBySourceOrName } from './useTrackRefBySourceOrName';
4
+
5
+ export function useTrack(
6
+ source: Track.Source,
7
+ participant?: Participant,
8
+ ): ReturnType<typeof useTrackRefBySourceOrName> {
9
+ const p = useEnsureParticipant(participant);
10
+ return useTrackRefBySourceOrName({ source, participant: p.value });
11
+ }
@@ -0,0 +1,11 @@
1
+ import { useEnsureParticipant } from '@/context/participant.context';
2
+ import type { Participant } from 'livekit-client';
3
+ import { useTrackRefBySourceOrName } from './useTrackRefBySourceOrName';
4
+
5
+ export function useTrackByName(
6
+ name: string,
7
+ participant?: Participant,
8
+ ): ReturnType<typeof useTrackRefBySourceOrName> {
9
+ const p = useEnsureParticipant(participant);
10
+ return useTrackRefBySourceOrName({ name, participant: p.value });
11
+ }
@@ -0,0 +1,34 @@
1
+ import { useEnsureTrackRef } from '@/context/track_reference.context';
2
+ import {
3
+ setupTrackMutedIndicator,
4
+ type TrackReferenceOrPlaceholder,
5
+ } from '@livekit/components-core';
6
+ import { useObservable } from '@vueuse/rxjs';
7
+ import type { Observable } from 'rxjs';
8
+ import { computed, toRefs, type ShallowRef } from 'vue';
9
+ import { useObservableState } from './private/useObservableState';
10
+
11
+ export function useTrackMutedIndicator(trackRef?: TrackReferenceOrPlaceholder): {
12
+ isMuted: ShallowRef<boolean>;
13
+ className: ShallowRef<string>;
14
+ } {
15
+ const trackReference = useEnsureTrackRef(trackRef);
16
+
17
+ const mediaTrackSetupResult = computed<ReturnType<typeof setupTrackMutedIndicator>>(() =>
18
+ setupTrackMutedIndicator(trackReference.value),
19
+ );
20
+
21
+ const { className, mediaMutedObserver } = toRefs(mediaTrackSetupResult.value);
22
+
23
+ const observable = useObservable(mediaMutedObserver.value as unknown as Observable<boolean>);
24
+
25
+ const isMuted = useObservableState({
26
+ observable: observable.value as unknown as Observable<boolean>,
27
+ startWith: !!(
28
+ trackReference.value.publication?.isMuted ||
29
+ trackReference.value.participant.getTrackPublication(trackReference.value.source)?.isMuted
30
+ ),
31
+ });
32
+
33
+ return { isMuted, className };
34
+ }