Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix format #88

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 45 additions & 45 deletions src/client/src/lib/components/lesson/Container.svelte
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
<script lang="ts">
import { onMount } from 'svelte';
import { type Call, type StreamVideoParticipant } from '@stream-io/video-client';
import { onMount } from 'svelte';
import { type Call, type StreamVideoParticipant } from '@stream-io/video-client';

import Participant from './Participant.svelte';
import ScreenShare from './ScreenShare.svelte';
import Participant from './Participant.svelte';
import ScreenShare from './ScreenShare.svelte';

export let call: Call;
export let call: Call;

let participants: StreamVideoParticipant[] = [];
let participants: StreamVideoParticipant[] = [];

import { screenShareEnabled } from '$lib/store/index';
import { screenShareEnabled } from '$lib/store/index';

onMount(() => {
const parentContainer = document.getElementById('participants');
onMount(() => {
const parentContainer = document.getElementById('participants');

if (parentContainer) call.setViewport(parentContainer);
if (parentContainer) call.setViewport(parentContainer);

call.state.participants$.subscribe((updatedParticipants) => {
participants = updatedParticipants;
});
});
call.state.participants$.subscribe((updatedParticipants) => {
participants = updatedParticipants;
});
});

function getParticipantClass(index: number): string {
const total = participants.length;
function getParticipantClass(index: number): string {
const total = participants.length;

if (total === 1) {
return 'w-full h-full';
} else if (total === 2) {
return 'w-1/2 h-full';
} else if (total === 3) {
return index === 0 ? 'w-1/2 h-1/2' : 'w-1/2 h-1/2';
} else if (total === 4) {
return 'w-1/2 h-1/2';
} else if (total <= 6) {
return 'w-1/3 h-1/2';
} else {
return 'w-1/4 h-1/4';
}
}
if (total === 1) {
return 'w-full h-full';
} else if (total === 2) {
return 'w-1/2 h-full';
} else if (total === 3) {
return index === 0 ? 'w-1/2 h-1/2' : 'w-1/2 h-1/2';
} else if (total === 4) {
return 'w-1/2 h-1/2';
} else if (total <= 6) {
return 'w-1/3 h-1/2';
} else {
return 'w-1/4 h-1/4';
}
}

let showScreenShare: boolean;

let showScreenShare:boolean;

screenShareEnabled.subscribe((value:boolean) => {
showScreenShare = value});
screenShareEnabled.subscribe((value: boolean) => {
showScreenShare = value;
});
</script>

<div id="participants" class="flex flex-wrap justify-center h-full">
{#each participants as participant, index}
<div class={`participant ${getParticipantClass(index)} flex items-center justify-center p-2`}>
{#if showScreenShare}
<ScreenShare {call} {participant} />
{:else}
<Participant {call} {participant} />
{/if}
</div>
{/each}
</div>
<div id="participants" class="flex h-full flex-wrap justify-center">
{#each participants as participant, index}
<div class={`participant ${getParticipantClass(index)} flex items-center justify-center p-2`}>
{#if showScreenShare}
<ScreenShare {call} {participant} />
{:else}
<Participant {call} {participant} />
{/if}
</div>
{/each}
</div>
88 changes: 60 additions & 28 deletions src/client/src/lib/components/lesson/ControlPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@
import { type Call } from '@stream-io/video-client';
import { goto } from '$app/navigation';
import { Button } from 'flowbite-svelte';
import { MicrophoneOutline, MicrophoneSlashOutline, VideoCameraOutline, ArrowUpFromBracketOutline, PhoneHangupOutline } from 'flowbite-svelte-icons';
import {
MicrophoneOutline,
MicrophoneSlashOutline,
VideoCameraOutline,
ArrowUpFromBracketOutline,
PhoneHangupOutline
} from 'flowbite-svelte-icons';
import { writable } from 'svelte/store';
import {screenShareEnabled} from '$lib/store/index'
import { screenShareEnabled } from '$lib/store/index';

export let call: Call;

const microphoneEnabled = writable(false);
const cameraEnabled = writable(false);

let screenShare
screenShareEnabled.subscribe((value:boolean) => {
screenShare = value

// eslint-disable-next-line @typescript-eslint/no-unused-vars
let screenShare;
screenShareEnabled.subscribe((value: boolean) => {
screenShare = value;
});

function toggleMicrophone() {
call.microphone.toggle();
microphoneEnabled.update(enabled => !enabled);
microphoneEnabled.update((enabled) => !enabled);
}

function toggleCamera() {
Expand All @@ -27,7 +34,7 @@

function toggleScreenShare() {
call.screenShare.toggle();
screenShareEnabled.update(enabled => !enabled);
screenShareEnabled.update((enabled) => !enabled);
}

function endCall() {
Expand All @@ -36,40 +43,65 @@
}
</script>

<div class="flex justify-around items-center h-full bg-gray-300 dark:bg-gray-800 p-4">

{#if $microphoneEnabled}
<Button pill={true} on:click={toggleMicrophone} class="bg-green-500 text-white hover:bg-green-700">
<div class="flex h-full items-center justify-around bg-gray-300 p-4 dark:bg-gray-800">
{#if $microphoneEnabled}
<Button
pill={true}
on:click={toggleMicrophone}
class="bg-green-500 text-white hover:bg-green-700"
>
<MicrophoneOutline class="h-6 w-6" />
</Button>
{:else}
<Button pill={true} on:click={toggleMicrophone} class="bg-green-500 text-white hover:bg-green-700">
{:else}
<Button
pill={true}
on:click={toggleMicrophone}
class="bg-green-500 text-white hover:bg-green-700"
>
<MicrophoneSlashOutline class="h-6 w-6" />
</Button>
{/if}


{/if}

{#if $cameraEnabled}
<Button pill={true} on:click={toggleCamera} class="bg-green-500 dark:bg-green-500 dark:hover:bg-green-700 text-white hover:bg-green-700">
<Button
pill={true}
on:click={toggleCamera}
class="bg-green-500 text-white hover:bg-green-700 dark:bg-green-500 dark:hover:bg-green-700"
>
<VideoCameraOutline class="h-6 w-6" />
</Button>
{:else}
<Button pill={true} on:click={toggleCamera} class="bg-gray-500 text-white dark:hover:bg-gray-700 hover:bg-gray-700 dark:bg-gray-500">
<Button
pill={true}
on:click={toggleCamera}
class="bg-gray-500 text-white hover:bg-gray-700 dark:bg-gray-500 dark:hover:bg-gray-700"
>
<VideoCameraOutline class="h-6 w-6" />
</Button>
{/if}

{#if $screenShareEnabled}
<Button pill={true} on:click={toggleScreenShare} class="bg-green-500 text-white hover:bg-green-700">
<ArrowUpFromBracketOutline class="h-6 w-6" />
</Button>
<Button
pill={true}
on:click={toggleScreenShare}
class="bg-green-500 text-white hover:bg-green-700"
>
<ArrowUpFromBracketOutline class="h-6 w-6" />
</Button>
{:else}
<Button pill={true} on:click={toggleScreenShare} class="bg-gray-500 text-white hover:bg-gray-700 dark:bg-gray-500 dark:hover:bg-gray-700">
<ArrowUpFromBracketOutline class="h-6 w-6" />
</Button>
<Button
pill={true}
on:click={toggleScreenShare}
class="bg-gray-500 text-white hover:bg-gray-700 dark:bg-gray-500 dark:hover:bg-gray-700"
>
<ArrowUpFromBracketOutline class="h-6 w-6" />
</Button>
{/if}
<Button pill={true} on:click={endCall} class="bg-red-500 text-white dark:bg-red-500 hover:bg-red-700 dark:hover:bg-red-700">
<Button
pill={true}
on:click={endCall}
class="bg-red-500 text-white hover:bg-red-700 dark:bg-red-500 dark:hover:bg-red-700"
>
<PhoneHangupOutline class="h-6 w-6" />
</Button>
</div>
</div>
4 changes: 2 additions & 2 deletions src/client/src/lib/components/lesson/Participant.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
export let participant: StreamVideoParticipant;
</script>

<div class="w-full h-full bg-gray-300 dark:bg-gray-400 flex items-center rounded-lg justify-center">
<div class="flex h-full w-full items-center justify-center rounded-lg bg-gray-300 dark:bg-gray-400">
<Video {call} {participant} />
<Audio {call} {participant} />
</div>
</div>
40 changes: 22 additions & 18 deletions src/client/src/lib/components/lesson/ScreenShare.svelte
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
<script lang="ts">
import { onMount } from 'svelte';
import { Call, type StreamVideoParticipant } from '@stream-io/video-client';
import { onMount } from 'svelte';
import { Call, type StreamVideoParticipant } from '@stream-io/video-client';

export let call: Call;
export let participant: StreamVideoParticipant;
export let call: Call;
export let participant: StreamVideoParticipant;

let videoEl: HTMLVideoElement;
let videoEl: HTMLVideoElement;

onMount(() => {
const unbind = call.bindVideoElement(videoEl, participant.sessionId, 'screenShareTrack');
const untrack = call.trackElementVisibility(videoEl, participant.sessionId, 'screenShareTrack');
onMount(() => {
const unbind = call.bindVideoElement(videoEl, participant.sessionId, 'screenShareTrack');
const untrack = call.trackElementVisibility(videoEl, participant.sessionId, 'screenShareTrack');

return () => {
if (unbind) unbind();
untrack();
};
});
return () => {
if (unbind) unbind();
untrack();
};
});
</script>

<div class="w-full h-full flex items-center justify-center">
<video bind:this={videoEl} data-session-id={participant.sessionId} class="w-full h-full object-contain">
<track kind="captions" />
</video>
</div>
<div class="flex h-full w-full items-center justify-center">
<video
bind:this={videoEl}
data-session-id={participant.sessionId}
class="h-full w-full object-contain"
>
<track kind="captions" />
</video>
</div>
40 changes: 22 additions & 18 deletions src/client/src/lib/components/lesson/Video.svelte
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
<script lang="ts">
import { onMount } from 'svelte';
import { Call, type StreamVideoParticipant } from '@stream-io/video-client';
import { onMount } from 'svelte';
import { Call, type StreamVideoParticipant } from '@stream-io/video-client';

export let call: Call;
export let participant: StreamVideoParticipant;
export let call: Call;
export let participant: StreamVideoParticipant;

let videoEl: HTMLVideoElement;
let videoEl: HTMLVideoElement;

onMount(() => {
const unbind = call.bindVideoElement(videoEl, participant.sessionId, 'videoTrack');
const untrack = call.trackElementVisibility(videoEl, participant.sessionId, 'videoTrack');
onMount(() => {
const unbind = call.bindVideoElement(videoEl, participant.sessionId, 'videoTrack');
const untrack = call.trackElementVisibility(videoEl, participant.sessionId, 'videoTrack');

return () => {
if (unbind) unbind();
untrack();
};
});
return () => {
if (unbind) unbind();
untrack();
};
});
</script>

<div class="w-full h-full flex items-center justify-center">
<video bind:this={videoEl} data-session-id={participant.sessionId} class="w-full h-full object-cover">
<track kind="captions" />
</video>
</div>
<div class="flex h-full w-full items-center justify-center">
<video
bind:this={videoEl}
data-session-id={participant.sessionId}
class="h-full w-full object-cover"
>
<track kind="captions" />
</video>
</div>
2 changes: 1 addition & 1 deletion src/client/src/lib/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ export const userInfo = writable<any>({
workspaces: []
});

export const screenShareEnabled = writable(false);
export const screenShareEnabled = writable(false);
Loading
Loading