Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script>
- var loc = window.location
- var wsStart = "ws://"
- if (loc.protocol === "https:"){
- wsStart = "wss://"
- }
- var webSocketEndpoint = wsStart + loc.host + '/notifications/' // ws : wss // Websocket URL, Same on as mentioned in the routing.py
- var socket = new WebSocket(webSocketEndpoint) // Creating a new Web Socket Connection
- // Socket On receive message Functionality
- socket.onmessage = function(e){
- console.log('message', e)
- $("body").append("<h3>"+e.data+"</h3>")
- // Can write any functionality based on your requirement
- }
- // Socket Connet Functionality
- socket.onopen = function(e){
- console.log('open', e)
- }
- // Socket Error Functionality
- socket.onerror = function(e){
- console.log('error', e)
- }
- // Socket close Functionality
- socket.onclose = function(e){
- console.log('closed', e)
- }
- </script>
Add Comment
Please, Sign In to add comment