본문으로 건너뛰기

비디오 (Video)

동영상 업로드 및 스트리밍 API입니다.

⚠️ 현재 cb.video SDK 는 백엔드와 일부 라우트가 정렬 중입니다 (2026-04 기준). 어떤 메서드가 실제로 동작하는지는 비디오 서버 개요 의 상태 표를 확인하세요.

비디오 업로드

⚠️ cb.video.uploadcb.video.storage.upload 는 둘 다 chunk 단계에서 백엔드와 어긋납니다 (SDK POST vs 백엔드 PUT). 정렬 전까지는 raw fetchPOST /v1/public/uploads/initPUT .../chunkPOST .../complete 를 직접 호출해야 합니다 — 비디오 업로드 페이지 의 우회 예제 참고.

아래는 SDK ↔ 백엔드 정렬 후의 목표 인터페이스입니다.

typescript
const input = document.getElementById('video-input') as HTMLInputElement
const file = input.files?.[0]
if (!file) throw new Error('파일을 선택해주세요')

const video = await cb.video.upload(file, {
  title: '내 동영상',
  description: '설명',
  visibility: 'public',  // 'public' | 'unlisted' | 'private'
  tags: ['vlog'],
  onProgress: (progress) => {
    console.log(`${progress.phase}: ${progress.percentage}%`)
  }
})
console.log('업로드 시작:', video.id, '상태:', video.status)  // 'processing'

📌 SDK 에는 createUploader / uploader.on('progress', ...) 같은 별도 API 가 없습니다. 진행률은 upload(...)onProgress 콜백으로 받습니다.

트랜스코딩 완료 대기

typescript
const ready = await cb.video.waitForReady(video.id, {
  timeout: 5 * 60 * 1000,
  interval: 5000
})
console.log('재생 가능:', ready.status)  // 'ready'

비디오 조회

typescript
// 비디오 목록
const result = await cb.video.list({
  status: 'ready',
  visibility: 'public',
  page: 1,
  limit: 20
})
console.log(result.videos)

// 단일 비디오
const video = await cb.video.get('video_123')

// 수정 / 삭제
await cb.video.update('video_123', { title: '새 제목' })
await cb.video.delete('video_123')

스트리밍

typescript
const streamInfo = await cb.video.getStreamUrl('video_123')

// HLS.js 로 재생
import Hls from 'hls.js'
if (Hls.isSupported()) {
  const hls = new Hls()
  hls.loadSource(streamInfo.stream_url)
  hls.attachMedia(videoElement)
}

채널 관리

typescript
// 채널 구독 / 해제 — 동작합니다
await cb.video.subscribeChannel('channel_123')
await cb.video.unsubscribeChannel('channel_123')

⚠️ 채널 자체의 CRUD (createChannel / getChannel / getChannelByHandle / updateChannel) 는 백엔드 라우트가 아직 없습니다. 채널은 콘솔에서 생성/관리하세요. 자세한 표는 비디오 서버 채널 페이지 참고.

커뮤니티 (댓글 / 좋아요)

typescript
// 댓글 목록 — 동작
const result = await cb.video.getComments('video_123', { limit: 20 })

// 댓글 삭제 — 동작
await cb.video.deleteComment('comment_123')

// 좋아요 토글 — 한 번 호출 = 좋아요, 다시 호출 = 좋아요 취소
await cb.video.likeVideo('video_123')

⚠️ cb.video.postCommentcb.video.unlikeVideo 는 백엔드 경로 mismatch 로 현재 동작하지 않습니다.

  • 댓글 작성: raw fetch 로 POST /v1/public/comments 호출 (body 에 video_id/content/parent_id)
  • 좋아요 취소: likeVideo 를 한 번 더 호출하는 토글 패턴 사용

📌 SDK 에는 incrementView 같은 명시적 조회수 증가 메서드가 없습니다. 조회수는 자체 로깅이나 추천 인터랙션 API 로 처리하세요 (reportWatchProgress 도 현재 동작하지 않습니다).

자세한 사용법은 Video Server 문서 를 참고하세요.