-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
380 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<script> | ||
export let state | ||
export let peer | ||
export let cancel | ||
let values = [] | ||
let code = '' | ||
peer.signalingPort.onmessage = ({ data }) => { | ||
const { description, candidate } = typeof data === 'string' ? JSON.parse(data) : data | ||
if (description) { | ||
if (description.type === 'answer') values = [] | ||
values.push(description.sdp) | ||
} else if (candidate) { | ||
values.push(candidate.candidate) | ||
} | ||
code = btoa(JSON.stringify(values)) | ||
} | ||
$: value = (step?.mode === 'copy' && code) || null | ||
function handleInput({ target }) { | ||
const val = JSON.parse(atob(target.value)) | ||
const [description, ...candidates] = val | ||
peer.signalingPort.postMessage({ | ||
description: { | ||
type: state === 'host' ? 'answer' : 'offer', | ||
sdp: description | ||
} | ||
}) | ||
for (const candidate of candidates) { | ||
peer.signalingPort.postMessage({ | ||
candidate: { | ||
candidate, | ||
sdpMid: '0', | ||
sdpMLineIndex: 0 | ||
} | ||
}) | ||
} | ||
value = null | ||
index = index + 1 | ||
} | ||
function copyData() { | ||
navigator.clipboard.writeText(value) | ||
index = index + 1 | ||
} | ||
let index = 0 | ||
$: step = map[state]?.[index] | ||
let map = { | ||
guest: [ | ||
{ | ||
title: 'Paste Invite Code', | ||
description: 'Paste the one time invite code sent to you by the lobby host.', | ||
mode: 'paste' | ||
}, | ||
{ | ||
title: 'Copy Invite Confirmation', | ||
description: 'Send the host this code, which required to request a connection.', | ||
mode: 'copy' | ||
} | ||
], | ||
host: [ | ||
{ | ||
title: 'Copy Invite Code', | ||
description: 'Copy the one time invite code, and send it to the person you wish to invite.', | ||
mode: 'copy' | ||
}, | ||
{ | ||
title: 'Paste Invite Confirmation', | ||
description: 'Paste the code sent to you by the user which wants to join your lobby.', | ||
mode: 'paste' | ||
} | ||
] | ||
} | ||
</script> | ||
<div class="h-full d-flex flex-column justify-content-center mb-20 pb-20 root container"> | ||
{#if step} | ||
<h1 class="font-weight-bold"> | ||
{step.title} | ||
</h1> | ||
<p class="font-size-18 mt-0"> | ||
{step.description} | ||
</p> | ||
<textarea disabled={step.mode === 'copy'} on:input={handleInput} bind:value class="form-control h-300 w-full mb-15" /> | ||
{#if step.mode === 'copy' && value} | ||
<button class="btn btn-primary mt-5" type="button" on:click={copyData} disabled={!value}>Copy</button> | ||
{/if} | ||
{/if} | ||
<button class="btn btn-danger mt-5" type="button" on:click={cancel}>Cancel</button> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<script> | ||
export let peers | ||
export let state | ||
export let invite | ||
export let cleanup | ||
</script> | ||
|
||
<div class="d-flex flex-column py-20 root container card"> | ||
<div class="d-flex align-items-center w-full"> | ||
<h1 class="font-weight-bold mr-auto">Lobby</h1> | ||
{#if state === 'host'} | ||
<button class="btn btn-success btn-lg ml-20" type="button" on:click={invite}>Invite To Lobby</button> | ||
{/if} | ||
<button class="btn btn-danger ml-20 btn-lg" type="button" on:click={cleanup}>Leave lobby</button> | ||
</div> | ||
{#each Object.values(peers) as peer} | ||
<div class="d-flex align-items-center "> | ||
{#if peer.user?.avatar?.medium} | ||
<img src={peer.user?.avatar?.medium} alt="avatar" class="w-50 img-fluid rounded" /> | ||
{/if} | ||
<h4 class="my-0 pl-20 mr-auto">{peer.user?.name || 'Anonymous'}</h4> | ||
{#if peer.user?.name} | ||
<span class="material-icons pointer text-primary" on:click={() => window.IPC.emit('open', 'https://anilist.co/user/' + peer.user?.name)}> open_in_new </span> | ||
{/if} | ||
{#if state === 'host'} | ||
<span class="material-icons ml-15 pointer text-danger" on:click={() => peer.peer.pc.close()}> logout </span> | ||
{/if} | ||
</div> | ||
{/each} | ||
</div> |
Oops, something went wrong.