Switching the video feedback in Svelte
This commit is contained in:
parent
d1c22b122c
commit
b3aa8975e9
7 changed files with 107 additions and 103 deletions
|
@ -3,6 +3,7 @@
|
|||
import {menuIconVisible} from "../Stores/MenuStore";
|
||||
import {gameOverlayVisibilityStore} from "../Stores/MediaStore";
|
||||
import CameraControls from "./CameraControls.svelte";
|
||||
import MyCamera from "./MyCamera.svelte";
|
||||
|
||||
</script>
|
||||
|
||||
|
@ -11,6 +12,7 @@
|
|||
<!-- {#if $menuIconVisible}
|
||||
<MenuIcon />
|
||||
{/if} -->
|
||||
<MyCamera></MyCamera>
|
||||
<CameraControls></CameraControls>
|
||||
{/if}
|
||||
</div>
|
||||
|
|
46
front/src/Components/MyCamera.svelte
Normal file
46
front/src/Components/MyCamera.svelte
Normal file
|
@ -0,0 +1,46 @@
|
|||
<script lang="typescript">
|
||||
import {localStreamStore} from "../Stores/MediaStore";
|
||||
import SoundMeterWidget from "./SoundMeterWidget.svelte";
|
||||
import {onDestroy} from "svelte";
|
||||
|
||||
function srcObject(node, stream) {
|
||||
node.srcObject = stream;
|
||||
return {
|
||||
update(newStream) {
|
||||
if (node.srcObject != newStream) {
|
||||
node.srcObject = newStream
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let stream : MediaStream|null;
|
||||
/*$: {
|
||||
if ($localStreamStore.type === 'success') {
|
||||
stream = $localStreamStore.stream;
|
||||
} else {
|
||||
stream = null;
|
||||
}
|
||||
}*/
|
||||
|
||||
const unsubscribe = localStreamStore.subscribe(value => {
|
||||
if (value.type === 'success') {
|
||||
stream = value.stream;
|
||||
} else {
|
||||
stream = null;
|
||||
}
|
||||
});
|
||||
|
||||
onDestroy(unsubscribe);
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<div>
|
||||
<div class="video-container div-myCamVideo" class:hide={!$localStreamStore.constraints.video}>
|
||||
<video class="myCamVideo" use:srcObject={$localStreamStore.stream} autoplay muted></video>
|
||||
<!-- {#if stream}
|
||||
<SoundMeterWidget stream={stream}></SoundMeterWidget>
|
||||
{/if} -->
|
||||
</div>
|
||||
</div>
|
36
front/src/Components/SoundMeterWidget.svelte
Normal file
36
front/src/Components/SoundMeterWidget.svelte
Normal file
|
@ -0,0 +1,36 @@
|
|||
<script lang="typescript">
|
||||
import {SoundMeter} from "../Phaser/Components/SoundMeter";
|
||||
import {onDestroy} from "svelte";
|
||||
|
||||
export let stream: MediaStream;
|
||||
let volume = 0;
|
||||
|
||||
console.log('stream', stream);
|
||||
|
||||
if (stream.getAudioTracks().length > 0) {
|
||||
const soundMeter = new SoundMeter();
|
||||
soundMeter.connectToSource(stream, new AudioContext());
|
||||
|
||||
const timeout = setInterval(() => {
|
||||
try{
|
||||
volume = parseInt((soundMeter.getVolume() / 10).toFixed(0));
|
||||
console.log(volume);
|
||||
}catch(err){
|
||||
|
||||
}
|
||||
}, 100);
|
||||
|
||||
onDestroy(() => {
|
||||
clearInterval(timeout);
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<div class="sound-progress" class:active={stream?.getAudioTracks().length > 0}>
|
||||
<span class:active={volume > 1}></span>
|
||||
<span class:active={volume > 2}></span>
|
||||
<span class:active={volume > 3}></span>
|
||||
<span class:active={volume > 4}></span>
|
||||
<span class:active={volume > 5}></span>
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue