@@ -344,6 +344,78 @@ export class WatchRoomServer {
344344 } ) ;
345345 } ) ;
346346
347+ socket . on ( 'music:change' , ( state ) => {
348+ const roomInfo = this . socketToRoom . get ( socket . id ) ;
349+ if ( ! roomInfo || ! roomInfo . isOwner ) return ;
350+
351+ const room = this . rooms . get ( roomInfo . roomId ) ;
352+ if ( room ?. roomType === 'music' ) {
353+ room . currentState = state ;
354+ this . rooms . set ( roomInfo . roomId , room ) ;
355+ socket . to ( roomInfo . roomId ) . emit ( 'music:change' , state ) ;
356+ }
357+ } ) ;
358+
359+ socket . on ( 'music:update' , ( state ) => {
360+ const roomInfo = this . socketToRoom . get ( socket . id ) ;
361+ if ( ! roomInfo || ! roomInfo . isOwner ) return ;
362+
363+ const room = this . rooms . get ( roomInfo . roomId ) ;
364+ if ( room ?. roomType === 'music' ) {
365+ room . currentState = state ;
366+ this . rooms . set ( roomInfo . roomId , room ) ;
367+ socket . to ( roomInfo . roomId ) . emit ( 'music:update' , state ) ;
368+ }
369+ } ) ;
370+
371+ socket . on ( 'music:queue' , ( state ) => {
372+ const roomInfo = this . socketToRoom . get ( socket . id ) ;
373+ if ( ! roomInfo || ! roomInfo . isOwner ) return ;
374+
375+ const room = this . rooms . get ( roomInfo . roomId ) ;
376+ if ( room ?. roomType === 'music' ) {
377+ room . currentState = state ;
378+ this . rooms . set ( roomInfo . roomId , room ) ;
379+ socket . to ( roomInfo . roomId ) . emit ( 'music:queue' , state ) ;
380+ }
381+ } ) ;
382+
383+ socket . on ( 'music:play' , ( state ) => {
384+ const roomInfo = this . socketToRoom . get ( socket . id ) ;
385+ if ( ! roomInfo || ! roomInfo . isOwner ) return ;
386+
387+ const room = this . rooms . get ( roomInfo . roomId ) ;
388+ if ( room ?. roomType === 'music' ) {
389+ room . currentState = state ;
390+ this . rooms . set ( roomInfo . roomId , room ) ;
391+ socket . to ( roomInfo . roomId ) . emit ( 'music:play' , state ) ;
392+ }
393+ } ) ;
394+
395+ socket . on ( 'music:pause' , ( state ) => {
396+ const roomInfo = this . socketToRoom . get ( socket . id ) ;
397+ if ( ! roomInfo || ! roomInfo . isOwner ) return ;
398+
399+ const room = this . rooms . get ( roomInfo . roomId ) ;
400+ if ( room ?. roomType === 'music' ) {
401+ room . currentState = state ;
402+ this . rooms . set ( roomInfo . roomId , room ) ;
403+ socket . to ( roomInfo . roomId ) . emit ( 'music:pause' , state ) ;
404+ }
405+ } ) ;
406+
407+ socket . on ( 'music:seek' , ( state ) => {
408+ const roomInfo = this . socketToRoom . get ( socket . id ) ;
409+ if ( ! roomInfo || ! roomInfo . isOwner ) return ;
410+
411+ const room = this . rooms . get ( roomInfo . roomId ) ;
412+ if ( room ?. roomType === 'music' ) {
413+ room . currentState = state ;
414+ this . rooms . set ( roomInfo . roomId , room ) ;
415+ socket . to ( roomInfo . roomId ) . emit ( 'music:seek' , state ) ;
416+ }
417+ } ) ;
418+
347419 // 聊天消息
348420 socket . on ( 'chat:message' , ( data ) => {
349421 const roomInfo = this . socketToRoom . get ( socket . id ) ;
0 commit comments