-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.ts
36 lines (32 loc) · 944 Bytes
/
main.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* A custom extension THAT ONLY WORKS in exported slides.
* Please read the README.md file to setup this project with
* your game.
*/
namespace webcam {
const CHANNEL = "webcam"
const EVENT_ID = 4567
const FRAME_EVENT = 1
let initialized = false;
export let currentFrame: Image = undefined;
/**
* Registers a handler when an image is onReceived
* from the webcam
*/
export function onFrameReceived(handler: () => void) {
init()
control.onEvent(EVENT_ID, FRAME_EVENT, function() {
if (handler)
handler();
})
}
function init() {
if (initialized) return;
initialized = true;
control.simmessages.onReceived(CHANNEL, function(msg: Buffer) {
// buffer is the encoded image
currentFrame = image.ofBuffer(msg);
control.raiseEvent(EVENT_ID, FRAME_EVENT)
})
}
}