genkid123

Untitled

Oct 11th, 2020
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. <script>
  2. var loc = window.location
  3. var wsStart = "ws://"
  4. if (loc.protocol === "https:"){
  5. wsStart = "wss://"
  6. }
  7. var webSocketEndpoint = wsStart + loc.host + '/notifications/' // ws : wss // Websocket URL, Same on as mentioned in the routing.py
  8. var socket = new WebSocket(webSocketEndpoint) // Creating a new Web Socket Connection
  9. // Socket On receive message Functionality
  10. socket.onmessage = function(e){
  11. console.log('message', e)
  12. $("body").append("<h3>"+e.data+"</h3>")
  13. // Can write any functionality based on your requirement
  14. }
  15.  
  16. // Socket Connet Functionality
  17. socket.onopen = function(e){
  18. console.log('open', e)
  19. }
  20.  
  21. // Socket Error Functionality
  22. socket.onerror = function(e){
  23. console.log('error', e)
  24. }
  25.  
  26. // Socket close Functionality
  27. socket.onclose = function(e){
  28. console.log('closed', e)
  29. }
  30.  
  31. </script>
Add Comment
Please, Sign In to add comment