add ratings, library change to web remote (#1285)
This commit is contained in:
parent
3ab6d3e56c
commit
8cf2ddf8dd
5 changed files with 246 additions and 13 deletions
|
@ -64,6 +64,15 @@ export class wsapi {
|
|||
electron.ipcMain.on('wsapi-returnvolumeMax', (_event: any, arg: any) => {
|
||||
this.returnmaxVolume(JSON.parse(arg));
|
||||
});
|
||||
electron.ipcMain.on('wsapi-libraryStatus', (_event: any, inLibrary: boolean, rating: number) => {
|
||||
this.returnLibraryStatus(inLibrary, rating);
|
||||
});
|
||||
electron.ipcMain.on('wsapi-rate', (_event: any, kind: string, id: string, rating: number) => {
|
||||
this.returnRatingStatus(kind, id, rating);
|
||||
});
|
||||
electron.ipcMain.on('wsapi-change-library', (_event: any, kind: string, id: string, shouldAdd: boolean) => {
|
||||
this.returnLibraryChange(kind, id, shouldAdd);
|
||||
});
|
||||
this.wss = new WebSocketServer({
|
||||
port: this.port,
|
||||
perMessageDeflate: {
|
||||
|
@ -242,6 +251,15 @@ export class wsapi {
|
|||
case "get-currentmediaitem":
|
||||
this._win.webContents.executeJavaScript(`wsapi.getPlaybackState()`);
|
||||
break;
|
||||
case "library-status":
|
||||
this._win.webContents.executeJavaScript(`wsapi.getLibraryStatus("${data.type}", "${data.id}")`);
|
||||
break;
|
||||
case "rating":
|
||||
this._win.webContents.executeJavaScript(`wsapi.rate("${data.type}", "${data.id}", ${data.rating})`);
|
||||
break;
|
||||
case "change-library":
|
||||
this._win.webContents.executeJavaScript(`wsapi.changeLibrary("${data.type}", "${data.id}", ${data.add})`);
|
||||
break;
|
||||
case "quit":
|
||||
electron.app.quit();
|
||||
break;
|
||||
|
@ -317,4 +335,35 @@ export class wsapi {
|
|||
client.send(JSON.stringify(response));
|
||||
});
|
||||
}
|
||||
|
||||
returnLibraryStatus(inLibrary: boolean, rating: number) {
|
||||
const response: standardResponse = {
|
||||
status: 0, data: {
|
||||
inLibrary, rating
|
||||
}, message: "OK", type: "libraryStatus"
|
||||
}
|
||||
this.clients.forEach(function each(client: any) {
|
||||
client.send(JSON.stringify(response));
|
||||
});
|
||||
}
|
||||
|
||||
returnRatingStatus(kind: string, id: string, rating: number) {
|
||||
const response: standardResponse = {
|
||||
status: 0, data: { kind, id, rating },
|
||||
message: "OK", type: "rate"
|
||||
};
|
||||
this.clients.forEach(function each(client: any) {
|
||||
client.send(JSON.stringify(response));
|
||||
});
|
||||
}
|
||||
|
||||
returnLibraryChange(kind: string, id: string, shouldAdd: boolean) {
|
||||
const response: standardResponse = {
|
||||
status: 0, data: { kind, id, add: shouldAdd },
|
||||
message: "OK", type: "change-library"
|
||||
};
|
||||
this.clients.forEach(function each(client: any) {
|
||||
client.send(JSON.stringify(response));
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue