-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotengine.py
More file actions
55 lines (38 loc) · 1.15 KB
/
dotengine.py
File metadata and controls
55 lines (38 loc) · 1.15 KB
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
43
44
45
46
47
48
49
50
51
52
53
# -*- coding: utf-8 -*-
# author: notedit
import time
import random
import requests # requests is great why not use this
import jwt # jwt is perfact why not use it
dot_engine_api_url = 'https://janus.dot.cc/api/'
class DotEngine(object):
def __init__(self,appkey,app_secret,test_mode=False):
self.appkey = appkey
self.app_secret = app_secret
def createToken(self,room,user,role='',expires=3600*24):
nonce = random.randint(0,9999999)
params = {
'room':room,
'user':user,
'appkey':self.appkey,
'expires':expires,
'role':role,
'nonce':nonce
}
sign = jwt.encode(params,self.app_secret)
data = {
'appkey':self.appkey,
'sign':sign
}
url = dot_engine_api_url + 'createToken'
r = requests.post(url,data=data)
# TBD more beautifule error handle
# result
"""
{
s:10000,
d:{'token':token},
e:'there is error or not error'
}
"""
return r.json()