Make PKJS work (now successfully hitting Jellyfin API)
This commit is contained in:
@@ -12,7 +12,7 @@
|
|||||||
"name": "1-more-episode",
|
"name": "1-more-episode",
|
||||||
"pebble": {
|
"pebble": {
|
||||||
"displayName": "1 More Episode",
|
"displayName": "1 More Episode",
|
||||||
"enableMultiJS": false,
|
"enableMultiJS": true,
|
||||||
"messageKeys": [
|
"messageKeys": [
|
||||||
"JS_READY",
|
"JS_READY",
|
||||||
"SLEEP_TIMESTAMP",
|
"SLEEP_TIMESTAMP",
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
// declare pkjs statics
|
// declare pkjs statics
|
||||||
static bool s_js_ready;
|
static bool s_js_ready;
|
||||||
static bool s_js_pending;
|
|
||||||
|
|
||||||
// declare window statics
|
// declare window statics
|
||||||
static Window *s_main_window;
|
static Window *s_main_window;
|
||||||
@@ -34,8 +33,6 @@ static void send_to_pkjs() {
|
|||||||
text_layer_set_text(s_last_episode_layer, "outbox_send failure ");
|
text_layer_set_text(s_last_episode_layer, "outbox_send failure ");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
s_js_pending = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
||||||
@@ -43,7 +40,8 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
|||||||
if (ready_tuple) {
|
if (ready_tuple) {
|
||||||
s_js_ready = true;
|
s_js_ready = true;
|
||||||
}
|
}
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Received JS_READY");
|
APP_LOG(APP_LOG_LEVEL_INFO, "Received JS_READY, calling PKJS...");
|
||||||
|
send_to_pkjs();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void inbox_dropped_handler(AppMessageResult reason, void *context) {
|
static void inbox_dropped_handler(AppMessageResult reason, void *context) {
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ Pebble.addEventListener("ready", function () {
|
|||||||
|
|
||||||
Pebble.addEventListener("appmessage", function (dict) {
|
Pebble.addEventListener("appmessage", function (dict) {
|
||||||
if (dict.payload["API_HOST"]) {
|
if (dict.payload["API_HOST"]) {
|
||||||
console.log("WOAH BRO");
|
if (dict.payload["API_IS_PLEX"] == 1) {
|
||||||
if (dict.payload["API_IS_PLEX"] == true) {
|
|
||||||
callAPI(dict.payload["API_HOST"] + "/status/sessions/history/all", true, dict.payload["API_KEY"]);
|
callAPI(dict.payload["API_HOST"] + "/status/sessions/history/all", true, dict.payload["API_KEY"]);
|
||||||
} else {
|
} else {
|
||||||
callAPI(dict.payload["API_HOST"] + "/System/ActivityLog/Entries", false, dict.payload["API_KEY"]);
|
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) {
|
function callAPI(fullURL, isPlex, apiKey) {
|
||||||
let data = null;
|
console.log("callAPI URL:", fullURL, "isPlex:", isPlex);
|
||||||
|
|
||||||
let xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.withCredentials = true;
|
xhr.onreadystatechange = function () {
|
||||||
|
if (xhr.readyState === 4) {
|
||||||
xhr.addEventListener("readystatechange", function () {
|
console.log(xhr.responseText); // raw JSON string from API
|
||||||
if (this.readyState === this.DONE) {
|
|
||||||
console.log(this.responseText);
|
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
xhr.open("GET", fullURL);
|
xhr.open("GET", fullURL, true);
|
||||||
xhr.setRequestHeader("accept", "application/json");
|
xhr.setRequestHeader("Accept", "application/json");
|
||||||
if (isPlex == true) {
|
if (isPlex) {
|
||||||
xhr.setRequestHeader("X-Plex-Token", apiKey);
|
xhr.setRequestHeader("X-Plex-Token", apiKey);
|
||||||
} else {
|
} else {
|
||||||
xhr.setRequestHeader("Authorization", 'MediaBrowser Token="' + apiKey + '"');
|
xhr.setRequestHeader("Authorization", 'MediaBrowser Token="' + apiKey + '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
xhr.send(data);
|
xhr.send(null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user