Make PKJS work (now successfully hitting Jellyfin API)

This commit is contained in:
2026-04-08 22:54:16 -04:00
parent 72f2bf23d8
commit 4b74403eb2
3 changed files with 14 additions and 19 deletions

View File

@@ -4,8 +4,7 @@ Pebble.addEventListener("ready", function () {
Pebble.addEventListener("appmessage", function (dict) {
if (dict.payload["API_HOST"]) {
console.log("WOAH BRO");
if (dict.payload["API_IS_PLEX"] == true) {
if (dict.payload["API_IS_PLEX"] == 1) {
callAPI(dict.payload["API_HOST"] + "/status/sessions/history/all", true, dict.payload["API_KEY"]);
} else {
callAPI(dict.payload["API_HOST"] + "/System/ActivityLog/Entries", false, dict.payload["API_KEY"]);
@@ -14,24 +13,22 @@ Pebble.addEventListener("appmessage", function (dict) {
});
function callAPI(fullURL, isPlex, apiKey) {
let data = null;
console.log("callAPI URL:", fullURL, "isPlex:", isPlex);
let xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
console.log(xhr.responseText); // raw JSON string from API
}
});
};
xhr.open("GET", fullURL);
xhr.setRequestHeader("accept", "application/json");
if (isPlex == true) {
xhr.open("GET", fullURL, true);
xhr.setRequestHeader("Accept", "application/json");
if (isPlex) {
xhr.setRequestHeader("X-Plex-Token", apiKey);
} else {
xhr.setRequestHeader("Authorization", 'MediaBrowser Token="' + apiKey + '"');
}
xhr.send(data);
xhr.send(null);
}