尝试连接Web套接字时django-channels websocket桥错误

时间:2018-11-27 07:03:04

标签: python django django-channels

我正在尝试在我的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

0 个答案:

没有答案