웹훅
방송 시작·종료, 다시보기 준비 같은 일이 생기면 귀사 서버로 알려 드립니다.
받는 방법
- 콘솔 → 개발자 → 웹훅 또는 POST /webhooks로 받을 주소와 이벤트를 정합니다. 주소는 공개된 https 주소여야 합니다.
- 만들 때 보이는 비밀값을 보관합니다. 서명 확인에 씁니다.
- 요청은 POST이고 본문은 JSON입니다. 5초 안에 2xx로 응답하면 성공입니다.
- 실패하면 1분, 5분, 30분, 2시간, 6시간 뒤에 다시 보냅니다. 보낸 기록은 콘솔의 전송 기록에서 볼 수 있고 다시 보낼 수 있습니다.
- 같은 이벤트가 두 번 올 수 있습니다. 본문의 id로 중복을 걸러 주세요.
| 헤더 | 값 |
|---|---|
X-Event | 이벤트 이름 |
X-Delivery-Id | 전송 건의 식별자. 본문의 id와 같습니다 |
X-Signature | t=<unix 초>,v1=<서명> |
{
"id": "dlv_…",
"event": "stream.started",
"createdAt": 1795427463,
"data": { "channelId": "ch_…", "externalId": "bj-1001", "startedAt": 1795427460 }
}API로 관리하기
콘솔 대신 API로도 웹훅을 만들고 지울 수 있습니다. 전체 권한 키가 필요합니다.
GET/webhooks
웹훅 목록. 비밀값은 들어 있지 않습니다.
{ "data": [ { "id": "wh_jwm0wbdfryiyoxk3", "url": "https://example.com/hook",
"events": ["stream.started", "stream.ended"], "active": true, "createdAt": 1795431467 } ] }POST/webhooks
웹훅 만들기
본문
| 이름 | 형식 | 필수 | 설명 |
|---|---|---|---|
url | 문자열 | 필수 | 이벤트를 받을 공개 https 주소. |
events | 배열 | 필수 | 받을 이벤트 이름. 아래 이벤트 종류 표의 값 중에서 하나 이상. |
{ "url": "https://example.com/hook", "events": ["stream.started", "stream.ended", "recording.ready"] }{ "id": "wh_jwm0wbdfryiyoxk3", "url": "https://example.com/hook", "events": [ … ], "active": true,
"createdAt": 1795431467, "secret": "whsec_…" }- secret은 이 응답에서 한 번만 볼 수 있습니다. 잃어버리면 지우고 다시 만듭니다.
- 웹훅은 10개까지 둘 수 있습니다.
DELETE/webhooks/{id}
웹훅 삭제
{ "deleted": true }POST/webhooks/{id}/test
시험 이벤트(webhook.test)를 바로 보내고 결과를 돌려줍니다.
{ "id": "dlv_fcxcdxw42wbyv1w9", "event": "webhook.test", "status": "delivered", "httpStatus": 200,
"attempts": 1, "nextAttemptAt": null, "createdAt": 1795431467 }- 고른 이벤트와 상관없이 갑니다. 본문의 data는 { webhookId, message }입니다.
- status가 failed면 httpStatus로 귀사 서버의 응답을 확인합니다. 응답이 없었으면 httpStatus는 null입니다. 시험 이벤트는 다시 보내지 않습니다.
- 시험 이벤트는 초당 1회까지 보낼 수 있습니다(넘으면 429).
GET/webhooks/{id}/deliveries
최근 전송 기록 50건
{ "data": [ { "id": "dlv_…", "event": "stream.started", "status": "delivered", "httpStatus": 200,
"attempts": 1, "nextAttemptAt": null, "createdAt": 1795431467 } ] }- status는 pending(다시 보낼 예정), delivered(성공), failed(재시도를 모두 실패)입니다.
이벤트 종류
| 이벤트 | 언제 | data |
|---|---|---|
stream.started | 방송이 시작됐을 때 | channelId, externalId, startedAt |
stream.ended | 방송이 끝났을 때 | channelId, externalId, startedAt, endedAt |
recording.ready | 다시보기나 MP4 파일이 준비됐을 때 | recordingId, channelId, externalId, startedAt, endedAt, durationSec, sizeBytes (MP4 만들기면 externalId 대신 sourceRecordingId) |
recording.failed | 녹화를 켠 방송이 녹화되지 않았을 때(녹화 시작 실패·녹화 중 오류, 또는 방송이 끝나고 1시간이 지나도 다시보기가 없을 때) | channelId, externalId, reason(start_failed, error, missing), at 또는 startedAt·endedAt |
recording.deleted | 다시보기가 지워졌을 때 | recordingId, channelId, reason(manual 직접 삭제, expired 보관 기간 만료) |
usage.cap_reached | 전송량 상한에 도달했을 때 | period, capGb, usedGb, blocked(재생 발급을 막았는지), until |
usage.spike | 대역폭이 알림 기준을 넘었을 때 | bandwidthMbps, thresholdMbps, minute |
서명 확인
- 서명은 HMAC-SHA256(비밀값, "<t>.<요청 본문 그대로>")의 16진수입니다.
- 본문을 JSON으로 풀기 전의 원문으로 계산해야 합니다.
- t가 5분 넘게 지난 요청은 버립니다.
import { createHmac, timingSafeEqual } from "node:crypto";
export function verifyWebhook(rawBody, signatureHeader, secret) {
const parts = Object.fromEntries(String(signatureHeader).split(",").map((p) => p.split("=")));
const t = Number(parts.t);
if (!t || Math.abs(Date.now() / 1000 - t) > 300) return false;
const expected = createHmac("sha256", secret).update(`${t}.${rawBody}`).digest("hex");
const given = String(parts.v1 ?? "");
return expected.length === given.length && timingSafeEqual(Buffer.from(expected), Buffer.from(given));
}import hashlib, hmac, time
def verify_webhook(raw_body: bytes, signature_header: str, secret: str) -> bool:
parts = dict(p.split("=", 1) for p in signature_header.split(","))
t = int(parts.get("t", 0))
if not t or abs(time.time() - t) > 300:
return False
expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
return hmac.compare_digest(expected, parts.get("v1", ""))function verify_webhook(string $rawBody, string $signatureHeader, string $secret): bool {
$parts = [];
foreach (explode(',', $signatureHeader) as $p) { [$k, $v] = array_pad(explode('=', $p, 2), 2, ''); $parts[$k] = $v; }
$t = (int)($parts['t'] ?? 0);
if (!$t || abs(time() - $t) > 300) return false;
return hash_equals(hash_hmac('sha256', "$t.$rawBody", $secret), $parts['v1'] ?? '');
}