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 (Secret Key 인증) |
cb.video.storage.upload | ✅ | init → chunk(PUT) → complete 를 SDK 가 자동 처리 |
cb.video.storage.listVideos / getVideo / deleteVideo / getStreamUrl / getTranscodeStatus | ✅ | 컨테이너 안 비디오 조작 — /v1/public/storages/videos/:storageID/... |
접근 수준 (access_level)
컨테이너마다 퍼블릭 키로 들어오는 SDK 요청이 어떤 영상을 고치고 지울 수 있는지를 정합니다. 퍼블릭 키(cb_pk_)는 브라우저 번들에 그대로 실려 나가는 공개 식별자라 자격증명이 아니므로, 영상마다 기록된 업로더를 대조해 인가합니다. 파일 스토리지와 같은 세 값을 쓰며, 콘솔 → 스토리지 → 비디오 스토리지 → 설정 → 보안 설정에서 바꿉니다.
| 접근 수준 | 목록 조회, 재생 | 업로드 | 수정, 삭제 |
|---|---|---|---|
shared | 제한 없음 | 로그인 없이 가능 | 로그인한 멤버가 올린 영상은 그 멤버만. 업로더 기록이 없는 영상은 누구나 |
public_read | 제한 없음 | 로그인 없이 가능 | 올린 본인만. 기록이 없는 영상은 콘솔이나 Secret Key 로만 |
private | 제한 없음 (아래 참고) | 로그인 없이 가능 (아래 참고) | 올린 본인만. 기록이 없는 영상은 콘솔이나 Secret Key 로만 |
- 기존 컨테이너와 새로 만드는 컨테이너 모두
shared라 동작이 바뀌지 않습니다. 생성 시점에는 지정할 수 없고 수정으로 바꿉니다. - 비디오 경로는 접근 수준에서 쓰기 강도만 가져다 쓰므로
public_read와private이 아직 같게 동작합니다. 목록 조회를 본인 것으로 좁히거나 익명 업로드를 막는 동작은 파일 스토리지에만 있습니다. - 로그인하면(
cb.auth.signIn()) SDK 가 멤버 토큰을 자동으로 붙이고, 그때 올린 영상에만 업로더가 기록됩니다. - 콘솔과 Secret Key(
cb_sk_) 요청은 접근 수준과 관계없이 항상 전체 영상에 접근합니다.
typescript
// 컨테이너 조회 응답에 실린다
const container = await cb.video.storage.get(storageId)
console.log(container.access_level) // 'shared' | 'public_read' | 'private'
// 변경 — 컨테이너 CRUD 라 Secret Key 가 필요하다. 세 값 외에는 400
await cb.video.storage.update(storageId, { access_level: 'public_read' })