mirror of
https://github.com/ThaUnknown/miru.git
synced 2026-04-18 10:52:04 +00:00
feat: new w2g sync
This commit is contained in:
parent
4da3254493
commit
8ba9d9f4cc
4 changed files with 69 additions and 23 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "Miru",
|
||||
"version": "3.10.6",
|
||||
"version": "3.10.7",
|
||||
"author": "ThaUnknown_ <ThaUnknown@users.noreply.github.com>",
|
||||
"description": "Stream anime torrents, real-time with no waiting for downloads.",
|
||||
"main": "src/index.js",
|
||||
|
|
@ -115,7 +115,6 @@
|
|||
"js-levenshtein": "^1.1.6",
|
||||
"matroska-subtitles": "github:ThaUnknown/matroska-subtitles#redist",
|
||||
"mime": "^3.0.0",
|
||||
"p2pcf": "github:ThaUnknown/p2pcf#no-remove",
|
||||
"perfect-seekbar": "^1.1.0",
|
||||
"pump": "^3.0.0",
|
||||
"quartermoon": "^1.2.3",
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ specifiers:
|
|||
matroska-subtitles: github:ThaUnknown/matroska-subtitles#redist
|
||||
mime: ^3.0.0
|
||||
p2pcf: github:ThaUnknown/p2pcf#no-remove
|
||||
p2pt: ^1.5.1
|
||||
perfect-seekbar: ^1.1.0
|
||||
pump: ^3.0.0
|
||||
quartermoon: ^1.2.3
|
||||
|
|
@ -41,6 +42,7 @@ dependencies:
|
|||
matroska-subtitles: github.com/ThaUnknown/matroska-subtitles/446d0628ff0bcf13eb95184777615f3a0e6d8ae8
|
||||
mime: 3.0.0
|
||||
p2pcf: github.com/ThaUnknown/p2pcf/faefe2854c817315530636a58d07726de7050561
|
||||
p2pt: 1.5.1
|
||||
perfect-seekbar: 1.1.0
|
||||
pump: 3.0.0
|
||||
quartermoon: 1.2.3
|
||||
|
|
@ -1235,6 +1237,14 @@ packages:
|
|||
dev: true
|
||||
optional: true
|
||||
|
||||
/domexception/1.0.1:
|
||||
resolution: {integrity: sha512-raigMkn7CJNNo6Ihro1fzG7wr3fHuYVytzquZKX5n0yizGsTcYgzdIUwj1X9pK0VvjeihV+XiclP+DjwbsSKug==}
|
||||
requiresBuild: true
|
||||
dependencies:
|
||||
webidl-conversions: 4.0.2
|
||||
dev: false
|
||||
optional: true
|
||||
|
||||
/dotenv-expand/5.1.0:
|
||||
resolution: {integrity: sha512-YXQl1DSa4/PQyRfgrv6aoNjhasp/p4qs9FjJ4q4cQk+8m4r6k4ZSiEyytKG8f8W9gi8WsQtIObNmKd+tMzNTmA==}
|
||||
dev: true
|
||||
|
|
@ -2246,6 +2256,18 @@ packages:
|
|||
engines: {node: '>=8'}
|
||||
dev: true
|
||||
|
||||
/p2pt/1.5.1:
|
||||
resolution: {integrity: sha512-q1pkIKBRvGcQfv5Q3W0/c9pbBUnjcauWylc/qUZwIqcrQIxu3rfuDQXsqjwEJaBwdPNPWMY06jc5qxwVgJX6MA==}
|
||||
dependencies:
|
||||
bittorrent-tracker: 9.19.0
|
||||
randombytes: 2.1.0
|
||||
simple-sha1: 3.1.0
|
||||
optionalDependencies:
|
||||
wrtc: 0.4.7
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
|
||||
/package-json-versionify/1.0.4:
|
||||
resolution: {integrity: sha512-mtKKtCeSZMtWcc5hHJS6OlEGP7J9g7WN6vWCCZi2hCXFag/Zmjokh6WFFTQb9TuMnBcZpRjhhMQyOyglPCAahw==}
|
||||
dependencies:
|
||||
|
|
@ -3099,6 +3121,11 @@ packages:
|
|||
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
|
||||
dev: false
|
||||
|
||||
/webidl-conversions/4.0.2:
|
||||
resolution: {integrity: sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==}
|
||||
dev: false
|
||||
optional: true
|
||||
|
||||
/webtorrent/1.9.6:
|
||||
resolution: {integrity: sha512-fJtVlqeg7s4G3MHppdONfHfspvdfJPTEgSUnc4W+i0tCtl1hyWHSdodC2T4VtNNE00Rdy60dLji3Ai0Y/FXvow==}
|
||||
engines: {node: '>=14'}
|
||||
|
|
@ -3180,6 +3207,17 @@ packages:
|
|||
/wrappy/1.0.2:
|
||||
resolution: {integrity: sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==}
|
||||
|
||||
/wrtc/0.4.7:
|
||||
resolution: {integrity: sha512-P6Hn7VT4lfSH49HxLHcHhDq+aFf/jd9dPY7lDHeFhZ22N3858EKuwm2jmnlPzpsRGEPaoF6XwkcxY5SYnt4f/g==}
|
||||
engines: {node: ^8.11.2 || >=10.0.0}
|
||||
requiresBuild: true
|
||||
optionalDependencies:
|
||||
domexception: 1.0.1
|
||||
dev: false
|
||||
optional: true
|
||||
bundledDependencies:
|
||||
- node-pre-gyp
|
||||
|
||||
/ws/7.5.9:
|
||||
resolution: {integrity: sha512-F+P9Jil7UiSKSkppIiD94dN07AwvFixvLIj1Og1Rl9GGMuNipJnV9JzjD6XuqmAeiswGvUmNLjr5cFuXwNS77Q==}
|
||||
engines: {node: '>=8.3.0'}
|
||||
|
|
|
|||
|
|
@ -137,8 +137,10 @@ class TorrentClient extends WebTorrent {
|
|||
destroyStoreOnDestroy: !this.settings.torrentPersist,
|
||||
announce: [
|
||||
'wss://tracker.openwebtorrent.com',
|
||||
'wss://tracker.webtorrent.dev',
|
||||
'wss://tracker.files.fm:7073/announce',
|
||||
'wss://spacetradersapi-chatbox.herokuapp.com:443/announce',
|
||||
'wss://peertube.cpy.re:443/tracker/socket'
|
||||
'wss://peertube.cpy.re/tracker/socket'
|
||||
]
|
||||
})
|
||||
break
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<script context='module'>
|
||||
import { writable } from 'svelte/store'
|
||||
import { writable, get } from 'svelte/store'
|
||||
import { alID } from '@/modules/anilist.js'
|
||||
import { add, client } from '@/modules/torrent.js'
|
||||
import { generateRandomHexCode } from '@/modules/util.js'
|
||||
|
|
@ -7,27 +7,30 @@
|
|||
import { page } from '@/App.svelte'
|
||||
import 'browser-event-target-emitter'
|
||||
|
||||
import P2PCF from 'p2pcf'
|
||||
import P2PT from 'https://esm.sh/p2pt?bundle'
|
||||
|
||||
export const w2gEmitter = new EventTarget()
|
||||
|
||||
const decode = TextDecoder.prototype.decode.bind(new TextDecoder('utf-8'))
|
||||
const encode = TextEncoder.prototype.encode.bind(new TextEncoder())
|
||||
|
||||
const peers = writable({})
|
||||
|
||||
export const state = writable(false)
|
||||
|
||||
let p2pcf = null
|
||||
let p2pt = null
|
||||
|
||||
function joinLobby (code = generateRandomHexCode(16)) {
|
||||
if (p2pcf) cleanup()
|
||||
p2pcf = new P2PCF(generateRandomHexCode(16), code)
|
||||
p2pcf.on('peerconnect', async peer => {
|
||||
if (p2pt) cleanup()
|
||||
p2pt = new P2PT([
|
||||
'wss://tracker.openwebtorrent.com',
|
||||
'wss://tracker.webtorrent.dev',
|
||||
'wss://tracker.files.fm:7073/announce',
|
||||
'wss://spacetradersapi-chatbox.herokuapp.com:443/announce',
|
||||
'wss://peertube.cpy.re/tracker/socket'
|
||||
], code)
|
||||
p2pt.on('peerconnect', async peer => {
|
||||
console.log(peer.id)
|
||||
console.log('connect')
|
||||
const user = (await alID)?.data?.Viewer || {}
|
||||
peer.send(
|
||||
p2pt.send(peer,
|
||||
JSON.stringify({
|
||||
type: 'init',
|
||||
id: user.id || generateRandomHexCode(16),
|
||||
|
|
@ -35,7 +38,7 @@
|
|||
})
|
||||
)
|
||||
})
|
||||
p2pcf.on('peerclose', peer => {
|
||||
p2pt.on('peerclose', peer => {
|
||||
peers.update(object => {
|
||||
console.log(peer.id)
|
||||
console.log('close', object[peer.id])
|
||||
|
|
@ -43,9 +46,9 @@
|
|||
return object
|
||||
})
|
||||
})
|
||||
p2pcf.on('msg', (peer, data) => {
|
||||
data = typeof data === 'string' ? JSON.parse(data) : JSON.parse(decode(data))
|
||||
p2pt.on('msg', (peer, data) => {
|
||||
console.log(data)
|
||||
data = typeof data === 'string' ? JSON.parse(data) : data
|
||||
switch (data.type) {
|
||||
case 'init':
|
||||
console.log('init', data.user)
|
||||
|
|
@ -80,9 +83,9 @@
|
|||
}
|
||||
}
|
||||
})
|
||||
p2pcf.start()
|
||||
p2pt.start()
|
||||
state.set(code)
|
||||
console.log(p2pcf)
|
||||
console.log(p2pt)
|
||||
}
|
||||
|
||||
function setPlayerState (detail) {
|
||||
|
|
@ -114,7 +117,11 @@
|
|||
})
|
||||
|
||||
function emit (type, data) {
|
||||
p2pcf?.broadcast(encode(JSON.stringify({ type, ...data })))
|
||||
if (p2pt) {
|
||||
for (const { peer } of Object.values(get(peers))) {
|
||||
p2pt.send(peer, { type, ...data })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const playerState = {
|
||||
|
|
@ -140,13 +147,13 @@
|
|||
function cleanup () {
|
||||
state.set(false)
|
||||
peers.set({})
|
||||
p2pcf.destroy()
|
||||
p2pcf = null
|
||||
p2pt.destroy()
|
||||
p2pt = null
|
||||
}
|
||||
|
||||
function invite () {
|
||||
if (p2pcf) {
|
||||
navigator.clipboard.writeText(`https://miru.watch/w2g/${p2pcf.roomId}`)
|
||||
if (p2pt) {
|
||||
navigator.clipboard.writeText(`https://miru.watch/w2g/${p2pt.identifierString}`)
|
||||
addToast({
|
||||
title: 'Copied to clipboard',
|
||||
text: 'Copied invite URL to clipboard',
|
||||
|
|
|
|||
Loading…
Reference in a new issue