Home / Docs Center / Device User Guides / webrtcIntercomCameraDevelopment Guide
webrtcIntercomCameraDevelopment Guide
Project: Device User Guide | page_id: 975
- The camera exposes port 9001 as the HTTPS interface
- The camera exposes port 9000 as the HTTP interface
- WebRTC playback is achieved by calling the following four HTTP POST interfaces
- The base address
deviceUrlused by the interfaces in the code: for LAN access use https://[IP]/9001/ or http://[IP]/9000/
For public network access use: https://live.xstrive.com/[serial number]/webrtc/
- connect interface
Method: POST
Parameters: none
Returns: sessionID (in the "Session-ID" request header)
Calling this interface allocates a unique SessionID. All subsequent interface calls must carry this generated SessionID
JS call example:
function send_post_connect()
{
var xhr = new XMLHttpRequest();
const loc = deviceUrl;
console.log("send post connect: " + loc);
xhr.open("POST", '' + loc + 'connect', true);
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE &&
this.status === 200) {
const sessid = xhr.getResponseHeader("Session-ID");
console.log("connect: session: %s", sessid);
/* Save the session ID */
session_id = sessid;
pc.createOffer(offerOptions)
.then(function (desc) {
console.log("got local description: %s", desc.type);
pc.setLocalDescription(desc).then(() => {
const sd = pc.localDescription;
const json = JSON.stringify(sd);
retryCount = 0;
send_post_sdp(json);
},
function (error) {
console.log("setLocalDescription: %s",
error.toString());
});
})
.catch(function(error) {
console.warn("Failed to create session description: %s",
error.toString());
});
}
}
xhr.send();
}
- offersdp interface
Method: POST
Parameters: none
Returns: sessionID (in the "Session-ID" request header) and sdp (in the body)
Calling this interface returns the offer sdp and a sessionID
JS call example:
function send_post_connect()
{
var xhr = new XMLHttpRequest();
const loc = self.location;
console.log("send post connect: " + loc);
xhr.open("POST", '' + loc + 'connect/offerer', true);
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE &&
(this.status === 200 || this.status === 201)) {
const sessid = xhr.getResponseHeader("Session-ID");
console.log("connect: new session: '%s' (%d %s)",
sessid, this.status, this.statusText);
/* Save the session ID */
session_id = sessid;
handle_offer(xhr.response);
}
}
}
xhr.send();
}
- sdp interface
Parameters: local sdp (offer)
Returns: remote sdp (answer)
Calling this interface sends the local sdp information (offer) to the camera and receives the sdp value (answer) returned by the camera
JS call example:
function send_post_sdp(descr)
{
var xhr = new XMLHttpRequest();
const loc = deviceUrl;
console.log("send post sdp: " + loc);
xhr.open("POST", '' + loc + 'sdp', true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Session-ID", session_id);
xhr.onreadystatechange = function() {
console.log("onreadystatechange:" + this.status);
if (this.readyState === XMLHttpRequest.DONE &&
this.status === 200) {
retryCount = maxRetryCount;
console.log("post sdp: 200 ok");
const descr = JSON.parse(xhr.response);
console.log("remote description: type='%s'", descr.type);
pc.setRemoteDescription(descr).then(() => {
console.log('set remote description -- success');
}, function (error) {
console.warn("setRemoteDescription: %s",
error.toString());
disconnect_call();
});
}
else if (this.readyState === XMLHttpRequest.DONE && this.status === 401){
retry_send_sdp(descr, xhr);
}
}
xhr.send(descr);
}
- candidate interface
Parameters: hole punching information returned by the iceServer
Returns: none
Calling this interface sends the p2p connection information returned by the iceServer to the camera, so that the ICE framework can establish the p2p connection
JS call example
function send_candidate(json)
{
var xhr = new XMLHttpRequest();
const loc = deviceUrl;
xhr.open("POST", '' + loc + 'candidate', true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Session-ID", session_id);
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE &&
this.status !== 200) {
/* todo: print warning and close call */
}
}
xhr.send(json);
}
- disconnect interface
Parameters: sessionId
Returns: none
Disconnect from the server and release resources
JS call example
function disconnect_call()
{
console.log("Disconnecting call");
if(localStream){
localStream.getTracks().forEach(track => track.stop());
}
if (pc) {
pc.close();
pc = null;
}
disconnectButton.disabled = true;
connectButton.disabled = false;
if (session_id) {
// send a message to the server
var xhr = new XMLHttpRequest();
xhr.open("POST", '' + deviceUrl + 'disconnect', true);
xhr.setRequestHeader("Session-ID", session_id);
xhr.send();
}
session_id = null;
}
The sample code of the js interface calls can be obtained by opening the web page https://[device IP]:9001/ in Chrome, then right-clicking and selecting View Source.
For the Android sample code, please contact us.
Didn't find what you need?Contact us,Talk to our engineers directly.