freeswitch/docs/JavaScript.txt

49 lines
1.1 KiB
Plaintext
Raw Normal View History

Session Methods
=======================================
session.streamFile
Usage:
session.streamFile(file, timer, callback);
file = Path to the file to play (ie /tmp/file.wav)
timer = Timer to use for async mode. (optional)
callback = Which function to fire when a dtmf digit is pressed. (optional)
Callback return values and meanings:
seek:ms - +1000 or -1000 will seek 1000ms forward or backwards, seek 0 will start the file over.
speed: - +1,-1 or 0 for normal speed. (valid ranges are +1,+2, 0 or -1,-2)
pause: - toggles pause and play modes on the file.
You can also return arbitrary values and act on them as you
wish. In our example we return "hangup" when the caller
press the * key on the keypad.
Example:
function on_dtmf(digits)
{
if (digits == "3") {
return "seek:+1000";
}
if (digits == "1") {
return "seek:-1000";
}
if (digits == "*") {
return "hangup";
}
}
session.answer();
while(session.state == "CS_EXECUTE") {
allDigits = "";
return_value = session.streamFile("/tmp/demo.wav", "", "on_dtmf");
if (return_value == "hangup") {
session.hangup(); // or break;
}
}