From dbd2bdc89cd3c47a25ec7e869ee526f093b2e21f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 15 May 2007 14:28:12 +0000 Subject: [PATCH] Add jsapi example of new javascript FSAPI Gateway interface git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5185 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- scripts/api.js | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 scripts/api.js diff --git a/scripts/api.js b/scripts/api.js new file mode 100644 index 0000000000..3d8bf559b2 --- /dev/null +++ b/scripts/api.js @@ -0,0 +1,63 @@ +/* + * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * Copyright (C) 2005/2006, Anthony Minessale II + * + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application + * + * The Initial Developer of the Original Code is + * Anthony Minessale II + * Portions created by the Initial Developer are Copyright (C) + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * + * Anthony Minessale II + * + * + * api.js Demo javascript FSAPI Interface + * + * To use this script: + * 1) Put it in $prefix/scripts. (eg /usr/local/freeswitch/scripts) + * 2) Load mod_xml_rpc and point a browser to your FreeSWITCH machine. + * http://your.freeswitch.box:8080/api/jsapi?api.js + */ + +/* Other possible js commands */ +//env = request.dumpENV("text"); +//xmlenv = new XML(request.dumpENV("xml")); +//request.addHeader("js-text", "You were in a javascript script"); + + +if (session) { + request.write("Don't call me from the dialplan silly! I'm a web interface today.\n"); + consoleLog("err", "Invalid usage!\n"); + exit(); +} + +request.write("FreeSWITCH Command Portal"); +request.write("

FreeSWITCH Command Portal

"); +request.write("
"); +request.write(""); +request.write("


"); + +if ((command = request.getHeader("command"))) { + cmd_list = command.split(" ", 2); + + if ((reply = apiExecute(cmd_list[0], cmd_list[1]))) { + request.write("Command Result
" + reply + "\n
"); + } +} + +