TCP server plugin for tSIP
TCP server plugin listens for TCP connections and allows to send Lua scripts to tSIP (as commands) and passes text messages back from Lua scripts to TCP clients. It is expected to work with plaintext and newline-terminated ("\n") messages.
As a TCP keepalive plugin sends just newline to each client connection that was inactive in the last 60 seconds.
Installation
- copy TcpServer.dll from Release_Build directory to tSIP /phone subdirectory
- start tSIP, go to Settings/Phones (plugins) and double click TcpServer.dll on the list
- close tSIP - TcpServer.cfg would be created in /phone subdirectory next to TcpServer.dll
- change port number in config file if needed (default listen port = TCP 7778)
- copy server_util.lua and dkjson.lua (or equivalent) to /scripts subdirectory; assign server_util.lua to "on call state" and/or "on registration state" as needed; you may extend it for other events or replace it altogether using very own scheme for application reports/replies
Usage
- for testing PuTTy/KiTTy terminal can be used with "Raw" mode (important as using "Telnet" mode would send some unexpected bytes after connection generating Lua exception when executing first script)
- send newline-separated Lua scripts to tSIP; if script need to contain more than one statement, separate them with semicolons
- receive JSON replies/events
Example session (Lua scripts as commands, JSON values as replies/events):
local util = require("scripts.server_util"); util.report_call_state("INITIAL_CALL_REPORT") {"type":"call_state","state_text":"CLOSED","state":0,"tag":"INITIAL_CALL_REPORT","call_peer":"","call_incoming":0} Call("sip:music@iptel.org") {"type":"call_state","tag":"","state_text":"OUTGOING","call_incoming":0,"call_peer":"sip:music@iptel.org","state":2} {"type":"call_state","tag":"","state_text":"ESTABLISHED","call_incoming":0,"call_peer":"sip:music@iptel.org","state":6} Hangup() {"state_text":"CLOSED","state":0,"type":"call_state","call_peer":"","tag":"","call_incoming":0}
Notes
- example script (server_util.lua) is used both as script triggered by event ("on call state", "on registration state") and by the script sent from the client to request initial state report (if needed)
- if you are already using other script for required application event, you add there code like: local util = require("scripts.server_util"); util.report_call_state("OPTIONAL_TAG")
- while this example uses JSON to pass events and replies, this text is generated entirely inside Lua script and can be replaced e.g. with XML
- script can be extended to support other events (e.g. BLF state change) and/or additional event information (e.g. codec used by the call)
Source and binary
- 2022.04.10. Initial release: TcpServer_1_0_0.zip + scripts.zip.
https://github.com/tomek-o/tSIP-plugin-TcpServer
Back to tSIP softphone