You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/event.md
+24-7Lines changed: 24 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,45 @@
1
1
# OpenSIPS Python Packages - Event Interface
2
2
3
-
This package can be used to subscribe to OpenSIPS Event Interface events.
3
+
This package can be used to subscribe to OpenSIPS events.
4
4
5
5
## Supported backend protocols
6
6
7
7
The following event transport protocols are supported:
8
-
*`datagram` - uses either UDP or UNIX datagram to receive notifications for subscribed events. If using UDP, the `ip` and `port` parameters are required. If using UNIX datagram, the `socket_path` parameter is required.
9
-
*`stream` - uses TCP to communicate with the Event Interface. Requires the `ip` and `port` parameters to be set.
8
+
*`datagram` (Default) - uses either UDP or UNIX datagram to receive notifications for subscribed events. By default, the UDP protocol is used with the `ip` and `port` parameters set to `127.0.0.1` and `50060` respectively, but you can tune them to your needs.
9
+
To use the UNIX datagram, set the `socket_path` parameter.
10
+
*`stream` - uses TCP to communicate with the Event Interface. Default values for `ip` and `port` are `127.0.0.1` and `50060` respectively, but you can change them as needed.
10
11
11
12
## How to use
12
13
13
-
To instantiate the `OpenSIPSEvent` class, you need to provide a MI connector, the backend protocol and the required parameters in a key-value format. Then `subscribe` and `unsubscribe` methods can be used to manage the subscriptions.
14
+
To subscribe to events, you must instantiate an `OpenSIPSEventHandler`. This class can be used to subscribe and unsubscribe from events. It uses an `OpenSIPSMI` object to communicate with the OpenSIPS MI interface. By default, a MI connector is created with the `fifo` type, but you can set it as a parameter in the constructor. As said before, the default transport protocol is `datagram`, but you can change it by setting the `_type` parameter.
15
+
16
+
Next step is to create an `OpenSIPSEvent` object. This can be done by calling the `subscribe` method of the `OpenSIPSEventHandler` object or by creating an `OpenSIPSEvent` object directly. The `subscribe` method will return an `OpenSIPSEvent` object.
17
+
18
+
To unsubscribe from an event, you can call the `unsubscribe` method of the `OpenSIPSEvent` object or the `unsubscribe` method of the `OpenSIPSEventHandler` object.
14
19
15
20
```python
21
+
from opensips.mi import OpenSIPSMI, OpenSIPSMIException
22
+
from opensips.event import OpenSIPSEvent, OpenSIPSEventException
0 commit comments