---title: Clientsidebar_position: 1---import MethodOff from ../../_common/_method_off.mdx;import MethodOn from ../../_common/_method_on.mdx;import MethodOnce from ../../_common/_method_once.mdx;import MethodRemoveAllListeners from ../../_common/_method_removealllisteners.mdx;You can use instances of this class to initiate or receive calls. Please see [Events](#events) for the full list of events you can subscribe to.#### ExamplesThe following example answers any call in the office context.javascriptimport { Voice } from @signalwire/realtime-api;const client = new Voice.Client({ project: , token: , contexts: [office],});client.on(call.received, async (call) => { console.log(Got call, call.from, call.to); try { await call.answer(); console.log(Inbound call answered); } catch (error) { console.error(Error answering inbound call, error); }});The following example initiates a new call.javascriptconst client = new Voice.Client({ project: , token: , contexts: [office],});try { const call = await client.dialPhone({ from: +YYYYYYYYYY, to: +XXXXXXXXXX, timeout: 30, });} catch (e) { console.log(Call not answered.);}## Constructors### constructor• **new Client**(opts)#### Parameters| Name | Type | Description || :-------------- | :--------- | :----------------------------------------------------------------------------------- || opts | Object | - || opts.contexts | string[] | SignalWire contexts, e.g. [home, office]. || opts.project | string | SignalWire project id, e.g. a10d8a9f-2166-4e82-56ff-118bc3a4840f. || opts.token | string | SignalWire project token, e.g. PT9e5660c101cd140a1c93a0197640a369cf5f16975a0079c9. |## Methods### dial▸ **dial**(dialer): Promise<[Call](./voice-call.mdx)\>Makes an outbound Call and waits until it has been answered or hung up. This is an advanced method that lets you call multiple devices in parallel or series: for simpler use cases, see [dialPhone](#dialphone) and [dialSip](#dialsip).With this method you can specify a configuration of devices to call in series and/or in parallel: as soon as one device answers the call, the returned promise is resolved. You specify a configuration through a [VoiceDeviceBuilder](./voice-devicebuilder.md) object.#### Parameters| Name | Type | Description || :------- | :----------------------------------------------- | :----------------------------------------- || dialer | [VoiceDeviceBuilder](./voice-devicebuilder.md) | The Dialer specifying the devices to call. |#### ReturnsPromise<[Call](./voice-call.mdx)\>A call object.#### ExampleCalls a phone number. If the number doesnt answer within 30 seconds, calls two different SIP endpoints in parallel.jsconst devices = new Voice.DeviceBuilder() .add(Voice.DeviceBuilder.Phone({ from: +XXXXXX, to: +YYYYYY, timeout: 30 })) .add([ Voice.DeviceBuilder.Sip({ from: sip:aaa@bbb.cc, to: sip:xxx@yyy.zz }), Voice.DeviceBuilder.Sip({ from: sip:aaa@bbb.cc, to: sip:ppp@qqq.rr }), ]);try { const call = await client.dial(devices); console.log(Call answered);} catch (e) { console.log(Call not answered);}---### dialPhone▸ **dialPhone**(params): Promise<[Call](./voice-call.mdx)\>Makes an outbound call to a PSTN number.#### Parameters| Name | Type | Description || :-------------------------- | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ || params | Object | - || params.from? | string | The party the call is coming from. Must be a SignalWire number or SIP endpoint that you own. || params.maxPricePerMinute? | number | The maximum price in USD acceptable for the call to be created. If the rate for the call is greater than this value, the call will not be created. If not set, all calls will be created. Price can have a maximum of four decimal places, i.e. 0.0075. || params.timeout? | number | The time, in seconds, the call will ring before it is considered unanswered. || params.to | string | The party you are attempting to call. |#### ReturnsPromise<[Call](./voice-call.mdx)\>A call object.#### Examplejstry { const call = await client.dialPhone({ from: +YYYYYYYYYY, to: +XXXXXXXXXX, timeout: 30, });} catch (e) { console.log(Call not answered.);}---### dialSip▸ **dialSip**(params): Promise<[Call](./voice-call.mdx)\>Makes an outbound call to a SIP endpoint.#### Parameters| Name | Type | Description || :-------------------------- | :------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ || params | Object | - || params.codecs? | SipCodec[] | Optional array of desired codecs in order of preference. Supported values are PCMU, PCMA, OPUS, G729, G722, VP8, H264. Default is parent leg codec(s). || params.from | string | The party the call is coming from. Must be a SignalWire number or SIP endpoint that you own. || params.headers? | [SipHeader](./types.mdx#sipheader)[] | Array of [SipHeader](./types.mdx#sipheader) objects. Must be X- headers only, see example below. || params.maxPricePerMinute? | number | The maximum price in USD acceptable for the call to be created. If the rate for the call is greater than this value, the call will not be created. If not set, all calls will be created. Price can have a maximum of four decimal places, i.e. 0.0075. || params.timeout? | number | The time, in seconds, the call will ring before it is considered unanswered. || params.to | string | The party you are attempting to call. || params.webrtcMedia? | boolean | If true, WebRTC media is negotiated. Default is parent leg setting. || params.sessionTimeout? | number | Non-negative value, in seconds, to use for the SIP Session-Expires header. If 0 or unset, SignalWire will pick the default (typically 600). |#### ReturnsPromise<[Call](./voice-call.mdx)\>A call object.#### Examplejstry { const call = await client.dialSip({ from: sip:xxx@yyy.zz, to: sip:ppp@qqq.rr, timeout: 30, headers: [ { name: X-SomeKeyA, value: SomeValueA }, { name: X-SomeKeyB, value: SomeValueB }, ], });} catch (e) { console.log(Call not answered.);}---### disconnect▸ **disconnect**(): voidDisconnects this client. The client will stop receiving events and you will need to create a new instance if you want to use it again.#### Returnsvoid#### Examplejsclient.disconnect();---### off ---### on ---### once ---### removeAllListeners ## Events### call.received• **call.received**(call)A call has been received. You can use the provided Call object to answer.#### Parameters| Name | Type || :----- | :------------------------- || call | [Call](./voice-call.mdx) |