1
你好我正在使用Tornado
,Django
frammwork在後端處理郵件在前端的消息。我不太喜歡我的項目,但是我的項目中有一個文件,其中的類實現了websocket.WebSocketHandler
和web.Application
。這是該文件如何發送消息到web託管與Tornado
class Application(web.Application):
"""
Main Class for this application holding everything together.
"""
def __init__(self):
PROJECT_NAME = os.path.basename(os.getcwd())
os.environ['DJANGO_SETTINGS_MODULE'] = PROJECT_NAME + 'tutorial/settings'
# Handlers defining the url routing.
handlers = [
('/room', SocketHandler),
('/room/([a-zA-Z0-9|=%]*)$', SocketHandler),
('/video_call', VideoCallSocketHandler),
('/video_call/([a-zA-Z0-9|=%]*)$', VideoCallSocketHandler),
]
在前端部分的一部分,是一個功能:
var ws = new WebSocket('wss://domain.com:9003/video_call/' + conferenceId);
ws.onmessage = function (ev) {
window.location.replace(redirectUrl);
};
我相信,從我們的移動aplication該功能獲取的信息。
所以問題是,我想發送消息到這個URL或任何它從我的python視圖'wss://domain.com:9003/video_call/' + conferenceId
。
例如:
def some_view_function(request, **kwargs):
conference_id = request.GET.data['conferenceId']
...
if something:
send message to wss://domain.com:9003/video_call/' + conference_id
我該怎麼辦呢?
如何在'send_to_queue'中定義'conference_id'。函數如何知道'WebSocket'發送消息? – Przemek