forked from RTCEngine/coturn-cluster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
turn_rest_api.py
44 lines (29 loc) · 1.07 KB
/
turn_rest_api.py
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
35
36
37
38
39
40
41
42
# -*- coding: utf-8 -*-
# author: leeoxiang
import uuid
import hmac
import hashlib
import base64
import time
import argparse
def generate(server,ttype,transport,secret):
userid = uuid.uuid4().hex
username = '%d:%s' % (int(time.time()) + 24*3600, userid)
digest = hmac.digest(bytes(secret,'utf-8'),bytes(username,'utf-8'),hashlib.sha1)
credential = base64.b64encode(digest)
uri = '%s:%s:3478?transport=%s' % (ttype,server,transport)
return {
'username':username,
'uris':[uri],
'credential':credential
}
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--server', help='turn/stun server ip')
parser.add_argument('--type', help='iceServer type, stun or turn')
parser.add_argument('--transport', help='turn/sturn transport, udp or tcp')
parser.add_argument('--secret', help='coturn server static_secret')
args = parser.parse_args()
iceserver = generate(args.server,args.type,args.transport,args.secret)
print('iceServer == ')
print(iceserver)