Record registers on RedisΒΆ

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from redis import Redis
from jaspion import Jaspion


# Freeswitch data to connection
freeswitch = {"host": "127.0.0.1", "password": "ClueCon", "port": 8021}

# Redis data to connection
redis = {"host": "127.0.0.1", "port": 6379}

# Instance of Jaspion and Redis conn
app = Jaspion(**freeswitch)
conn = Redis(**redis)


# Save all register in redis with expires of sip message.
@app.handle("sofia::register")
def register(event):
    key = "registers:%s" % event["call-id"]
    ttl = int(event["expires"])
    conn.hmset(key, event)
    conn.expire(key, ttl)


# Exclude redis register if unregister is recived
@app.handle("sofia::unregister")
def unregister(event):
    key = "registers:%s" % event["call-id"]
    conn.delete(key)


if __name__ == "__main__":
    # Start Jaspion
    app.run()