diff --git a/README.md b/README.md index 09663849..5816975e 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,149 @@ rtp_port: port to listen and send RTP traffic (default 10000-20000) The config file can be added to a mounted volume with its location passed in the SIP_CONFIG_FILE env var, or its body can be passed in the SIP_CONFIG_BODY env var. +### Using the SIP service + +#### Creating Bridge and Dispatch Rule + +Accepting SIP traffic requires two resources be created. First a `SIP Bridge`, then a `SIP Dispatch Rule`. + +These resources can be created with any of the server SDKs or with the [livekit-cli](https://github.com/livekit/livekit-cli). The syntax with the livekit-cli is as follow: + +The `SIP Bridge` is used to authenticate incoming traffic. Typically you will create a `SIP Bridge` to map to your different +SIP providers and their IP Ranges/Authentication details. + +```shell +livekit-cli create-sip-bridge \ + --request +``` + +The SIP Bridge request creation JSON file uses the following syntax: + +```json +{ + "inbound_addresses": Array of IP Address or CIDRs where SIP INVITEs will be accepted from + "outbound_address": IP Address that SIP INVITEs will be sent too + "outbound_number": When making an outbound call on this SIP Trunk what Phone Number should be used + "inbound_numbers_regex": Phone numbers this SIP Trunk will serve. If Empty it will serve all incoming calls, + "inbound_user": Username for Authentication of inbound calls, no Authentication if empty, + "inbound_password": Password for Authentication of inbound calls, no Authentication if empty, + "outbound_user": Username for Authentication of outbound calls, no Authentication if empty, + "outbound_password": Password for Authentication of outbound calls, no Authentication if empty +} +``` + +On success, `livekit-cli` will return the unique id for the SIP Trunk. + +Next a `SIP Dispatch Rule` needs to be created. A `SIP Dispatch Rule` determines what LiveKit room an incoming call should be directed into. You can direct calls into +different rooms depending on the metadata of the call. Things like who is calling, who they called and what pin did they enter. + +```shell +livekit-cli create-sip-dispatch-rule \ + --request +``` + +The SIP Bridge request creation JSON file uses the following syntax: + +```json +{ + "rule": // What rule to use to dispatch this call, see the next section for rules + "trunk_ids": // Array of SIP Trunk IDs that are accepted for this rule. If empty all Trunks are accepted + "hide_phone_number": // If true hide the phone number when joining the LiveKit room +} +``` + +At this time we support one rule `dispatchRuleDirect`. This can be set like so + +``` + "rule": { + "dispatchRuleDirect": { + "roomName":"my-new-room" + } + } +``` + + +On success, `livekit-cli` will return the unique id for the SIP Dispatch Rule. + +### Running locally + +#### Running natively + +The SIP service can be run natively on any platform supported by libpous. + +##### Prerequisites + +The SIP service is built in Go. Go >= 1.18 is needed. The SIP services uses [libopus](https://opus-codec.org/) and must be installed externally: + +For Debian + +``` +sudo apt-get install pkg-config libopus-dev libopusfile-dev +``` + +For Mac + +``` +brew install pkg-config opus opusfile + +``` + +For more instructions see [hraban/opus' README](https://github.com/hraban/opus#build--installation) + +##### Building + +Build the SIP service by running: + +```shell +mage build +```` + +##### Running the service + +To run against a local LiveKit server, a redis server must be running locally. All servers must be configured to communicate over localhost. Create a file named `config.yaml` with the following content: + +```yaml +log_level: debug +api_key: +api_secret: +ws_url: ws://localhost:7880 +redis: + address: localhost:6379 +``` + +```shell +sip --config=config.yaml +``` + +#### Running with Docker + +To run against a local LiveKit server, a Redis server must be running locally. The SIP service must be instructed to connect to LiveKit server and Redis on the host. The host network is accessible from within the container on IP: +- host.docker.internal on MacOS and Windows +- 172.17.0.1 on linux + +Create a file named `config.yaml` with the following content: + +```yaml +log_level: debug +api_key: +api_secret: +ws_url: ws://host.docker.internal:7880 (or ws://172.17.0.1:7880 on linux) +redis: + address: host.docker.internal:6379 (or 172.17.0.1:6379 on linux) +``` + +The container must be run with host networking enabled. SIP by default uses UDP port 1000 -> 2000 and 5060, this large range of ports is hard for docker to handle at this time. + +Then to run the service: + +```shell +docker run --rm \ + -e SIP_CONFIG_BODY="`cat config.yaml`" \ + --network host \ + livekit/sip +``` + +