Browser SDK
createPhone
Create the phone that holds the connection, the audio and the calls of one page.
import { createPhone } from '@06line/sdk-browser';
const phone = createPhone({ getEphemeralKey: () => fetch('/api/06line-key', { method: 'POST' }).then((r) => r.json()) });Returns a Phone. Create one per page: it opens a single WebRTC session and handles one
call at a time.
Options
Prop
Type
What it does for you
| Concern | Handled by the SDK |
|---|---|
| Keys | Fetches an ephemeral key at start and refreshes it before it expires |
| WebRTC session | Builds the offer with the ICE servers, opens the session, listens to its data channel, opens a new session when ICE fails or the data channel closes (see reconnection) |
| Calls | Each REST call becomes a promise, resolved with the call or rejected with a PhoneError; call events update the Call objects; an incoming call another session answers ends here with answered_elsewhere |
| Devices and volumes | Microphone and speaker chosen per call, changeable mid-call; input gain and playback volume from 0 to 2 |
| Microphone | getUserMedia with echo cancellation and noise suppression (the browser's automatic gain is off: inputVolume is the only gain), or your own MediaStream; permission errors |
| Audio | WebRTC with G.711: the browser handles jitter and lost packets; the SDK adds input gain, a soft limiter and playback volume |
| Call controls | Mute, input and output levels for a meter |
Browser support
Chrome, Edge, Firefox and Safari, current versions. Speaker choice needs HTMLMediaElement.setSinkId, which some Safari
versions lack: check phone.canChooseOutput.