我正在尝试在我的Django应用中实现实时通知。我已经设置了信号和使用者。我在javascript端遇到错误
我的JavaScript代码:
<script>
document.addEventListener('DOMContentLoaded', function() {
const webSocketBridge = new channels.WebSocketBridge();
const nl = document.querySelector("#nl");
webSocketBridge.connect('student/dashboard/tasks/');
webSocketBridge.listen(function(action, stream) {
console.log("RESPONSE:", action);
if(action.event == "New Task") {
var el = document.createElement("li");
el.innerHTML = ` <b>${action.username}</b> completed Task
${action.title}`;
nl.appendChild(el);
}
})
document.ws = webSocketBridge; /* for debugging */
})
</script>
错误显示在控制台上:
TypeError: Invalid WebSocket constructor. Set
`options.constructor