mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-16 12:42:06 +00:00
fix(music-together): fix unknown user
This commit is contained in:
@ -165,6 +165,17 @@ export default createPlugin<
|
|||||||
if (!wait) return false;
|
if (!wait) return false;
|
||||||
|
|
||||||
if (!this.me) this.me = getDefaultProfile(this.connection.id);
|
if (!this.me) this.me = getDefaultProfile(this.connection.id);
|
||||||
|
|
||||||
|
this.profiles = {};
|
||||||
|
this.putProfile(this.connection.id, {
|
||||||
|
id: this.connection.id,
|
||||||
|
...this.me,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.queue?.setOwner({
|
||||||
|
id: this.connection.id,
|
||||||
|
...this.me,
|
||||||
|
});
|
||||||
const rawItems =
|
const rawItems =
|
||||||
this.queue?.flatItems?.map(
|
this.queue?.flatItems?.map(
|
||||||
(it) =>
|
(it) =>
|
||||||
@ -173,16 +184,11 @@ export default createPlugin<
|
|||||||
ownerId: this.connection!.id,
|
ownerId: this.connection!.id,
|
||||||
}) satisfies VideoData,
|
}) satisfies VideoData,
|
||||||
) ?? [];
|
) ?? [];
|
||||||
this.queue?.setOwner({
|
|
||||||
id: this.connection.id,
|
|
||||||
...this.me,
|
|
||||||
});
|
|
||||||
this.queue?.setVideoList(rawItems, false);
|
this.queue?.setVideoList(rawItems, false);
|
||||||
this.queue?.syncQueueOwner();
|
this.queue?.syncQueueOwner();
|
||||||
this.queue?.initQueue();
|
this.queue?.initQueue();
|
||||||
this.queue?.injection();
|
this.queue?.injection();
|
||||||
|
|
||||||
this.profiles = {};
|
|
||||||
this.connection.onConnections((connection) => {
|
this.connection.onConnections((connection) => {
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
this.api?.toastService?.show(
|
this.api?.toastService?.show(
|
||||||
@ -201,10 +207,6 @@ export default createPlugin<
|
|||||||
this.putProfile(connection.peer, undefined);
|
this.putProfile(connection.peer, undefined);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.putProfile(this.connection.id, {
|
|
||||||
id: this.connection.id,
|
|
||||||
...this.me,
|
|
||||||
});
|
|
||||||
|
|
||||||
const listener = async (
|
const listener = async (
|
||||||
event: ConnectionEventUnion,
|
event: ConnectionEventUnion,
|
||||||
@ -216,11 +218,18 @@ export default createPlugin<
|
|||||||
case 'ADD_SONGS': {
|
case 'ADD_SONGS': {
|
||||||
if (conn && this.permission === 'host-only') return;
|
if (conn && this.permission === 'host-only') return;
|
||||||
|
|
||||||
await this.queue?.addVideos(
|
const videoList: VideoData[] = event.payload.videoList.map(
|
||||||
event.payload.videoList,
|
(it) => ({
|
||||||
event.payload.index,
|
...it,
|
||||||
|
ownerId: it.ownerId ?? conn?.peer ?? this.connection!.id,
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
await this.connection?.broadcast('ADD_SONGS', event.payload);
|
|
||||||
|
await this.queue?.addVideos(videoList, event.payload.index);
|
||||||
|
await this.connection?.broadcast('ADD_SONGS', {
|
||||||
|
...event.payload,
|
||||||
|
videoList,
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'REMOVE_SONG': {
|
case 'REMOVE_SONG': {
|
||||||
@ -367,7 +376,13 @@ export default createPlugin<
|
|||||||
this.ignoreChange = true;
|
this.ignoreChange = true;
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case 'ADD_SONGS': {
|
case 'ADD_SONGS': {
|
||||||
await this.connection?.broadcast('ADD_SONGS', event.payload);
|
await this.connection?.broadcast('ADD_SONGS', {
|
||||||
|
...event.payload,
|
||||||
|
videoList: event.payload.videoList.map((it) => ({
|
||||||
|
...it,
|
||||||
|
ownerId: it.ownerId ?? this.connection!.id,
|
||||||
|
})),
|
||||||
|
});
|
||||||
await this.connection?.broadcast('SYNC_QUEUE', undefined);
|
await this.connection?.broadcast('SYNC_QUEUE', undefined);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -398,10 +413,14 @@ export default createPlugin<
|
|||||||
this.ignoreChange = true;
|
this.ignoreChange = true;
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case 'ADD_SONGS': {
|
case 'ADD_SONGS': {
|
||||||
await this.queue?.addVideos(
|
const videoList: VideoData[] = event.payload.videoList.map(
|
||||||
event.payload.videoList,
|
(it) => ({
|
||||||
event.payload.index,
|
...it,
|
||||||
|
ownerId: it.ownerId ?? this.connection!.id,
|
||||||
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await this.queue?.addVideos(videoList, event.payload.index);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'REMOVE_SONG': {
|
case 'REMOVE_SONG': {
|
||||||
|
|||||||
@ -177,7 +177,12 @@ export class Queue {
|
|||||||
if (!items) return false;
|
if (!items) return false;
|
||||||
|
|
||||||
this.internalDispatch = true;
|
this.internalDispatch = true;
|
||||||
this._videoList.push(...videos);
|
this._videoList.push(
|
||||||
|
...videos.map((it) => ({
|
||||||
|
...it,
|
||||||
|
ownerId: it.ownerId ?? this.owner?.id,
|
||||||
|
})),
|
||||||
|
);
|
||||||
this.queue?.dispatch({
|
this.queue?.dispatch({
|
||||||
type: 'ADD_ITEMS',
|
type: 'ADD_ITEMS',
|
||||||
payload: {
|
payload: {
|
||||||
@ -286,6 +291,7 @@ export class Queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.internalDispatch) {
|
if (!this.internalDispatch) {
|
||||||
|
console.log('Music Together: Queue event', event);
|
||||||
if (event.type === 'CLEAR') {
|
if (event.type === 'CLEAR') {
|
||||||
this.ignoreFlag = true;
|
this.ignoreFlag = true;
|
||||||
}
|
}
|
||||||
@ -307,6 +313,12 @@ export class Queue {
|
|||||||
const index = this._videoList.length + videoList.length - 1;
|
const index = this._videoList.length + videoList.length - 1;
|
||||||
|
|
||||||
if (videoList.length > 0) {
|
if (videoList.length > 0) {
|
||||||
|
this._videoList.push(
|
||||||
|
...videoList.map((it) => ({
|
||||||
|
...it,
|
||||||
|
ownerId: it.ownerId ?? this.owner?.id,
|
||||||
|
})),
|
||||||
|
);
|
||||||
this.broadcast({
|
this.broadcast({
|
||||||
// play
|
// play
|
||||||
type: 'ADD_SONGS',
|
type: 'ADD_SONGS',
|
||||||
@ -330,23 +342,30 @@ export class Queue {
|
|||||||
}
|
}
|
||||||
).items.length === 1
|
).items.length === 1
|
||||||
) {
|
) {
|
||||||
|
const videoList = mapQueueItem(
|
||||||
|
(it) =>
|
||||||
|
({
|
||||||
|
videoId: it!.videoId,
|
||||||
|
ownerId: this.owner!.id,
|
||||||
|
}) satisfies VideoData,
|
||||||
|
(
|
||||||
|
event.payload! as {
|
||||||
|
items: QueueItem[];
|
||||||
|
}
|
||||||
|
).items,
|
||||||
|
);
|
||||||
|
this._videoList.push(
|
||||||
|
...videoList.map((it) => ({
|
||||||
|
...it,
|
||||||
|
ownerId: it.ownerId ?? this.owner?.id,
|
||||||
|
})),
|
||||||
|
);
|
||||||
this.broadcast({
|
this.broadcast({
|
||||||
// add playlist
|
// add playlist
|
||||||
type: 'ADD_SONGS',
|
type: 'ADD_SONGS',
|
||||||
payload: {
|
payload: {
|
||||||
// index: (event.payload as any).index,
|
// index: (event.payload as any).index,
|
||||||
videoList: mapQueueItem(
|
videoList,
|
||||||
(it) =>
|
|
||||||
({
|
|
||||||
videoId: it!.videoId,
|
|
||||||
ownerId: this.owner!.id,
|
|
||||||
}) satisfies VideoData,
|
|
||||||
(
|
|
||||||
event.payload! as {
|
|
||||||
items: QueueItem[];
|
|
||||||
}
|
|
||||||
).items,
|
|
||||||
),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user