Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEPRECATED] Feature: Adds integration of topik/youtube-music-obs-widget as plugin #1120

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions plugins/obs-widget/back.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const {ipcMain} = require("electron");
const http = require("http");
const registerCallback = require("../../providers/song-info");

let currentSongInfo;
const data = {
player: {
hasSong: false,
isPaused: true,
seekbarCurrentPosition: 0,
},
track: {
author: [],
title: "",
album: "",
cover: "",
duration: 0,
}
};

/** @param {Electron.BrowserWindow} win */
module.exports = async (win) => {
const requestListener = function (req, res) {
if(req.url !== '/query'){
res.writeHead(404);
res.end("404 Not found!");
}
res.setHeader("Access-Control-Allow-Origin", "*");
res.writeHead(200);
if (currentSongInfo !== undefined && !currentSongInfo.title && !currentSongInfo.artist) {
res.end(JSON.stringify({}));
return;
}
Object.assign(data, {
player: {
hasSong: true,
isPaused: currentSongInfo.isPaused,
seekbarCurrentPosition: currentSongInfo.elapsedSeconds
},
track: {
author: [currentSongInfo.artist],
title: currentSongInfo.title,
album: currentSongInfo.album,
cover: currentSongInfo.cover,
duration: currentSongInfo.duration
}
});
res.end(JSON.stringify(data));
};
const server = http.createServer(requestListener);
server.listen(9863, "localhost", () => {
});
ipcMain.on('apiLoaded', () => win.webContents.send('setupTimeChangedListener'));
ipcMain.on('timeChanged', async (_, t) => {
if (!currentSongInfo.title || currentSongInfo.isPaused) return;
currentSongInfo.elapsedSeconds = t;
});

registerCallback((songInfo) => {
currentSongInfo = songInfo;
});
};