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 로 생성·관리할 수 있고, 콘솔에서도 동일하게 관리됩니다.
typescript
// 컨테이너 생성 (또는 콘솔에서 생성한 storageId 사용)
const container = await cb.video.storage.create({
name: 'my-videos',
is_public: true,
})
const storageId = container.id
// 컨테이너 목록 / 단일 조회 / 수정 / 삭제
const { storage_videos } = await cb.video.storage.list()
await cb.video.storage.get(storageId)
await cb.video.storage.update(storageId, { description: '업데이트' })
// await cb.video.storage.delete(storageId)
// 특정 스토리지의 비디오 목록 (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.create / list / get / update / delete | ✅ | 컨테이너 CRUD — /v1/public/storages/videos (Public Key 인증) |
cb.video.storage.upload | ✅ | init → chunk(PUT) → complete 를 SDK 가 자동 처리 |
cb.video.storage.listVideos / getVideo / deleteVideo / getStreamUrl / getTranscodeStatus | ✅ | 컨테이너 안 비디오 조작 — /v1/public/storages/videos/:storageID/... |