From d437cde6dae42b6a4dc668e5abc5437c4cb19c39 Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Mon, 28 Sep 2020 11:04:10 +0200 Subject: [PATCH] Default files for webcam and attempt for error log --- dist/static/assets/webcam.js | 75 ++++++++++++++++++++- server/domain-objects/createDefaultFiles.js | 18 ++--- 2 files changed, 84 insertions(+), 9 deletions(-) diff --git a/dist/static/assets/webcam.js b/dist/static/assets/webcam.js index 5a3c7008..3e95a0ca 100644 --- a/dist/static/assets/webcam.js +++ b/dist/static/assets/webcam.js @@ -397,4 +397,77 @@ function transformPoint(p, cx, cy, angle) { x: px * cos(-angle) - py * sin(-angle), y: px * sin(-angle) + py * cos(-angle) } -} \ No newline at end of file +} + + + +// error handling from consoleUtils.js::hijackConsoleErrorsScript +function getScriptOff(line) { + var offs = 0; + var l = 0; + var file = ''; + for (var i=0; i l) { + l = n; + file = offs[i][1]; + } + } + return [line - l, file]; +} +// catch reference errors, via http://stackoverflow.com/a/12747364/2994108 +window.onerror = function (msg, url, lineNumber, columnNo, error) { + var string = msg.toLowerCase(); + var substring = "script error"; + var data = {}; + // if (url.match(${EXTERNAL_LINK_REGEX}) !== null && error.stack){ + // var errorNum = error.stack.split('about:srcdoc:')[1].split(':')[0]; + // var fileInfo = getScriptOff(errorNum); + // data = msg + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')'; + // } else { + var fileInfo = getScriptOff(lineNumber); + data = msg + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')'; + // } + window.parent.postMessage([{ + log: [{ + method: 'error', + data: [data], + id: Date.now().toString() + }], + source: fileInfo[1] + }], '*'); + return false; +}; +// catch rejected promises +window.onunhandledrejection = function (event) { +if (event.reason && event.reason.message && event.reason.stack){ + var errorNum = event.reason.stack.split('about:srcdoc:')[1].split(':')[0]; + var fileInfo = getScriptOff(errorNum); + var data = event.reason.message + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')'; + window.parent.postMessage([{ + log: [{ + method: 'error', + data: [data], + id: Date.now().toString() + }], + source: fileInfo[1] + }], '*'); +} +}; + +(function(){ + const oldLog = console.log; + console.log = function () { + const err = new Error(); + const logSrc = err.stack.split("\n")[1]; + window.parent.postMessage([{ + log: [{ + method: 'log', + data: arguments, + id: Date.now().toString() + }], + source: logSrc + }], '*'); + oldLog.apply(console, arguments); + }; +})(); \ No newline at end of file diff --git a/server/domain-objects/createDefaultFiles.js b/server/domain-objects/createDefaultFiles.js index b901caaf..9f2fb78e 100644 --- a/server/domain-objects/createDefaultFiles.js +++ b/server/domain-objects/createDefaultFiles.js @@ -1,17 +1,19 @@ -const defaultSketch = `function setup() { - createCanvas(400, 400); -} +const defaultSketch = `// liveUpdate -function draw() { - background(220); -}`; +function drawMask(detection) { + stroke('red'); + strokeWeight(2); + rect(detection.box.x, detection.box.y, detection.box.width, detection.box.height) +} +`; const defaultHTML = ` - - + + +