Skip to content

Commit

Permalink
Merge pull request #55 from ty-porter/dev
Browse files Browse the repository at this point in the history
Release v0.9.1
  • Loading branch information
ty-porter authored Jun 21, 2023
2 parents b577ad4 + 7fd9895 commit 94b180f
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
24 changes: 24 additions & 0 deletions .github/require_release_branch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Require release branch

on:
pull_request:

jobs:
check_branch:
runs-on: ubuntu-latest
steps:
- name: Check branch
if: github.base_ref == 'master' && github.head_ref != 'dev'
run: |
echo "ERROR: You can only merge to master from dev. Contributors should point their PRs to the dev branch."
exit 1
- uses: actions/checkout@v3
if: github.base_ref == 'master'
with:
fetch-depth: 0

- name: Check version.py
if: github.base_ref == 'master'
run: |
git diff --name-only origin/master | grep -q RGBMatrixEmulator/version.py || (echo "Need to change version for pushes to master!" && exit 1)
60 changes: 20 additions & 40 deletions RGBMatrixEmulator/adapters/browser_adapter/static/assets/client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
function init() {
const WS_ERROR_TIMEOUT = 6 * 1000;
const WS_MAX_RETRY = 10;
const FPS_DEFAULT = 24;
const WS_RETRY_DELAY = 2000;
const FPS_DEFAULT = 24;

let img = document.getElementById("liveImg");
let fpsText = document.getElementById("fps");
Expand All @@ -15,38 +14,11 @@ function init() {
let requestTimeSmoothing = 0.2; // larger=more smoothing
let targetTime = 1000 / fpsTarget;

let retryCount = 0;
let socket = generateSocket();

function requestImage() {
function requestImage() {
requestStartTime = performance.now();

waitForSocketReady(socket, function () {
socket.send('more');
});
}

function waitForSocketReady(socket, callback) {
if (socketReady(socket)) {
retryCount = 0;
return callback();
}
else if (retryCount < WS_MAX_RETRY) {
let retriesRemaining = WS_MAX_RETRY - retryCount;
let retryText = retriesRemaining == 1 ? "retry" : "retries"
console.error(`Failed to fetch next frame. Retrying in ${WS_ERROR_TIMEOUT / 1000}s... (${retriesRemaining} ${retryText} remaining)`);
retryCount += 1;

setTimeout(function () {
waitForSocketReady(socket, callback);
}, WS_ERROR_TIMEOUT);
} else {
console.error(`Max retries exhausted. Confirm that the server is still running on ${location.host}.`);
}
}

function socketReady(socket) {
return socket.readyState == socket.OPEN;
socket.send('more');
}

function generateSocket() {
Expand All @@ -55,7 +27,7 @@ function init() {
if (path.endsWith("index.html")) {
path = path.substring(0, path.length - "index.html".length);
}

if(!path.endsWith("/")) {
path = path + "/";
}
Expand All @@ -64,25 +36,33 @@ function init() {
let ws = new WebSocket(wsProtocol + location.host + path + "websocket");

ws.binaryType = 'arraybuffer';

ws.onopen = function() {
console.log("RGBME WebSocket connection established!");
startTime = performance.now();
requestImage();
};

ws.onclose = function() {
// Handle retries via requestImage call
requestImage();
// Handle retries by recreating the connection to websocket.
console.warn(`RGBME WebSocket connection lost. Retrying in ${WS_RETRY_DELAY / 1000}s.`)
setTimeout(function() {
// We generate socket with a timeout to make sure server has time to recover.
socket = generateSocket();
}, WS_RETRY_DELAY);
}

ws.onerror = function() {
ws.close();
}

ws.onmessage = function(evt) {
let arrayBuffer = evt.data;
let blob = new Blob([new Uint8Array(arrayBuffer)], {type: "image/jpeg"});
let old_img = img.src.slice()
img.src = window.URL.createObjectURL(blob);
window.URL.revokeObjectURL(old_img);

let endTime = performance.now();
let currentTime = endTime - startTime;
// smooth with moving average
Expand All @@ -93,12 +73,12 @@ function init() {
if (fpsText) {
fpsText.textContent = fps;
}

let currentRequestTime = performance.now() - requestStartTime;
// smooth with moving average
requestTime = (requestTime * requestTimeSmoothing) + (currentRequestTime * (1.0 - requestTimeSmoothing));
let timeout = Math.max(0, targetTime - requestTime);

setTimeout(requestImage, timeout);
};

Expand Down
2 changes: 1 addition & 1 deletion RGBMatrixEmulator/version.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python

# package version
__version__ = '0.9.0'
__version__ = '0.9.1'
"""Installed version of RGBMatrixEmulator."""

0 comments on commit 94b180f

Please sign in to comment.