The present version is a draft and currently not available to use. The final version will come soon.
Getting started
Make sure you've read What's in it for you for more info on how to register and start testing APIs.
Authentication
The API follows the KPN Store API Authentication Standard to secure the API. It includes the use of OAuth 2.0 client_id
and client_secret
to receive an access token.
Go to the Authentication tab on top of this page to find out how to:
- Authenticate to an API using cURL.
- Authenticate to an API on Swaggerhub.
- Import Open API Specifications (OAS), also called Swagger files into Postman.
How to...
Add the JavaScript API
^^Example^^
<head>
<script src="https://api4.apidaze.io/javascript/releases/APIdaze-0.2.6.min.js"></script>
</head>
Initialize the APIdaze client
Just create a CLIENT
instance with parameters.
^^Example^^
var client = new APIdaze.CLIENT(
{
type: "webrtc",
apiKey: "d3adb33f",
onReady: function() {
// Put your JavaScript code
},
onDisconnected: function() {
// Put your JavaScript code
},
onAudiostats: function(event) {
// Put your JavaScript code
}
});
type
: Specify the connection type (webrtc
,flash
orauto
, which defaults toflash
).debug
:true
orfalse
defaults tofalse
.apiKey
: Your API key.onReady
: A JavaScript function that gets called when the connection is setup.onDisconnected
: A JavaScript function that gets called when the connection to the server gets down.onAudiostats
: A JavaScript function that gets called every five second during a call and contains information about the audio quality of the call. Theevent
parameter object structure is given hereafter as a sample.
^^Example^^
var eventsample =
{
type: "audiostats",
data: {
duration: "00:01:05", // Total call duration
opackets: "3238 ", // Packets sent to server
olostpackets: "0", // Packets sent to server and lost on the way
ipackets: "2981 ", // Packets received from server
ilostpackets: "0", // Packets sent from server and lost on the way
rtt: "0.033000" // Round Trip Time to server in seconds (also called "ping time")
}
};
Place a call from your web pages
Just call the call
function on the previously created CLIENT
object. Add any parameter along with your listener functions that will let you handle in-call events. All the parameters set as the first argument will be forwarded to your ExternalScript
URL as HTTP parameters, therefore allowing to control the call.
In order to allow the call to the number 0123456789
, your ExternalScript
must return the following XML to APIdaze:
^^Example^^
<document>
<work>
<dial>
<number>0123456789</number>
</dial>
</work>
</document>
In the following example, the number to call is sent in the my_parameter_that_contains_a_number
, and a string that identifies the web session is sent in the my_web_session_id
parameter.
^^Example^^
var call = client.call(
{
my_parameter_that_contains_a_number: "0123456789",
my_web_session_id: "3d1n1de32bge65hbokapdm"
},
{
onRinging: function() {
// Put your JavaScript code
},
onAnswer: function() {
// Put your JavaScript code
},
onHangup: function() {
// Put your JavaScript code
}
}
);
Object
: A set of attributs and values sent as HTTP parameters to yourExternalScript
URL.onRinging: function() {}
: A function that gets called when the remote end is ringing.onAnswer: function() {}
: A function that gets called when the call has been answered.onHangup: function() {}
: A function that gets called when the call is hung up.
While in a call, you can call these two methods on the call
object to turn on and off your audio input.
^^Example^^
call.stopLocalAudio(); // Stop sending your audio input
call.startLocalAudio(); // Start sending your audio input
Join a conference room, add text and video chat to your web pages
Just call the joinroom
function on the previously created CLIENT
object. Add the room name your want to join along with your nickname for the room and listener functions as parameters. All the parameters set as the first argument will be forwarded to your ExternalScript
URL as HTTPparameters, therefore allowing to open access to the room.
When calling joinroom
, your ExternalScript
receives an HTTP request with the following parameters:
- roomName.
- nickName.
- …
In order to grant access to the room named myroom
, your ExternalScript
must return the following XML to APIdaze:
^^Example^^
<document>
<work>
<conference>myroom</conference>
</work>
</document>
On the JavaScript side, here is what you would display:
^^Example^^
var room = client.joinroom(
{
roomName: "myroom", // Mandatory
nickName: "nick" // Mandatory
},
{
onConfbridgejoin: function(event) {
console.log("Confbridge Join Event : " + event.data);
// Put your JavaScript code
},
onConfbridgeleave: function(event) {
console.log("Confbridge Leave Event : " + event.data);
// Put your JavaScript code
},
onConfbridgemembers: function(event) {
console.log("Members list : " + event.data);
// Put your JavaScript code
},
onConfbridgetalking: function(event) {
var jsondata = JSON.parse(event.data);
console.log("Channel " + jsondata.channel + " in room " + jsondata.room + " talking status : " + jsondata.talkingstatus);
// Put your JavaScript code
},
onConfbridgetextmessage: function(event) {
console.log("Received text : " + event.data);
// Put your JavaScript code
}
}
);
Object
: A set of attributes and values sent as HTTP parameters to yourExternalScript
URL.nickName
androomName
are mandatory.onConfbridgejoin: function() {}
: A function that gets called when someone joins the room.onConfbridgeleave: function() {}
: A function that gets called when someone leaves the room.onConfbridgemembers: function() {}
: A function that gets called when you enter the room.onConfbridgetalking: function() {}
: A function that gets called when someone is talking.onConfbridgetextmessage: function() {}
: A function that gets called when receiving text from one of the room members. More on this function in the next section.
More on rooms: text and video chat
The room
JavaScript object brings methods and handlers that allows you to easily add text and video chat to your webpage.
Adding text chat
Sending a text message to the room members :
^^Example^^
room.sendMessage("public", "anyone", "Hi everybody !");
Handling text messages from the room members is just a matter of putting your JavaScript code in the onConfbridgetextmessage
handler.
Join the room in video
Call the joinInVideo
method on an existing room to activate video.
^^Example^^
room.joinInVideo(
{
videoContainerId: "remotevideos", // Optional
mode: "sendrecv" // "sendrecv" or "recvonly". Defaults to "sendrecv".
},
{
onConfbridgevideomembers: function(event) {
console.log("Video members: " + JSON.parse(event.data));
// Put your JavaScript code
},
onConfbridgenewssrc: function(event) {
console.log("New user in video bridge : " + event.data);
// Put your JavaScript code
},
onConfbridgeleftssrc: function(event) {
console.log("User left video bridge : " + event.data);
// Put your JavaScript code
}
}
);
videoContainerId
: The DOM id of the element that contains the video elements in the HTML page. Will be created automatically if not set.mode
: Valid values are “sendrecv” (to send and receive video streams) and “recvonly” (won’t send your own video stream to the members). The default value is “sendrecv”.onConfbridgevideomembers: function() {}
: Returns the list of video peers in the room. This function is called when you join the room in video (after calling thejoinInVideo
method).onConfbridgenewssrc: function() {}
: A function that gets called when a new video stream coming from the room has been detected.onConfbridgeleftssrc: function() {}
: A function that gets called when a user stopped sending his video stream to the room.
While in a video call, you can call these two methods on the room object to turn on and off sending your video stream to the peers. Note that audio and text chat will still remain available.
^^Example^^
room.stopLocalVideo(); // Stop sending your video stream to the room
room.startLocalVideo(); // Start sending your video stream to the room
HTTP response headers
The following tables display the standard response headers that are returned with each API response:
Standard response field name | Description |
---|---|
sunset | This field will be populated with the deprecation details. By default the value is n/a. |
api-version | Indicates the API version you have used. |
quota-interval | Used to specify an integer (for example, 1, 2, 5, 60, and so on) that will be paired with the quota-time-unit you specify (minute, hour, day, week, or month) to determine a time period during which the quota use is calculated. For example, an interval of 24 with a quota-time-unit of hour means that the quota will be calculated over the course of 24 hours. |
quota-limit | Number of API calls an user can make within a given time period. If this limit is exceeded, the user will be throttled and API requests will fail. |
quota-reset-UTC | All quota times are set to the Coordinated Universal Time (UTC) time zone. |
quota-time-unit | Used to specify the unit of time applicable to the quota. For example, an interval of 24 with a quota-time-unit of hour means that the quota will be calculated over the course of 24 hours. |
quota-used | Number of API calls made within the quota. |
strict-transport-security | The HTTP Strict-Transport-Security (HSTS) response header lets a website tell browsers that it should only be accessed using HTTPS, instead of using HTTP. All present and future subdomains will be HTTPS for a maximum of 1 year and access is blocked to pages or sub domains that can only be served over HTTP including HSTS preload lists of web browsers. Strict-Transport-Security: max-age=31536000; includeSubDomains; preload. |
Access control field name | Description |
access-control-allow-credentials | Tells browsers whether to expose the response to frontend JavaScript when the request's credentials mode (Request.credentials) is include. When a request's credentials mode (Request.credentials) is include, browsers will only expose the response to frontend JavaScript if the Access-Control-Allow-Credentials value is true. Boolean. |
access-control-allow-origin | Indicates whether the response can be shared with requesting code from the given origin. |
access-control-allow-headers | Used in response to a pre-flight request which includes the Access-Control-Request-Headers to indicate which HTTP headers can be used during the actual request. |
access-control-max-age | Indicates how long the results of a pre-flight request (that is the information contained in the Access-Control-Allow-Methods and Access-Control-Allow-Headers headers) can be cached. |
access-control-allow-methods | Indicates which HTTP methods are allowed on a particular endpoint for cross-origin requests.For example: GET, PUT, POST, DELETE. |
content-length | The Content-Length entity header indicates the size of the entity-body, in bytes, sent to the recipient. |
content-type | The Content-Type entity header the client what the content type of the returned content actually is. |