From 18b14177d26f1553d6df886c69767176bafaf23a Mon Sep 17 00:00:00 2001 From: apoc Date: Wed, 17 Feb 2021 11:59:25 +0100 Subject: [PATCH] working bigbluebutton display --- chaospott_mumble.js | 79 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 68 insertions(+), 11 deletions(-) diff --git a/chaospott_mumble.js b/chaospott_mumble.js index 4d7594d..537259c 100644 --- a/chaospott_mumble.js +++ b/chaospott_mumble.js @@ -3,10 +3,12 @@ // icon-color: deep-green; icon-glyph: power-off; const mumbleApiUrl = "https://apoc.uber.space/chaospott_mumble.json"; const spaceApiUrl = "https://status.chaospott.de/status.json"; +const bbbApiUrl = "https://unterricht.roschow.de/chaospott_bbb.json"; const logoUrl = "https://chaospott.de/images/logo.png"; const logoLocalFilename = "chaospott_logo.png"; const mumbleLocalFilename = "chaospott_mumble.json"; const spaceLocalFilename = "chaospott_space.json"; +const bbbLocalFilename = "chaospott_bbb.json"; const title = "Chaospott"; const subTitle = "Essen"; @@ -42,6 +44,7 @@ async function createWidget(){ try { var [mumbleStatus, mumbleFresh] = await getJSONandCache(mumbleLocalFilename, mumbleApiUrl); var [spaceStatus, spaceFresh] = await getJSONandCache(spaceLocalFilename, spaceApiUrl); + var [bbbStatus, bbbFresh] = await getJSONandCache(bbbLocalFilename, bbbApiUrl); } catch(err) { const errorList = new ListWidget(); errorList.addText("Please enable internet for initial execution."); @@ -72,10 +75,23 @@ async function createWidget(){ colorBorderLonely = colorLonelyStale; } + if (bbbFresh){ + colorBBBOpen = colorOpenFresh; + colorBBBClosed = colorClosedFresh; + colorBBBLonely = colorLonelyFresh; + } else { + colorBBBOpen = colorOpenStale; + colorBBBClosed = colorClosedStale; + colorBBBLonely = colorLonelyStale; + colorBorderOpen = colorOpenStale; + colorBorderClosed = colorClosedStale; + colorBorderLonely = colorLonelyStale; + } + if (spaceStatus.state.open){ widget.backgroundColor = colorBorderOpen; - } else { - switch(mumbleStatus.connected_users){ + } else { + switch(mumbleStatus.connected_users + bbbStatus.participantCount){ case 0: widget.backgroundColor = colorBorderClosed; break; @@ -89,11 +105,11 @@ async function createWidget(){ widget.setPadding(0, 5, 0, 5); canvasStack = widget.addStack(); - canvasStack.setPadding(5, 15, 5, 15); + canvasStack.setPadding(8, 15, 8, 15); canvasStack.cornerRadius = 15; canvasStack.layoutVertically(); canvasStack.backgroundColor = Color.dynamic(Color.white(), Color.black()); - + const headerStack = canvasStack.addStack(); const titleStack = headerStack.addStack(); @@ -105,11 +121,11 @@ async function createWidget(){ subTitleText.font = Font.mediumSystemFont(10); headerStack.addSpacer(5); - + let logo = await getCachedImage(logoLocalFilename, logoUrl); const logoImage = headerStack.addImage(logo); logoImage.imageSize = new Size(30, 30); - + canvasStack.addSpacer(5); const middleRow = canvasStack.addStack(); @@ -124,23 +140,27 @@ async function createWidget(){ spaceLastUpdateLabel.font = Font.mediumSystemFont(6); spaceLastUpdateLabel.applyRelativeStyle(); + + // + const bottomRow = canvasStack.addStack(); bottomRow.useDefaultPadding(); bottomRow.centerAlignContent(); const mumbleLabelStack = bottomRow.addStack(); mumbleLabelStack.layoutVertically(); - const labelMumble = mumbleLabelStack.addText("Mumble"); - labelMumble.font = Font.regularSystemFont(14); + const labelMumble = mumbleLabelStack.addText("M"); + labelMumble.font = Font.regularSystemFont(12); - let mumbleLastUpdate = new Date(mumbleStatus.last_update * 1000 ); + let mumbleLastUpdate = new Date(mumbleStatus.last_update * 1000); const labelMumbleUpdated = mumbleLabelStack.addDate(mumbleLastUpdate); labelMumbleUpdated.font = Font.mediumSystemFont(6); labelMumbleUpdated.applyTimeStyle(); - bottomRow.addSpacer(29); + bottomRow.addSpacer(3); + const mumbleValueStack = bottomRow.addStack(); const labelMumbleUser = mumbleValueStack.addText(mumbleStatus.connected_users.toString(10)); - labelMumbleUser.font = Font.boldSystemFont(30); + labelMumbleUser.font = Font.boldSystemFont(23); switch(mumbleStatus.connected_users){ case 0: labelMumbleUser.textColor = colorMumbleClosed; @@ -152,6 +172,43 @@ async function createWidget(){ labelMumbleUser.textColor = colorMumbleOpen; } +bottomRow.addSpacer(10); + + const bbbLabelStack = bottomRow.addStack(); + bbbLabelStack.layoutVertically(); + const labelBBB = bbbLabelStack.addText("BBB"); + labelBBB.font = Font.regularSystemFont(12); + + let bbbLastUpdate = new Date(bbbStatus.startTime); + let labelBBBUpdated; + if(bbbStatus.active){ + labelBBBUpdated = bbbLabelStack.addDate(bbbLastUpdate); + } else { + labelBBBUpdated = bbbLabelStack.addTexte("---"); + } + labelBBBUpdated.font = Font.mediumSystemFont(6); + labelBBBUpdated.applyTimeStyle(); + +bottomRow.addSpacer(3); + + const bbbValueStack = bottomRow.addStack(); + const labelBBBUser = bbbValueStack.addText(bbbStatus.participantCount.toString(10)); + labelBBBUser.font = Font.boldSystemFont(23); + switch(bbbStatus.participantCount){ + case 0: + labelBBBUser.textColor = colorBBBClosed; + break; + case 1: + labelBBBUser.textColor = colorBBBLonely; + break; + default: + labelBBBUser.textColor = colorBBBOpen; + } + + + // + + canvasStack.addSpacer(4) dateStack = canvasStack.addStack();