Add websocket playback control for next and previous

This commit is contained in:
Manuel 2023-04-02 20:43:12 +02:00
parent 65d401fdbb
commit 831e03a77f
3 changed files with 21 additions and 8 deletions

View File

@ -113,9 +113,6 @@ export class JellyfinWebSocketService implements OnModuleDestroy {
msg.Data as SessionApiSendPlaystateCommandRequest; msg.Data as SessionApiSendPlaystateCommandRequest;
this.handleSendPlaystateCommandRequest(sendPlaystateCommandRequest); this.handleSendPlaystateCommandRequest(sendPlaystateCommandRequest);
break; break;
case SessionMessageType[SessionMessageType.UserDataChanged]:
this.logger.debug("Received update for user session data");
break;
default: default:
this.logger.warn( this.logger.warn(
`Received a package from the socket of unknown type: ${msg.MessageType}`, `Received a package from the socket of unknown type: ${msg.MessageType}`,
@ -129,13 +126,19 @@ export class JellyfinWebSocketService implements OnModuleDestroy {
) { ) {
switch (request.Command) { switch (request.Command) {
case PlaystateCommand.PlayPause: case PlaystateCommand.PlayPause:
this.eventEmitter.emitAsync('internal.voice.controls.togglePause'); this.eventEmitter.emit('internal.voice.controls.togglePause');
break; break;
case PlaystateCommand.Pause: case PlaystateCommand.Pause:
this.eventEmitter.emitAsync('internal.voice.controls.pause'); this.eventEmitter.emit('internal.voice.controls.pause');
break; break;
case PlaystateCommand.Stop: case PlaystateCommand.Stop:
this.eventEmitter.emitAsync('internal.voice.controls.stop'); this.eventEmitter.emit('internal.voice.controls.stop');
break;
case PlaystateCommand.NextTrack:
this.eventEmitter.emit('internal.audio.track.next');
break;
case PlaystateCommand.PreviousTrack:
this.eventEmitter.emit('internal.audio.track.previous');
break; break;
default: default:
this.logger.warn( this.logger.warn(

View File

@ -1,4 +1,4 @@
import { EventEmitter2 } from '@nestjs/event-emitter'; import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';
import { Track } from './Track'; import { Track } from './Track';

View File

@ -1,5 +1,5 @@
import { Injectable, Logger } from '@nestjs/common'; import { Injectable, Logger } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter'; import { EventEmitter2, OnEvent } from '@nestjs/event-emitter';
import { Playlist } from '../models/shared/Playlist'; import { Playlist } from '../models/shared/Playlist';
@ -18,4 +18,14 @@ export class PlaybackService {
this.playlist = new Playlist(this.eventEmitter); this.playlist = new Playlist(this.eventEmitter);
return this.playlist; return this.playlist;
} }
@OnEvent('internal.audio.track.previous')
private handlePreviousTrackEvent() {
this.getPlaylistOrDefault().setPreviousTrackAsActiveTrack();
}
@OnEvent('internal.audio.track.next')
private handleNextTrackEvent() {
this.getPlaylistOrDefault().setNextTrackAsActiveTrack();
}
} }