Skip to content

Commit

Permalink
feat: add w2g
Browse files Browse the repository at this point in the history
fix: #154
  • Loading branch information
ThaUnknown committed Apr 18, 2022
1 parent aba4083 commit 369c698
Show file tree
Hide file tree
Showing 12 changed files with 380 additions and 41 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Miru",
"version": "1.6.2",
"version": "1.7.0",
"author": "ThaUnknown_ <ThaUnknown@users.noreply.github.com>",
"main": "src/index.js",
"homepage": "https://github.com/ThaUnknown/miru#readme",
Expand All @@ -18,7 +18,7 @@
"electron": "^16.0.10",
"electron-builder": "^22.14.13",
"electron-notarize": "^1.1.1",
"svelte": "^3.46.4",
"svelte": "^3.47.0",
"vite": "^2.8.6",
"vite-plugin-commonjs-externals": "^0.1.1"
},
Expand All @@ -35,7 +35,9 @@
"build": {
"protocols": {
"name": "miru",
"schemes": ["miru"]
"schemes": [
"miru"
]
},
"publish": [
{
Expand Down
15 changes: 15 additions & 0 deletions src/renderer/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@
padding-top: 2rem;
}
:global(.root) {
animation: 0.3s ease 0s 1 root-load-in;
}
@keyframes root-load-in {
from {
bottom: -1.2rem;
transform: scale(0.95);
}
to {
bottom: 0;
transform: scale(1);
}
}
@media (max-width: 768px) {
.page-wrapper.with-sidebar[data-sidebar-type~='overlayed-sm-and-down'] > :global(.content-wrapper) {
left: var(--sidebar-minimised);
Expand Down
3 changes: 3 additions & 0 deletions src/renderer/src/lib/Router.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import Home from './pages/home/Home.svelte'
import Player from './pages/Player.svelte'
import Settings from './pages/Settings.svelte'
import WatchTogether from './pages/watchtogether/WatchTogether.svelte'
export let page = 'home'
const current = getContext('gallery')
</script>
Expand All @@ -19,6 +20,8 @@
<Settings />
{:else if page === 'home'}
<Home bind:current={$current} />
{:else if page === 'watchtogether'}
<WatchTogether />
{/if}
</div>

Expand Down
7 changes: 7 additions & 0 deletions src/renderer/src/lib/Sidebar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
icon: 'queue_music',
text: 'Now Playing'
},
{
click: () => {
page = 'watchtogether'
},
icon: 'groups',
text: 'Watch Together'
},
{
click: () => {
page = 'settings'
Expand Down
4 changes: 2 additions & 2 deletions src/renderer/src/lib/ViewAnime.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@
}
function getMediaMaxEp(media, playable) {
if (playable) {
return media.nextAiringEpisode?.episode - 1 || media.airingSchedule?.nodes?.[0].episode - 1 || media.episodes
return media.nextAiringEpisode?.episode - 1 || media.airingSchedule?.nodes?.[0]?.episode - 1 || media.episodes
} else {
return media.episodes || media.nextAiringEpisode?.episode - 1 || media.airingSchedule?.nodes?.[0].episode - 1
return media.episodes || media.nextAiringEpisode?.episode - 1 || media.airingSchedule?.nodes?.[0]?.episode - 1
}
}
</script>
Expand Down
15 changes: 14 additions & 1 deletion src/renderer/src/lib/pages/Player.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,23 @@
<script>
import { alEntry } from '@/modules/anilist.js'
import { client } from '@/modules/torrent.js'
import { resolveFileMedia } from '@/modules/anime.js'
import Peer from '@/modules/Peer.js'
import Subtitles from '@/modules/subtitles.js'
import { toTS, videoRx, fastPrettyBytes } from '@/modules/util.js'
import Keyboard from './Keyboard.svelte'
import { w2gEmitter } from './watchtogether/WatchTogether.svelte'
w2gEmitter.on('playerupdate',({detail})=>{
currentTime = detail.time
paused = detail.paused
})
function updatew2g() {
w2gEmitter.emit('player', { time: Math.floor(currentTime), paused })
}
async function mediaChange(current, image) {
if (current && 'mediaSession' in navigator) {
if (!media || (!hadImage && image)) {
Expand Down Expand Up @@ -788,6 +798,9 @@
bind:ended
bind:muted
bind:playbackRate
on:pause={updatew2g}
on:play={updatew2g}
on:seeked={updatew2g}
on:timeupdate={() => createThumbnail()}
on:timeupdate={checkCompletion}
on:waiting={showBuffering}
Expand Down
19 changes: 1 addition & 18 deletions src/renderer/src/lib/pages/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,4 @@
</div>
</Tab>
</div>
</div></Tabs>

<style>
.root {
animation: 0.3s ease 0s 1 load-in;
}
@keyframes load-in {
from {
bottom: -1.2rem;
transform: scale(0.95);
}
to {
bottom: 0;
transform: scale(1);
}
}
</style>
</div></Tabs>
17 changes: 0 additions & 17 deletions src/renderer/src/lib/pages/home/Home.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,3 @@
{/if}
</div>
</div>
<style>
.root {
animation: 0.3s ease 0s 1 load-in;
}
@keyframes load-in {
from {
bottom: -1.2rem;
transform: scale(0.95);
}
to {
bottom: 0;
transform: scale(1);
}
}
</style>
93 changes: 93 additions & 0 deletions src/renderer/src/lib/pages/watchtogether/Connect.svelte
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>
30 changes: 30 additions & 0 deletions src/renderer/src/lib/pages/watchtogether/Lobby.svelte
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>
Loading

0 comments on commit 369c698

Please sign in to comment.