SDK 사용법
cb.video 는 두 가지 사용 패턴을 지원합니다:
- 단일 스토리지:
cb.video.list(),cb.video.get(videoId)— 기본 비디오 스토리지 사용 - 다중 스토리지:
cb.video.storage.listVideos(storageId, ...)— 여러 비디오 스토리지를 분리 운영할 때
초기화
typescript
import ConnectBase from 'connectbase-client'
const cb = new ConnectBase({
publicKey: 'cb_pk_...'
})비디오 목록 조회
typescript
const result = await cb.video.list({
status: 'ready', // 'pending' | 'processing' | 'ready' | 'failed'
visibility: 'public', // 'public' | 'unlisted' | 'private'
page: 1,
limit: 20
})
console.log(result.videos) // Video[]
console.log(result.total)비디오 상세 조회
typescript
const video = await cb.video.get('video-id')
console.log(video.title)
console.log(video.duration)
console.log(video.view_count)
console.log(video.status) // 'pending' | 'processing' | 'ready' | 'failed'
console.log(video.visibility)비디오 수정 / 삭제
typescript
await cb.video.update('video-id', {
title: '새 제목',
description: '새 설명',
visibility: 'public'
})
await cb.video.delete('video-id')HLS 스트리밍
typescript
const streamInfo = await cb.video.getStreamUrl('video-id')
// {
// stream_url: 'https://cdn.../master.m3u8',
// ...
// }
// 특정 화질 지정
const hd = await cb.video.getStreamUrl('video-id', '1080p')
// HLS.js 로 재생
import Hls from 'hls.js'
if (Hls.isSupported()) {
const hls = new Hls()
hls.loadSource(streamInfo.stream_url)
hls.attachMedia(videoElement)
}다중 스토리지 (storage 서브 네임스페이스)
여러 비디오 스토리지를 운영할 때는 cb.video.storage 를 사용합니다.
스토리지(컨테이너) 자체는 콘솔에서 미리 생성해야 합니다 — SDK 의 컨테이너 CRUD 는 아직 백엔드에 라우트가 없습니다.
typescript
// 콘솔에서 발급받은 storageId 를 사용
const storageId = 'stg_xxx'
// 특정 스토리지의 비디오 목록 (status / limit / cursor 지원)
const videos = await cb.video.storage.listVideos(storageId, {
status: 'ready',
limit: 20,
})
// 단일 비디오 조회
const video = await cb.video.storage.getVideo(storageId, 'video-id')
// 비디오 삭제
await cb.video.storage.deleteVideo(storageId, 'video-id')| SDK 메서드 | 동작 | 비고 |
|---|---|---|
cb.video.storage.listVideos / getVideo / deleteVideo / getStreamUrl / getTranscodeStatus | ✅ | 모두 /v1/public/storages/videos/:storageID/... 프록시를 통해 동작 |
cb.video.storage.upload | ⚠️ 청크 단계 mismatch | init/complete 경로는 정렬되어 있지만 chunk 단계에서 SDK 가 POST 를, 백엔드가 PUT 를 요구해 405 가 됩니다. raw fetch 로 PUT /v1/public/storages/videos/:storageID/uploads/:uploadID/chunk 를 직접 호출하세요. |
cb.video.storage.create / list / get / update / delete | ❌ 404 | 스토리지 컨테이너 CRUD 라우트가 백엔드에 없음 — 콘솔에서 생성/관리하세요 |