# live-cat

> ray-streaming launcher for 3dcat

Latest version **2.1.6** (published 2024-12-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install live-cat
pnpm add live-cat
yarn add live-cat
bun add live-cat
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.1.6 |
| Published | 2024-12-03 |
| First published | 2021-12-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 627.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | jim |
| Maintainers | elyongwj, kitsch, jim1874 |
| Keywords | WebRTC, 3DCAT |

## Links

- npm: https://www.npmjs.com/package/live-cat
- npm.io page: https://npm.io/package/live-cat

## Dependencies (5)

- [rxjs](https://npm.io/package/rxjs.md) ^7.8.1
- [ray-streaming](https://npm.io/package/ray-streaming.md) 2.23.9
- [@neodrag/svelte](https://npm.io/package/@neodrag/svelte.md) ^2.0.6
- [svelte-viewport-info](https://npm.io/package/svelte-viewport-info.md) ^1.0.2
- [resize-observer-polyfill](https://npm.io/package/resize-observer-polyfill.md) ^1.5.1

## Recent versions

- 2.1.6 (latest) — 2024-12-03
- 0.1.0-beta.0 (beta) — 2021-12-02
- 2.1.5 — 2024-12-03
- 2.1.4 — 2024-11-14
- 2.1.3 — 2024-11-13
- 2.1.2 — 2024-10-25
- 2.1.1 — 2024-10-11
- 2.1.0 — 2024-09-27
- 2.0.0 — 2024-09-12
- 1.2.3 — 2024-08-01
- 1.2.2 — 2024-07-30
- 1.2.1 — 2024-06-14
- 1.2.0 — 2024-04-08
- 1.1.12 — 2024-03-07
- 1.1.11 — 2024-03-05
- … 56 more at https://npm.io/package/live-cat/versions

## README

# 3DCAT RayStreaming Launcher

[RayStreaming](https://www.npmjs.com/package/ray-streaming 'RayStreaming') Launcher

### Quick start

instantiation parameter

```typescript
type Phase =
  | 'initial'
  | 'signaling-connected'
  | 'node-ready'
  | 'end-candidate'
  | 'peer-connection-connected'
  | 'data-channel-open'
  | 'streaming-ready'
  | 'loaded-metadata'
  | 'streaming-playing'

interface Options {
  minBitrate: number
  maxBitrate: number
  startBitrate: number
  rateLevel: RateLevel

  startType: StartType
  autorunRivatuner: boolean
  enableLogPersistent: boolean
  audioToastDisplay: boolean
  iceTransportPolicy: RTCIceTransportPolicy
  autoLoadingVideo: boolean
  isFullScreen: boolean
  openMicrophone: boolean
  openMultiTouch: boolean

  needLandscape: boolean
  landscapeType: LandscapeType
  settingHoverButton: VirtualControlDisplayType
  keyboardMappingConfig?: VirtualGlobalType
  inputHoverButton: InputHoverButton

  toolbarLogo: string
  toolOption?: ToolOptionType
  eventOption?: eventOptionType
  onError: (reason: ErrorState) => void
  onPhaseChange: (phase: Phase, deltaTime: number) => void
  onPlay: () => void
  onMount: (element: HTMLElement) => void
  onRotate: (rotate: boolean) => void
}
enum RateLevel {
  SD,
  HD,
  FHD,
  UHD4K,
}
enum StartType {
  Normal = 1,
  Screen = 3,
}
enum VirtualControlDisplayType {
  HideAll,
  DisplayMobile,
  DisplayPc,
  DisplayAll,
}
interface VirtualGlobalType {
  showButton: boolean
  landscape: VirtualDataType[]
  portrait: VirtualDataType[]
}
type VirtualDataType = {
  type: ScreenDataType
  value: SolutionValue
  scale?: number
}

enum ScreenDataType {
  Normal = 1,
  UDLR,
  WASD,
  Joystick,
  Mouse,
}
type SolutionValue = {
  pos: number[]
  value: number[]
  width?: number
  height: number
  shape?: SolutionShape
}
enum SolutionShape {
  Rectangle = 1,
  Circle,
}
enum InputHoverButton {
  Hide,
  Display,
}
```

```javascript
import { Launcher } from 'live-cat'

// NOTE: signaling,token and iceServers were provided by 3dcat
const signaling = 'wss://xxxxx'
const token = 'xxxxxxxx'
const iceServers = [
  {
    urls: 'turn:xxx.xxx.xxx.xxx',
    username: 'xxxxxx',
    credential: 'xxxxxx',
  },
  {
    urls: 'stun:xxx.xxx.xxx.xxx',
    username: 'xxxxxx',
    credential: 'xxxxx',
  },
]

const bootstrap = () => {
  const container = document.querySelector('body')
  document.querySelector('body').style.width = '100%'
  document.querySelector('body').style.height = '100%'
  const launcher = new Launcher(
    `${signaling}/clientWebsocket/${token}`,
    iceServers,
    container,
    options,
  )
}
window.addEventListener('DOMContentLoaded', () => {
  if (
    navigator.userAgent.includes('miniProgram') ||
    navigator.userAgent.includes('MicroMessenger')
  ) {
    //NOTE: wechat environment started
    document.addEventListener('WeixinJSBridgeReady', bootstrap)
  } else {
    bootstrap()
  }
})
```

### Adjust bandwidth

```javascript
Launcher.connection().changeBandwidth(
  8000, // start bitrate kbps
  10000, // max bitrate kbps
  5000, // min bitrate kbps
)
Launcher.connection().changeBandwidth(
  10000, // medians bitrate kbps
)
```

### Statistics

```javascript
window.setInterval(() => {
  const { fps, bitrate, packetLossRate, latency, averageJitterBufferDelay } = launcher.report()
  console.log(`
    FPS: ${fps}
    biterate: ${bitrate}kbps
    latency: ${latency}ms
    averageJitterBufferDelay: ${averageJitterBufferDelay}ms
    packetLossRate: ${(packetLossRate * 100).toFixed(3)}%
  `)
}, 1000)
```

### ToggleFullscreen

```javascript
/* NOTE: fullscreen need user activation gesture
 * @see https://html.spec.whatwg.org/multipage/interaction.html#user-activation-processing-model
 */
someTriggerElement.addEventListener('click', () => launcher.toggleFullscreen())
```

### Dashboard

```javascript
// ...
launcher.showDashboard()
launcher.hideDashboard()
// NOTE: export statistics and log data
launcher.exportLog()
```

### Microphone

```javascript
// start capture audio to node
launcher.openMicrophone()
// stop
launcher.closeMicrophone()
```

### Camera

```javascript
// start capture video to node
launcher.openCamera()
// stop
launcher.closeCamera()
```

### File Transfer

```typescript
//Upload file to node

//Note: When dir is empty, it actually points to the "<User>/Downloads" directory in node
launcher.changeUploadDir(dir:string)
launcher.uploadFile(file: File, onStateChange?: FileUploadStateChangeHandler)

//Download file from node
launcher.downloadFileByFullPath(absolutePath:string)
```

### Destroy

```javascript
launcher.destroy()
```

---
_Source: https://npm.io/package/live-cat · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
