coze-js icon indicating copy to clipboard operation
coze-js copied to clipboard

feat(websocket): Add WebRTC demo

Open jackshen310 opened this issue 6 months ago • 2 comments

jackshen310 avatar May 27 '25 08:05 jackshen310

Walkthrough

This update introduces a WebRTC-based live audio streaming and translation feature across multiple packages and the realtime-console example. It adds new API resources, event types, and configuration options for simultaneous interpretation, along with documentation and UI components for publishing and subscribing to live audio streams, including translation support and QR code-based sharing.

Changes

Files/Paths Change Summary
common/changes/@coze/api/..., common/changes/@coze/realtime-api/... Changelog entries documenting the addition of a WebRTC demo and live audio/translation features.
examples/realtime-console/package.json Added qrcode.react dependency, removed deploy script, added postbuild script for static hosting.
examples/realtime-console/tsconfig.json Changed moduleResolution from node to bundler.
examples/realtime-console/src/App.tsx Registered new /subscribe route for the Subscribe page.
examples/realtime-console/src/pages/main/header.tsx Added liveId state, subscribed to LIVE_CREATED event, rendered LiveInfo component, commented out audio test/reporting code.
examples/realtime-console/src/pages/main/index.tsx Added support for "translate" room mode, translation event handling, and combined transcript/translation UI rendering.
examples/realtime-console/src/pages/main/setting-form.tsx Added "Translate" room mode and configuration UI, persisted translate_config in local storage, updated form logic.
examples/realtime-console/src/pages/main/live-info.tsx New LiveInfo component: displays QR code and URL for live listening, supports download/copy, conditionally renders for translate mode.
examples/realtime-console/src/pages/subscribe/index.tsx New Subscribe component: manages real-time audio subscription, stream selection, mute/unmute, and connection state UI.
examples/realtime-console/src/utils/local-manager.ts Added TRANSLATE_CONFIG enum member to LocalStorageKey.
examples/realtime-console/src/utils/utils.ts Added getTranslateConfig utility to parse translation config from local storage.
packages/coze-js/src/resources/audio/index.ts Imported and exposed new Live resource via Audio class.
packages/coze-js/src/resources/audio/live/index.ts New Live class: fetches live stream info, defines RetrieveLiveData, StreamInfo, and LiveType types.
packages/coze-js/src/resources/audio/rooms/rooms.ts Extended RoomConfig with translate_config, added TranslateConfig interface, and RoomMode.Translate enum member.
packages/realtime-api/README.md, README.zh-CN.md, live.md Added documentation for simultaneous interpretation, including usage guides and API reference for live audio/translation.
packages/realtime-api/package.json Added "./live" export subpath for live audio/translation module.
packages/realtime-api/rslib.config.ts Added build outputs for live subpath in both CJS and ESM formats.
packages/realtime-api/src/event-names.ts Added LIVE_CREATED event to EventNames enum.
packages/realtime-api/src/index.ts Added translateConfig to RealtimeClientConfig, updated room creation logic to support translation.
packages/realtime-api/src/live/index.ts New WebLiveClient class for subscribing to live audio streams, manages WebRTC connections, exposes status/events/mute/subscribe/unsubscribe methods.

Sequence Diagram(s)

Simultaneous Interpretation: Publishing and Subscribing Flow

sequenceDiagram
    participant Publisher (RealtimeClient)
    participant Server (Coze WTN)
    participant Subscriber (WebLiveClient)
    participant UI (LiveInfo/Subscribe)

    Publisher->>Server: Create Room with translateConfig
    Server-->>Publisher: Room created, emits LIVE_CREATED event (liveId)
    Publisher->>UI: Show QR code and listen URL (via LiveInfo)
    Subscriber->>Server: Connect using liveId
    Subscriber->>Server: Fetch available streams (origin/translation)
    Subscriber->>Server: Subscribe to selected stream (SDP offer)
    Server-->>Subscriber: SDP answer, starts audio stream
    Subscriber->>UI: Play audio, update status

Suggested reviewers

  • DingGao-Devin

Poem

🐇
A whisper hops across the wire,
Now rabbits translate, never tire.
QR codes and streams anew,
Live audio magic just for you!
With WebRTC, we leap ahead—
Listen, share, and gently tread
Where bunny tech and voices wed.

✨ Finishing Touches
  • [ ] 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

coderabbitai[bot] avatar May 27 '25 08:05 coderabbitai[bot]

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


shenxiaojie.316 seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar May 28 '25 06:05 CLAassistant