Tutorio will POST each event to your URL as it happens. Leave events out to get all of them. The secret in the answer signs every delivery; it is shown once, here, and never again (not in the list either), so keep it. People's names are left out of what is sent unless you ask for them with include_names: without it each participant comes with their id, your external_id for them, their role and their times, and a recording comes without its list of people and without its summary (which is written about the lesson and can name a child): the event carries "summary_available": true instead, and GET /recordings/{id} has the summary and the transcript.
const crypto = require('crypto');
// rawBody is the request body exactly as received, before JSON.parse.
function verify(secret, header, rawBody) {
const parts = Object.fromEntries(header.split(',').map((p) => p.trim().split('=')));
const want = crypto.createHmac('sha256', secret)
.update(parts.t + '.' + rawBody)
.digest('hex');
const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300;
return fresh && parts.v1.length === want.length &&
crypto.timingSafeEqual(Buffer.from(parts.v1), Buffer.from(want));
}
verify.py
import hashlib, hmac, time
# raw_body is the request body as bytes, exactly as received.
def verify(secret: str, header: str, raw_body: bytes) -> bool:
parts = dict(p.strip().split("=", 1) for p in header.split(","))
signed = parts["t"].encode() + b"." + raw_body
want = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
fresh = abs(time.time() - int(parts["t"])) < 300
return fresh and hmac.compare_digest(want, parts.get("v1", ""))
Make an embed link. Send "embed": true when you create a sign-in link and use its url as the frame's src. A participant needs an external_id. An embed link only works in a frame: it signs the person in to that one room, never to their Tutorio account.
// The lesson page in your product, rendered on your server:
app.get('/lessons/:id', async (req, res) => {
const lesson = await db.lessons.find(req.params.id);
const user = req.user;
const board = await tutorio('POST', '/boards', {
name: lesson.title,
external_id: 'lesson-' + lesson.id,
});
// "embed": true makes a link that only works as the src of a frame.
// Make a fresh one each time the page is rendered.
const link = await tutorio('POST', '/boards/' + board.code + '/links', {
role: user.isTutor ? 'host' : 'participant',
name: user.name,
external_id: 'user-' + user.id,
embed: true,
});
res.render('lesson', { roomSrc: link.url, roomTab: link.fallback_url });
});
lesson.html
<iframe id="room"
src="{{ roomSrc }}"
allow="camera; microphone; display-capture; fullscreen; clipboard-write; autoplay"
allowfullscreen
style="width:100%;height:720px;border:0"
title="Whiteboard"></iframe>
<a href="{{ roomTab }}" target="_blank" rel="noopener">Open in a new tab</a>
<script>
window.addEventListener('message', function (e) {
if (e.origin !== 'https://tutorio.app') return;
if (e.source !== document.getElementById('room').contentWindow) return;
switch (e.data && e.data.type) {
case 'tutorio:ready': break; // the room has loaded
case 'tutorio:joined': break; // e.data.role is "host" or "participant"
case 'tutorio:left': break; // they left the room
case 'tutorio:ended': break; // the host ended the session
case 'tutorio:error': break; // e.data.code says why; render the page again for a fresh link
}
});
</script>