2021-05-31 17:49:41 +02:00
|
|
|
<script lang="typescript">
|
|
|
|
import {Game} from "../../Phaser/Game/Game";
|
2021-06-03 14:31:21 +02:00
|
|
|
import {EnableCameraScene, EnableCameraSceneName} from "../../Phaser/Login/EnableCameraScene";
|
2021-06-01 16:17:36 +02:00
|
|
|
import {
|
|
|
|
audioConstraintStore,
|
|
|
|
cameraListStore,
|
|
|
|
localStreamStore,
|
|
|
|
microphoneListStore,
|
|
|
|
videoConstraintStore
|
|
|
|
} from "../../Stores/MediaStore";
|
2021-06-01 11:19:46 +02:00
|
|
|
import {onDestroy} from "svelte";
|
2021-06-01 16:17:36 +02:00
|
|
|
import HorizontalSoundMeterWidget from "./HorizontalSoundMeterWidget.svelte";
|
|
|
|
import cinemaCloseImg from "../images/cinema-close.svg";
|
2021-06-02 09:58:00 +02:00
|
|
|
import cinemaImg from "../images/cinema.svg";
|
|
|
|
import microphoneImg from "../images/microphone.svg";
|
2021-05-31 17:49:41 +02:00
|
|
|
|
|
|
|
export let game: Game;
|
2021-06-01 16:17:36 +02:00
|
|
|
let selectedCamera : string|null = null;
|
|
|
|
let selectedMicrophone : string|null = null;
|
2021-05-31 17:49:41 +02:00
|
|
|
|
2021-06-03 14:31:21 +02:00
|
|
|
const enableCameraScene = game.scene.getScene(EnableCameraSceneName) as EnableCameraScene;
|
2021-05-31 17:49:41 +02:00
|
|
|
|
|
|
|
function submit() {
|
|
|
|
enableCameraScene.login();
|
|
|
|
}
|
|
|
|
|
2021-06-01 11:19:46 +02:00
|
|
|
function srcObject(node, stream) {
|
|
|
|
node.srcObject = stream;
|
|
|
|
return {
|
|
|
|
update(newStream) {
|
|
|
|
if (node.srcObject != newStream) {
|
|
|
|
node.srcObject = newStream
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 16:17:36 +02:00
|
|
|
let stream: MediaStream | null;
|
2021-06-01 11:19:46 +02:00
|
|
|
|
|
|
|
const unsubscribe = localStreamStore.subscribe(value => {
|
|
|
|
if (value.type === 'success') {
|
|
|
|
stream = value.stream;
|
2021-06-01 16:17:36 +02:00
|
|
|
|
|
|
|
if (stream !== null) {
|
|
|
|
const videoTracks = stream.getVideoTracks();
|
|
|
|
if (videoTracks.length > 0) {
|
|
|
|
selectedCamera = videoTracks[0].getSettings().deviceId;
|
|
|
|
}
|
|
|
|
const audioTracks = stream.getAudioTracks();
|
|
|
|
if (audioTracks.length > 0) {
|
|
|
|
selectedMicrophone = audioTracks[0].getSettings().deviceId;
|
|
|
|
}
|
|
|
|
}
|
2021-06-01 11:19:46 +02:00
|
|
|
} else {
|
|
|
|
stream = null;
|
2021-06-01 16:17:36 +02:00
|
|
|
selectedCamera = null;
|
|
|
|
selectedMicrophone = null;
|
2021-06-01 11:19:46 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
onDestroy(unsubscribe);
|
|
|
|
|
2021-06-01 16:17:36 +02:00
|
|
|
function normalizeDeviceName(label: string): string {
|
|
|
|
// remove text in parenthesis
|
|
|
|
return label.replace(/\([^()]*\)/g, '').trim();
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectCamera() {
|
|
|
|
videoConstraintStore.setDeviceId(selectedCamera);
|
|
|
|
}
|
|
|
|
|
|
|
|
function selectMicrophone() {
|
|
|
|
audioConstraintStore.setDeviceId(selectedMicrophone);
|
|
|
|
}
|
|
|
|
|
2021-05-31 17:49:41 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<form class="enableCameraScene" on:submit|preventDefault={submit}>
|
2021-06-01 16:17:36 +02:00
|
|
|
<section class="text-center">
|
2021-05-31 17:49:41 +02:00
|
|
|
<h2>Turn on your camera and microphone</h2>
|
|
|
|
</section>
|
2021-06-02 09:58:34 +02:00
|
|
|
{#if $localStreamStore.stream}
|
2021-06-03 14:31:21 +02:00
|
|
|
<video class="myCamVideoSetup" use:srcObject={$localStreamStore.stream} autoplay muted playsinline></video>
|
2021-06-02 09:58:34 +02:00
|
|
|
{:else }
|
|
|
|
<div class="webrtcsetup">
|
|
|
|
<img class="background-img" src={cinemaCloseImg} alt="">
|
|
|
|
</div>
|
|
|
|
{/if}
|
2021-06-01 16:17:36 +02:00
|
|
|
<HorizontalSoundMeterWidget stream={stream}></HorizontalSoundMeterWidget>
|
|
|
|
|
|
|
|
<section class="selectWebcamForm">
|
|
|
|
|
|
|
|
{#if $cameraListStore.length > 1 }
|
2021-06-02 09:58:00 +02:00
|
|
|
<div class="control-group">
|
2021-06-07 14:19:50 +02:00
|
|
|
<img src={cinemaImg} alt="Camera" />
|
2021-06-02 09:58:00 +02:00
|
|
|
<div class="nes-select">
|
|
|
|
<select bind:value={selectedCamera} on:change={selectCamera}>
|
|
|
|
{#each $cameraListStore as camera}
|
|
|
|
<option value={camera.deviceId}>
|
|
|
|
{normalizeDeviceName(camera.label)}
|
|
|
|
</option>
|
|
|
|
{/each}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-01 16:17:36 +02:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
{#if $microphoneListStore.length > 1 }
|
2021-06-02 09:58:00 +02:00
|
|
|
<div class="control-group">
|
|
|
|
<img src={microphoneImg} alt="Microphone" />
|
|
|
|
<div class="nes-select">
|
|
|
|
<select bind:value={selectedMicrophone} on:change={selectMicrophone}>
|
|
|
|
{#each $microphoneListStore as microphone}
|
|
|
|
<option value={microphone.deviceId}>
|
|
|
|
{normalizeDeviceName(microphone.label)}
|
|
|
|
</option>
|
|
|
|
{/each}
|
|
|
|
</select>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-06-01 16:17:36 +02:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
</section>
|
2021-05-31 17:49:41 +02:00
|
|
|
<section class="action">
|
|
|
|
<button type="submit" class="nes-btn is-primary letsgo" >Let's go!</button>
|
|
|
|
</section>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.enableCameraScene {
|
|
|
|
pointer-events: auto;
|
|
|
|
margin: 20px auto 0;
|
|
|
|
color: #ebeeee;
|
2021-06-01 16:17:36 +02:00
|
|
|
|
|
|
|
section.selectWebcamForm {
|
|
|
|
margin-top: 3vh;
|
2021-06-07 10:29:38 +02:00
|
|
|
margin-bottom: 3vh;
|
2021-06-01 16:17:36 +02:00
|
|
|
min-height: 10vh;
|
2021-06-07 09:27:49 +02:00
|
|
|
width: 50vw;
|
2021-06-01 16:17:36 +02:00
|
|
|
margin-left: auto;
|
|
|
|
margin-right: auto;
|
|
|
|
|
|
|
|
select {
|
|
|
|
font-family: "Press Start 2P";
|
2021-06-07 14:19:50 +02:00
|
|
|
margin-top: 1vh;
|
|
|
|
margin-bottom: 1vh;
|
2021-06-01 16:17:36 +02:00
|
|
|
|
|
|
|
option {
|
|
|
|
font-family: "Press Start 2P";
|
|
|
|
}
|
|
|
|
}
|
2021-05-31 17:49:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
section.action{
|
|
|
|
text-align: center;
|
|
|
|
margin: 0;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
h2{
|
|
|
|
font-family: "Press Start 2P";
|
|
|
|
margin: 1px;
|
|
|
|
}
|
|
|
|
|
|
|
|
section.text-center{
|
|
|
|
text-align: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
button.letsgo {
|
|
|
|
font-size: 200%;
|
|
|
|
}
|
2021-06-01 11:19:46 +02:00
|
|
|
|
2021-06-02 09:58:00 +02:00
|
|
|
.control-group {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
|
|
|
|
img {
|
|
|
|
width: 30px;
|
2021-06-07 14:19:50 +02:00
|
|
|
margin-right: 10px;
|
2021-06-02 09:58:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 11:19:46 +02:00
|
|
|
.webrtcsetup{
|
2021-06-01 16:17:36 +02:00
|
|
|
margin-top: 2vh;
|
2021-06-01 11:19:46 +02:00
|
|
|
margin-left: auto;
|
|
|
|
margin-right: auto;
|
2021-06-01 16:17:36 +02:00
|
|
|
height: 28.125vw;
|
|
|
|
width: 50vw;
|
2021-06-01 11:19:46 +02:00
|
|
|
border: white 6px solid;
|
|
|
|
|
2021-06-01 16:17:36 +02:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
|
2021-06-01 11:19:46 +02:00
|
|
|
img.background-img {
|
|
|
|
width: 40%;
|
|
|
|
}
|
|
|
|
}
|
2021-06-02 09:58:34 +02:00
|
|
|
.myCamVideoSetup {
|
|
|
|
margin-top: 2vh;
|
|
|
|
margin-left: auto;
|
|
|
|
margin-right: auto;
|
2021-06-03 10:30:53 +02:00
|
|
|
max-height: 50vh;
|
2021-06-02 09:58:34 +02:00
|
|
|
width: 50vw;
|
|
|
|
border: white 6px solid;
|
|
|
|
-webkit-transform: scaleX(-1);
|
|
|
|
transform: scaleX(-1);
|
|
|
|
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
2021-06-01 11:19:46 +02:00
|
|
|
}
|
2021-06-07 14:19:50 +02:00
|
|
|
}
|
2021-06-01 11:19:46 +02:00
|
|
|
|
2021-06-07 14:19:50 +02:00
|
|
|
@media only screen and (max-width: 800px) {
|
|
|
|
* {
|
|
|
|
font-size: 80%;
|
|
|
|
}
|
|
|
|
.enableCameraScene .control-group img {
|
|
|
|
width: 15px;
|
|
|
|
margin-right: 5px;
|
|
|
|
}
|
2021-05-31 17:49:41 +02:00
|
|
|
}
|
2021-06-07 14:19:50 +02:00
|
|
|
|
|
|
|
|
2021-05-31 17:49:41 +02:00
|
|
|
</style>
|
|
|
|
|