After building Sippet for your platform, you will find an executable named
sippet_phone_v8_shell
in the output directory.
When you run it without parameters, you might get a shell line the following:
Sippet shell (V8 version 4.2.29)
>
The iterative shell offers a Phone object, which you can instantiate as follows
var phone = sippet.Phone();
Before using the Phone object, it has to be initialized. The simplest initialization is the following:
phone.init();
But you can pass other configurations:
var settings = {
// disable DTLS transport while streaming
disable_encryption: true,
ice_servers: [
// a simple STUN server
{ uri: "stun:stun.l.google.com:19302" },
// a TURN server for port allocations
{
uri: "turn:hello.com?transport=tcp",
username: "test",
password: "pass"
}
]
};
phone.init(settings);
// Phone state:
// 0 = offline
// 1 = connecting
// 2 = online
console.log(String(phone.state));
Full list of Phone events.
phone.on('loginCompleted', function(state_code, status_text){
/* Your code here */
});
phone.on('incomingCall', function(call){
/* Your code here */
});
phone.on('callRinging', function(call){
/* Your code here */
});
phone.on('callEstablished', function(call){
/* Your code here */
});
phone.on('callHungUp', function(call){
/* Your code here */
});
phone.on('callError', function(status_code, status_text, call){
/* Your code here */
});
phone.on('networkError', function(error_code){
/* Your code here */
});
Now, you may want to login before receiving and making calls.
var account = {
username: "test",
password: "1234",
host: "sip:host.com;transport=tcp" // Registrar SIP-URI
};
phone.login(account);
In order to call someone at the same Registrar server you have made login, execute:
var call = phone.makeCall("1234");
In the example above, a call will be initiated to
sip:1234@host.com;transport=tcp
.
The following properties are available:
// Call Type:
// 0 = incoming,
// 1 = outgoing
console.log(String(call.type));
// Call State:
// 0 = calling,
// 1 = ringing,
// 2 = established,
// 3 = hungup,
// 4 = error
console.log(String(call.state));
// Call full URI
// "sip:dest@host.com"
console.log(call.uri);
// Call destination name
// "dest"
console.log(call.name);
// Time when the call was created
console.log(call.creationTime);
// Time when the call was established
console.log(call.startTime);
// Time when the call was finished
console.log(call.endTime);
// Call duration in seconds
console.log(String(call.duration));
call.answer();
call.sendDtmf("1234");
call.hangup();
phone.hangupAll();
phone.logout();