NkMEDIA API External Interface

October 17, 2016 ยท View on GitHub

This documente describes the currently supported External API commands for core NkMEDIA. See the API Introduction for an introduction to the interface, and Core Events for a description of available events.

All commands must have

{
	class: "media",
	subclass: "session"
}

See also each backend and plugin documentation:

Also, for Erlang developers, you can have a look at the command syntax specification and command implementation.

create

Performs the creation of a new media session. The mandatory type field defines the type of the session. Currently, the following types are supported, along with the necessary plugin or plugins that support them.

Type|Plugins ---|---|--- p2p|- echo|[nkmedia_janus](janus.md#echo, fs.md#echo), nkmedia_fs, nkmedia_kms proxy|nkmedia_janus publish|nkmedia_janus, nkmedia_kms listen|nkmedia_janus, nkmedia_kms park|nkmedia_fs, nkmedia_kms mcu|nkmedia_fs bridge|nkmedia_fs, nkmedia_kms

See each specific plugin documentation to learn about how to use it and supported options.

Common fields for the request are:

FieldDefaultDescription
type(mandatory)Session type
wait_replyfalseWait for the offer or answer
offer{}Offer for the session, if available
no_offer_trickle_icefalseForces consolidation of offer candidates in SDP
no_answer_trickle_icefalseForces consolidation of answer candidates in SDP
trickle_ice_timeout5000Timeout for Trickle ICE before consolidating candidates
sdp_type"webrtc"Type of offer or answer SDP to generate (webrtc or rtp)
backend(automatic)Forces a specific backend for the request (nkmedia_janus, nkmedia_fs or nkmedia_kms)
master_id(none)Makes this session a slave of this master session (see bellow)
set_master_answerfalseIf true, this slave session will set its answer to master
stop_after_peertrueFor master or slave sessions, stop if peer stops
wait_timeout60Timeout for sessions in wait state
ready_timeout86400Timeout for sessions in ready (answer is already set) state
subscribetrueSubscribe to session events. Use false to avoid automatic subscription.
event_body{}Body to receive in all automatic events.

If you use wait_reply=true, the backend will supply the answer (in case you supplied an offer), or the offer (if you don't supply one, you must then send the answer to the backend). Otherwhise, you must use the get_offer or get_answer commands.

Sample

{
	class: "media",
	subclass: "session",
	cmd: "create",
	data: {
		type: "echo",
		backend: "nkmedia_janus",
		wait_reply: true
		offer: {
			sdp: "v=0.."
		}
	}
	tid: 1
}

-->

{
	result: "ok",
	data: {
		session_id: "54c1b637-36fb-70c2-8080-28f07603cda8",
		answer: {
			sdp: "v=0..."
		}
	},
	tid: 1
}

Depending on the session type and backend, other fields can be used. Please refer to each backend documentation, for example:

FieldDescription
room_idRoom to use
publisher_idPublisher to connect to
layoutMCU layout to use
loopsLoops to repeat in the player
uriURI to use for the player
mute_audioMute the audio
mute_videoMute the video
mute_dataMute the data channel
bitrateBitrate to set

Events

When creating a session, the user connection is automatically subscribed to receive all events related to the session (unless subscribe=false is used).

Master/Slave sessions

When you start a session using a master_id key poiting to another existing session, this session will become a slave of that master session. This means:

  • When any of the session stops, the other stops also (unless stop_after_peer=false is used).
  • When the slave session gets an answer it will be automatically set at the master (if set_master_answer=true).
  • ICE candidates are routed among sessions as needed automatically.

Tricle ICE

All webrtc SDPs are supposed to have ICE candidates inside by default. If the candidates are not included and trickle ICE must be used, the trickle_ice parameter of the offer or answer must be set to true. Some backends will not use trickle ICE (Freeswitch does not support it, and Janus only for the client side), others they will always use tricle ICE (like Kurento). You can use the no_offer_trickle_ice and no_answer_trickle_ice parameters to force the consolidation of candidates in the server-generated SDP. NkMEDIA will then receive the candidates and insert them in the SDP before offering it to the client or the backend.

destroy

Destroys a started session.

Field|Default|Description ---|---|---|--- session_id|(mandatory)|Session Id

set_answer

When the started session's type requires you to supply an answer (because the backend already generated the offer), you must use this API to set the session's answer.

FieldDefaultDescription
session_id(mandatory)Session Id
answer(mandatory)Answer for the session

Sample

{
	class: "media",
	subclass: "session",
	cmd: "set_answer",
	data: {
		answer: {
			"sdp": "..."
		}
	}
	tid: 1
}

-->

{
	result: "ok",
	tid: 1
}

get_offer

Waits for the session offer to be generated

Sample

{
	class: "media",
	subclass: "session",
	cmd: "get_offer",
	tid: 1
}

-->

{
	result: "ok",
	data: {
		offer: {
			"sdp": "..."
		}
	}
	tid: 1
}

get_answer

Waits for the session answer to be generated

get_info

Gets extended information about a specific session

Sample

{
	class: "media",
	subclass: "session",
	cmd: "get_info",
	data: {
		session_id: "54c1b637-36fb-70c2-8080-28f07603cda8"
	}
	tid: 1
}

-->

{
	result: "ok",
	data: {
		backend: "nkmedia_fs",
	    type: "echo",
	    type_ext: {},
	    user_id: "user@domain.com",
	    user_session: "1f0fbffa-3919-6d40-03f5-38c9862f00d9",
	    ...
	},
	tid: 1
}

get_list

Gets a list of all current sessions

Sample

{
	class: "media",
	subclass: "session",
	cmd: "get_list",
	tid: 1
}

-->

{
	result: "ok",
	data: [
		"54c1b637-36fb-70c2-8080-28f07603cda8"
	],
	tid: 1
}

update_media

Some backends allow you to modify the media session characteristics in real time. See each backend documentation. Typical fields are:

FieldSampleDescription
mute_audiofalseMute the audio
mute_videofalseMute the video
mute_datafalseMute the data channel
bitrate0Bitrate to use (kbps, 0 for unlimited)

Sample

{
	class: "media",
	subclass: "session",
	cmd: "update_media",
	data: {
		session_id: "54c1b637-36fb-70c2-8080-28f07603cda8",
		mute_audio: true,
		bitrate: 100000
	}
	tid: 1
}

set_type

Some backends allow to change the session type once started. See each backend documentation. Fields session_id and type are mandatory.

Sample

{
	class: "media",
	subclass: "session",
	cmd: "set_type",
	data: {
		session_id: "54c1b637-36fb-70c2-8080-28f07603cda8",
		type: "listen",
		publisher_id: "9dedf3cf-3da7-883c-6790-38c9862f00d9"
	}
	tid: 1
}

recorder_action

Some backends allow to record the session. See each backend documentation.

Sample

{
	class: "media",
	subclass: "session",
	cmd: "recorder_action",
	data: {
		session_id: "54c1b637-36fb-70c2-8080-28f07603cda8",
		action: "start"
	}
	tid: 1
}

player_action

Some backends allow to control a play session. See each backend documentation.

Sample

{
	class: "media",
	subclass: "session",
	cmd: "player_action",
	data: {
		session_id: "54c1b637-36fb-70c2-8080-28f07603cda8",
		action: "get_position"
	}
	tid: 1
}

-->

{
	result: "ok",
	data: {
		position: 50000
	},
	tid: 1
}

room_action

Some backends allow to control the room this session belongs to. See each backend documentation.

Sample

{
	class: "media",
	subclass: "session",
	cmd: "room_action",
	data: {
		session_id: "54c1b637-36fb-70c2-8080-28f07603cda8",
		action: "layout"
		data: {
			layout: "2x2"
		}
	}
	tid: 1
}

set_candidate

When the client sends an SDP offer or answer without candidates (and with the field trickle_ice=true), it must use this command to send candidates to the backend. The following fields are mandatory:

FieldSampleDescription
session_id-Session id this candidate refers to
sdpMid"audio"Media id
sdpMLineIndex0Line index
candidate"candidate..."Current candidate

set_candidate_end

When the client has no more candidates to send, it should use this command to inform the server.