Skip to main content

Bash API example

Resources

Resources

Communicating with MistServer through bash

Installing the mist_api.sh (also available on github) allows you to run mistCall. It has several dependencies curl, jq, md5sum, cut & cat. While these dependencies should be available on almost all distributions of Linux you will get a warning if there is one missing.

Using mistCall is as follows:

mistCall [SERVER] [USERNAME PASSWORD] COMMAND
  • [SERVER] Optional, requires the server address and port where MistServer is listening. Defaults to localhost:4242
  • [USERNAME PASSWORD] Optional, the username and password used for authentication. Defaults to empty.
  • COMMAND The API call to using a partial JSON object. See the API for possible options.

Using mistCall locally only requires mistCall COMMAND

You can get additional information on how to use mistCall by running it without any COMMAND.

Source the bash script

In order to use mistCall in your terminal or through other applications you will want to source the script.

. mist_api.sh

We'd also recommend adding it to your bashrc so it's available whenever you open a terminal as your user by adding the following to your .bashrc file.

. /PATH/TO/mist_api.sh

Examples

Invalid command & default response

This is something you'll see if your command used is invalid or has no response.

Command used

mistCall

Response

{"LTS":1,"authorize":{"local":true,"status":"OK"}}

The LTS part is there for legacy reasons, the authorize field tells you the login was successful. If mistCall failed due to authorization issues you will be notified upon failure.

Adding a stream

This can be done through the addstream call. Adding the stream livestream01 with source push://localhost@password.

Command used

mistCall '{"addstream":{"livestream01":{"source":"push://localhost@password"}}'

Response

{"LTS":1,"authorize":{"local":true,"status":"OK"},"streams":{"incomplete list":1,"livestream01":{"name":"livestream01","source":"push://localhost@password"}}}

The response will inform you of the stream and configuration if successful. Of course you could add additional parameters as well:

Command used

mistCall '"addstream":{"livestream01": {"name": "livestream01","source": "push://localhost@password","stop_sessions": false,"DVR":"120000","cut": null,"debug": null,"fallback_stream": null,"maxkeepaway": null,"resume": null,"segmentsize":"6000","processes": []}}'

Response

{"LTS":1,"authorize":{"local":true,"status":"OK"},"streams":{"incomplete list":1,"livestream01":{"DVR":"120000","name":"livestream01","processes":[],"segmentsize":"6000","source":"push://localhost@password","stop_sessions":false}}}

A full list of optional parameters can be received through the capabilities call. The response tends to be big enough that we recommend writing it to a file.

Removing a stream

This can be done through the deletestream call. Removing the stream livestream01

Command used

mistCall '{"deletestream":["livestream01"]}'

Response

{"LTS":1,"authorize":{"local":true,"status":"OK"},"streams":{"incomplete list":1}}

Forcefully stopping/resetting a stream

This can be done through the nuke_stream call to completely stop all connections of a stream or reset it in case you expect it to be stuck.

Command used

mistCall '"nuke_stream":"streamname"'

Response There is no response to this call, so you'd only see:

{"LTS":1,"authorize":{"local":true,"status":"OK"}}

Requesting the configurations

You can request all MistServer configurations through the config call:

Command used

mistCall '"config":'

Response You would get a blob of the current Server/Protocol configurations as well as the version.

{"LTS":1,"authorize":{"local":true,"status":"OK"},"config":{"accesslog":"LOG","controller":{"interface":null,"port":null,"username":null},"defaultStream":null,"iid":"f@]pPestNP[WpJTT","limits":null,"prometheus":"","protocols":[{"connector":"AAC","online":"Enabled"},{"connector":"CMAF","online":"Enabled"},{"connector":"DTSC","online":1},{"connector":"EBML","online":"Enabled"},{"connector":"FLAC","online":"Enabled"},{"connector":"FLV","online":"Enabled"},{"connector":"H264","online":"Enabled"},{"connector":"HDS","online":"Enabled"},{"connector":"HLS","online":"Enabled"},{"connector":"HTTP","online":1},{"connector":"HTTPTS","online":"Enabled"},{"connector":"JSON","online":"Enabled"},{"connector":"MP3","online":"Enabled"},{"connector":"MP4","online":"Enabled"},{"connector":"OGG","online":"Enabled"},{"connector":"RTMP","online":1},{"connector":"RTSP","online":1},{"connector":"SDP","online":"Enabled"},{"connector":"SubRip","online":"Enabled"},{"connector":"TSRIST","online":"Push-only"},{"connector":"TSSRT","online":1},{"connector":"WAV","online":"Enabled"},{"connector":"WebRTC","online":"Enabled"},{"connector":"TS","online":1,"port":8888,"streamname":"live+tcp"}],"serverid":"","sessionInputMode":15,"sessionOutputMode":15,"sessionStreamInfoMode":1,"sessionUnspecifiedMode":0,"sessionViewerMode":14,"time":1700664241,"tknMode":15,"triggers":null,"trustedproxy":[],"version":"3.2.2-42-gb6460dfe3 Generic_x86_64"}}

Of course, streams are missing from this. To get a full configuration with all possible settings we recommend using the config_backup call instead.

Command used

mistCall '"config_backup": true'

Response

{"LTS":1,"authorize":{"local":true,"status":"OK"},"config_backup":{FULL_CONFIG}

This returns the full configurations as they would appear in your configuration file.

Building your own

Of course you can use the examples above to just implement the communication to MistServer in your project, but should you wish to build your own we recommend reading up on the API. We've tried to make it as clear & easy to use possible, but should you run into questions feel free to contact us.