Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

3 Commits

Repository files navigation

简体中文 | English

Cloud Streaming Web App ↔ Client Communication Demo

A reference sample for cloud-streamed Web applications that communicate with the end-user client over a runtime-injected JavaScript bridge— including bidirectional text messaging and shared microphone PCM audio.

Live demo page: index.html

Demo preview — connection status, mic stats, waveform, and playback


What This Demo Shows

CapabilityDescription
Bidirectional textRegister on_message to receive client messages; call dlcaSend() to push text back to the client
Shared microphoneReceive client mic audio as PCM via on_mic_pcm (s16le, interleaved)
Connection statusShows when the cloud-streaming bridge is ready
Mic capture detectionDetects whether the client has started sharing the microphone (15s timeout)
Live statsFormat, sample rate, channels, packet count, bytes, volume level, rolling buffer duration
VisualizationVolume meter and waveform (no real-time playback by default)
Playback bufferPlay last 10 seconds — merges cached PCM and plays through Web Audio

Use this sample as a starting point for voice interaction, in-app notifications, game chat, ASR pipelines, or any workflow that needs client ↔ cloud Web app data exchange.


Architecture at a Glance

Text messages

Client <————————————————> Cloud streaming service <————————————————> Web app
Data channel dlcaReg / dlcaSend
  • Client → app: on_message callback
  • App → client: dlcaSend(text)

Shared microphone

Client microphone
|
v (client enables "share microphone")
Cloud streaming service
|
v
Web app on_mic_pcm callback

Audio is captured on the client. The streamed Web app only receives PCM and decides how to use it (playback, recognition, upload, etc.).


Quick Start

1. Integrate the bridge

Add dlcaReg handlers to your page (see the integration section in index.html or the minimal template below).

2. Deploy and configure the admin console

  1. Host your Web content at a reachable URL
  2. Set the app entry URL in the cloud streaming admin console
  3. Under Advanced settings, enable Communication plugin and Microphone component

3. Connect from the client

  • Use HTTPS — default port 8086
  • URLs copied from the admin console are often http; change them to https://host:8086/...
  • When the page opens, allow microphone access

4. Verify the demo

  1. Start a cloud streaming session — the demo page should show Cloud streaming bridge ready
  2. Allow the microphone and speak — packet count increases, waveform and volume bar react
  3. Click Send test message to client — the client should receive the text
  4. Click Play last 10 seconds — hear the cached PCM buffer

Opening the HTML file directly in a normal browser will not expose dlcaReg / dlcaSend. Access the page through a cloud streaming session, or guard with typeof dlcaReg === 'function'.


API Reference

The platform injects two global functions into your streamed Web app:

FunctionPurpose
dlcaReg(type, callback)Register callbacks for client → app data
dlcaSend(text)Send text from the app to the client

App entry URL and streaming parameters are configured in the admin console — do not hard-code them in the page.

dlcaReg(type, callback)

Register a callback. Registering the same type again replaces the previous handler.

ParameterTypeDescription
typestringCallback type (see table below)
callbackfunctionHandler invoked when data arrives

Supported type values

typeDirectionDescription
"on_message"Client → appText messages
"on_mic_pcm"Client mic → appPCM audio frames

Example

dlcaReg('on_message',(text)=>{console.log('Message from client:',text);});dlcaReg('on_mic_pcm',(pcmBuffer,sampleRate,channelCount,sampleCount)=>{constpcm=newInt16Array(pcmBuffer);// Process PCM...});

Register early in page load. Messages that arrive before registration are dropped.


dlcaSend(text)

Send a text message from the Web app to the control client in the current session.

ParameterTypeDescription
textstringPlain text or JSON string

Returns:booleantrue if sent successfully.

Example

dlcaSend(JSON.stringify({event: 'scene_ready',level: 1}));

Prerequisites

  • Communication plugin and Microphone component enabled in admin advanced settings
  • Client accessed via https://host:8086/...
  • Microphone permission granted in the browser

Callback Details

on_message

dlcaReg('on_message',(text)=>{// text: string});
ParameterTypeDescription
textstringText from the client

on_mic_pcm

dlcaReg('on_mic_pcm',(pcmBuffer,sampleRate,channelCount,sampleCount)=>{// pcmBuffer: ArrayBuffer// sampleRate: e.g. 48000// channelCount: 1 or 2// sampleCount: total samples (= frames × channels)});
ParameterTypeDescription
pcmBufferArrayBufferRaw PCM bytes
sampleRatenumberSample rate (Hz)
channelCountnumberNumber of channels
sampleCountnumberTotal sample count

PCM format

PropertyValue
EncodingSigned 16-bit little-endian (s16le)
LayoutInterleaved — stereo is L0 R0 L1 R1 ...
Byte lengthsampleCount × 2
Frames per channelsampleCount / channelCount

Read channels

dlcaReg('on_mic_pcm',(pcmBuffer,sampleRate,channelCount,sampleCount)=>{constint16=newInt16Array(pcmBuffer);constframes=sampleCount/channelCount;for(leti=0;i<frames;i++){constleft=int16[i*channelCount+0];constright=channelCount>1 ? int16[i*channelCount+1] : left;// Your logic...}});

Play with Web Audio

functionplayPcm(pcmBuffer,sampleRate,channelCount,sampleCount){if(sampleCount<=0)sampleCount=pcmBuffer.byteLength/2;constint16=newInt16Array(pcmBuffer);constframes=sampleCount/channelCount;constctx=newAudioContext({ sampleRate });constbuffer=ctx.createBuffer(channelCount,frames,sampleRate);for(letch=0;ch<channelCount;ch++){constdata=buffer.getChannelData(ch);for(leti=0;i<frames;i++){data[i]=int16[i*channelCount+ch]/32768;}}constsource=ctx.createBufferSource();source.buffer=buffer;source.connect(ctx.destination);source.start();}

Minimal Integration Template

<script>(function(){functioninit(){if(typeofdlcaReg!=='function')returnfalse;dlcaReg('on_message',(text)=>{console.log('[message]',text);});dlcaReg('on_mic_pcm',(pcmBuffer,sampleRate,channelCount,sampleCount)=>{constpcm=newInt16Array(pcmBuffer);// Feed your audio pipeline});returntrue;}if(!init()){consttimer=setInterval(()=>init()&&clearInterval(timer),500);}})();</script>

Notes

  1. Register early — call dlcaReg as soon as possible, ideally at the top of your page script.
  2. Local preview — bridge APIs are unavailable when opening HTML locally; this is expected.
  3. Structured datadlcaSend is text-only; use JSON.stringify / JSON.parse for objects.
  4. Visualization vs. playback — the demo uses meters and waveforms; playback or ASR is up to your app.
  5. Streaming callbackson_mic_pcm fires per audio packet; buffer, schedule, or resample as needed.
  6. HTTPS + mic — configure the entry URL in the admin console; clients should use HTTPS (port 8086) and grant mic permission.

Files

FileDescription
preview.pngScreenshot of the running demo
index.htmlFull demo: messaging, mic PCM, stats, volume bar, waveform, 10s playback
README.mdThis document (English)
README.zh-CN.md简体中文文档

About

A demo for demonstrating the microphone voice and data channels of WebGL content

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages