mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
added track
likes logic
This commit is contained in:
parent
d9b6d212a1
commit
c9842f9f1e
@ -12,6 +12,7 @@ export const DefaultContextValues = {
|
|||||||
bpm: 0,
|
bpm: 0,
|
||||||
syncMode: false,
|
syncMode: false,
|
||||||
syncModeLocked: false,
|
syncModeLocked: false,
|
||||||
|
liked: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const Context = React.createContext(DefaultContextValues)
|
export const Context = React.createContext(DefaultContextValues)
|
||||||
@ -29,6 +30,7 @@ export class WithPlayerContext extends React.Component {
|
|||||||
bpm: app.cores.player.getState("trackBPM") ?? 0,
|
bpm: app.cores.player.getState("trackBPM") ?? 0,
|
||||||
syncMode: app.cores.player.getState("syncModeLocked"),
|
syncMode: app.cores.player.getState("syncModeLocked"),
|
||||||
syncModeLocked: app.cores.player.getState("syncMode"),
|
syncModeLocked: app.cores.player.getState("syncMode"),
|
||||||
|
liked: app.cores.player.getState("liked"),
|
||||||
}
|
}
|
||||||
|
|
||||||
events = {
|
events = {
|
||||||
@ -64,6 +66,9 @@ export class WithPlayerContext extends React.Component {
|
|||||||
},
|
},
|
||||||
"player.coverColorAnalysis.update": (data) => {
|
"player.coverColorAnalysis.update": (data) => {
|
||||||
this.setState({ coverColorAnalysis: data })
|
this.setState({ coverColorAnalysis: data })
|
||||||
|
},
|
||||||
|
"player.toggle.like": (data) => {
|
||||||
|
this.setState({ liked: data })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -158,9 +158,12 @@ class MediaSession {
|
|||||||
// TODO: Check if source playing is a stream. Also handle if it's a stream resuming after a pause will seek to the last position
|
// TODO: Check if source playing is a stream. Also handle if it's a stream resuming after a pause will seek to the last position
|
||||||
export default class Player extends Core {
|
export default class Player extends Core {
|
||||||
static dependencies = [
|
static dependencies = [
|
||||||
|
"api",
|
||||||
"settings"
|
"settings"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
static websocketListen = "music"
|
||||||
|
|
||||||
static refName = "player"
|
static refName = "player"
|
||||||
|
|
||||||
static namespace = "player"
|
static namespace = "player"
|
||||||
@ -205,6 +208,7 @@ export default class Player extends Core {
|
|||||||
syncMode: false,
|
syncMode: false,
|
||||||
syncModeLocked: false,
|
syncModeLocked: false,
|
||||||
startingNew: false,
|
startingNew: false,
|
||||||
|
liked: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
public = {
|
public = {
|
||||||
@ -300,6 +304,7 @@ export default class Player extends Core {
|
|||||||
|
|
||||||
return this.state
|
return this.state
|
||||||
}.bind(this),
|
}.bind(this),
|
||||||
|
toggleCurrentTrackLike: this.toggleCurrentTrackLike.bind(this),
|
||||||
seek: this.seek.bind(this),
|
seek: this.seek.bind(this),
|
||||||
duration: this.duration.bind(this),
|
duration: this.duration.bind(this),
|
||||||
velocity: this.velocity.bind(this),
|
velocity: this.velocity.bind(this),
|
||||||
@ -309,6 +314,16 @@ export default class Player extends Core {
|
|||||||
setSampleRate: this.setSampleRate.bind(this),
|
setSampleRate: this.setSampleRate.bind(this),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wsEvents = {
|
||||||
|
"music:self:track:toggle:like": (data) => {
|
||||||
|
const to = data.action === "liked"
|
||||||
|
|
||||||
|
if (this.state.liked !== to) {
|
||||||
|
this.state.liked = to
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async initializeAudioProcessors() {
|
async initializeAudioProcessors() {
|
||||||
if (this.audioProcessors.length > 0) {
|
if (this.audioProcessors.length > 0) {
|
||||||
console.log("Destroying audio processors")
|
console.log("Destroying audio processors")
|
||||||
@ -480,9 +495,15 @@ export default class Player extends Core {
|
|||||||
}
|
}
|
||||||
case "syncModeLocked": {
|
case "syncModeLocked": {
|
||||||
app.eventBus.emit("player.syncModeLocked.update", change.object.syncModeLocked)
|
app.eventBus.emit("player.syncModeLocked.update", change.object.syncModeLocked)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
case "syncMode": {
|
case "syncMode": {
|
||||||
app.eventBus.emit("player.syncMode.update", change.object.syncMode)
|
app.eventBus.emit("player.syncMode.update", change.object.syncMode)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
case "liked": {
|
||||||
|
app.eventBus.emit("player.toggle.like", change.object.liked)
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -497,6 +518,10 @@ export default class Player extends Core {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async initializeBeforeRuntimeInitialize() {
|
async initializeBeforeRuntimeInitialize() {
|
||||||
|
for (const [eventName, eventHandler] of Object.entries(this.wsEvents)) {
|
||||||
|
app.cores.api.listenEvent(eventName, eventHandler, Player.websocketListen)
|
||||||
|
}
|
||||||
|
|
||||||
if (app.isMobile) {
|
if (app.isMobile) {
|
||||||
this.state.audioVolume = 1
|
this.state.audioVolume = 1
|
||||||
}
|
}
|
||||||
@ -506,6 +531,23 @@ export default class Player extends Core {
|
|||||||
// UI Methods
|
// UI Methods
|
||||||
//
|
//
|
||||||
|
|
||||||
|
async toggleCurrentTrackLike() {
|
||||||
|
if (!this.currentAudioInstance) {
|
||||||
|
console.error("No track playing")
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
const currentId = this.currentAudioInstance.manifest._id
|
||||||
|
|
||||||
|
const result = await PlaylistModel.toggleTrackLike(currentId).catch((err) => {
|
||||||
|
return null
|
||||||
|
})
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
this.state.liked = result.action === "liked"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
attachPlayerComponent() {
|
attachPlayerComponent() {
|
||||||
if (this.currentDomWindow) {
|
if (this.currentDomWindow) {
|
||||||
console.warn("EmbbededMediaPlayer already attached")
|
console.warn("EmbbededMediaPlayer already attached")
|
||||||
@ -834,6 +876,8 @@ export default class Player extends Core {
|
|||||||
|
|
||||||
this.state.currentAudioManifest = instance.manifest
|
this.state.currentAudioManifest = instance.manifest
|
||||||
|
|
||||||
|
this.state.liked = instance.manifest.liked
|
||||||
|
|
||||||
// set time to 0
|
// set time to 0
|
||||||
this.currentAudioInstance.audioElement.currentTime = 0
|
this.currentAudioInstance.audioElement.currentTime = 0
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user