PROTO_WS module
Admin Guide
Section titled “Admin Guide”Overview
Section titled “Overview”The WebSocket protocol (RFC 6455) provides an end-to-end full-duplex communication channel between two web-based applications. This allows WebSocket enabled browsers to connect to a WebSocket server and exchange any type of data. RFC 7118 provides the specifications for transporting SIP messages over the WebSocket protocol.
The proto_ws module is transport module that provides communication over the WebSocket protocol. This module is fully compliant with the RFC 7118, thus allowing browsers to act as SIP clients for the OpenSIPS proxy.
The current implementation acts both as WebSocket server and client, thus it can accept connections from WebSocket clients and can also initiate connections to another WebSocket server. After the connection is established, messages can flow in both directions.
OpenSIPS supports the following WebSocket operations:
- text and binary - can both send and receive WebSocket messages that contain text or binary body
- close - messages used to safely close the WebSocket communication using a 2-messages handshake
- ping - responds with pong messages. There is no mechanism to trigger ping messages.
- pong - sent when a ping message is received. OpenSIPS, absorbes the pong messages received.
Once loaded, you will be able to define WebSocket listeners in your script. To
add a listener, you have to add its IP, and optionally the listening port,
after the mpath parameter, similar to this
example:
...mpath=/path/to/modules...socket=ws:127.0.0.1 # change with the listening IPsocket=ws:127.0.0.1:5060 # change with the listening IP and port...Dependencies
Section titled “Dependencies”OpenSIPS Modules
Section titled “OpenSIPS Modules”The following modules must be loaded before this module:
- None.
External Libraries or Applications
Section titled “External Libraries or Applications”The following libraries or applications must be installed before running OpenSIPS with this module loaded:
- None.
Exported Parameters
Section titled “Exported Parameters”ws_port (integer)
Section titled “ws_port (integer)”The default port to be used for all WS related operation. Be careful as the default port impacts both the SIP listening part (if no port is defined in the WS listeners) and the SIP sending part (if the destination WS URI has no explicit port).
If you want to change only the listening port for WS, use the port option in the SIP listener defintion.
Default value is 80.
...modparam("proto_ws", "ws_port", 8080)...ws_send_timeout (integer)
Section titled “ws_send_timeout (integer)”Time in milliseconds after a WebSocket connection will be closed if it is not available for blocking writing in this interval (and OpenSIPS wants to send something on it).
Default value is 100 ms.
...modparam("proto_ws", "ws_send_timeout", 200)...ws_max_msg_chunks (integer)
Section titled “ws_max_msg_chunks (integer)”The maximum number of chunks in which a SIP message is expected to arrive via WebSocket. If a received packet is more fragmented than this, the connection is dropped (either the connection is very overloaded and this leads to high fragmentation - or we are the victim of an ongoing attack where the attacker is sending very fragmented traffic in order to decrease server performance).
Default value is 4.
...modparam("proto_ws", "ws_max_msg_chunks", 8)...trace_destination (string)
Section titled “trace_destination (string)”Trace destination as defined in the tracing module. Currently the only tracing module is proto_hep. Network events such as connect, accept and connection closed events shall be traced along with errors that could appear in the process. For each connection that is created an event containing information about http request and reply belonging to web socket protocol handshake and network layer information shall be sent.
Default value is none(not defined).
...modparam("proto_hep", "hep_id", "[hep_dest]10.0.0.2;transport=tcp;version=3")
modparam("proto_ws", "trace_destination", "hep_dest")...trace_on (int)
Section titled “trace_on (int)”This controls whether tracing for ws is on or not. You still need to define trace destinationin order to work, but this value will be controlled using mi function mi ws trace.
...modparam("proto_ws", "trace_on", 1)...trace_filter_route (string)
Section titled “trace_filter_route (string)”Define the name of a route in which you can filter which connections will be trace and which connections won’t be. In this route you will have information regarding source and destination ips and ports for the current connection. To disable tracing for a specific connection the last call in this route must be drop, any other exit mode resulting in tracing the current connection ( of course you still have to define a trace destination and trace must be on at the time this connection is opened.
...modparam("proto_ws", "trace_filter_route", "ws_filter").../* all ws connections will go through this route if tracing is activated * and a trace destination is defined */route[ws_filter] { ... /* all connections opened from/by ip 1.1.1.1:8000 will be traced on interface 1.1.1.10:5060(opensips listener) all the other connections won't be */ if ( $si == "1.1.1.1" && $sp == 8000 && $socket_in(ip) == "1.1.1.10" && $socket_in(port) == 5060) exit; else drop;}...require_origin (int)
Section titled “require_origin (int)”Controls whether the module should require the Origin header or not.
...modparam("proto_ws", "require_origin", no)...Exported MI Functions
Section titled “Exported MI Functions”ws_trace
Section titled “ws_trace”Name: ws_trace
Parameters:
- trace_mode(optional): set ws tracing on and off. This parameter
can be missing and the command will show the current tracing
status for this module( on or off );
Possible values:
- on
- off
MI FIFO Command Format:
opensips-cli -x mi ws_trace onFrequently Asked Questions
Section titled “Frequently Asked Questions”Q: Can OpenSIPS act as a WebSocket client?
Yes, starting with OpenSIPS 2.2, it can act as a WebSocket client.
Q: Does OpenSIPS support WebSocket message fragmentation?
No, WebSocket fragmentation mechanism is not supported.
Contributors
Section titled “Contributors”By Commit Statistics
Section titled “By Commit Statistics”Top contributors by DevScore(1), authored commits(2) and lines added/removed(3)
| # | Name | DevScore | Commits | Lines++ | Lines— |
|---|---|---|---|---|---|
| 1. | Razvan Crainea (@razvancrainea) | 95 | 49 | 3920 | 733 |
| 2. | Ionut Ionita (@ionutrazvanionita) | 21 | 14 | 592 | 112 |
| 3. | Bogdan-Andrei Iancu (@bogdan-iancu) | 19 | 17 | 59 | 31 |
| 4. | Liviu Chircu (@liviuchircu) | 14 | 11 | 80 | 82 |
| 5. | Stefan Darius (@dariusstefan) | 11 | 5 | 380 | 84 |
| 6. | Vlad Patrascu (@rvlad-patrascu) | 7 | 5 | 54 | 44 |
| 7. | Maksym Sobolyev (@sobomax) | 6 | 4 | 7 | 7 |
| 8. | Vlad Paiu (@vladpaiu) | 4 | 2 | 3 | 1 |
| 9. | Dan Shields | 3 | 1 | 4 | 2 |
| 10. | Nick Altmann (@nikbyte) | 3 | 1 | 2 | 2 |
All remaining contributors: James Stanley, Peter Lemenkov (@lemenkov), Julián Moreno Patiño.
(1) DevScore = author_commits + author_lines_added / (project_lines_added / project_commits) + author_lines_deleted / (project_lines_deleted / project_commits)
(2) including any documentation-related commits, excluding merge commits
(3) ignoring whitespace edits, renamed files and auto-generated files
By Commit Activity
Section titled “By Commit Activity”| # | Name | Commit Activity |
|---|---|---|
| 1. | Stefan Darius (@dariusstefan) | Jun 2026 - Jul 2026 |
| 2. | Razvan Crainea (@razvancrainea) | Mar 2015 - Jun 2026 |
| 3. | Bogdan-Andrei Iancu (@bogdan-iancu) | Mar 2017 - Mar 2026 |
| 4. | James Stanley | Mar 2023 - Mar 2023 |
| 5. | Maksym Sobolyev (@sobomax) | Feb 2017 - Feb 2023 |
| 6. | Liviu Chircu (@liviuchircu) | Mar 2015 - Apr 2022 |
| 7. | Vlad Patrascu (@rvlad-patrascu) | May 2017 - Oct 2021 |
| 8. | Dan Shields | Aug 2021 - Aug 2021 |
| 9. | Nick Altmann (@nikbyte) | May 2021 - May 2021 |
| 10. | Peter Lemenkov (@lemenkov) | Jun 2018 - Jun 2018 |
All remaining contributors: Ionut Ionita (@ionutrazvanionita), Julián Moreno Patiño, Vlad Paiu (@vladpaiu).
(1) including any documentation-related commits, excluding merge commits
Documentation
Section titled “Documentation”Contributors
Section titled “Contributors”Last edited by: Razvan Crainea (@razvancrainea), Vlad Patrascu (@rvlad-patrascu), Bogdan-Andrei Iancu (@bogdan-iancu), Peter Lemenkov (@lemenkov), Liviu Chircu (@liviuchircu), Ionut Ionita (@ionutrazvanionita).
License
Section titled “License”All documentation files (i.e. .md extension) are licensed under the Creative Common License 4.0