Created
November 1, 2014 19:31
-
-
Save calvinfroedge/c74be9d18e28c7d5b47f to your computer and use it in GitHub Desktop.
Engine.io socket test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> | |
| <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> | |
| <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> | |
| <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <script src="bower_components/engine.io-client/engine.io.js"></script> | |
| </head> | |
| <body id="body"> | |
| <h1 id="heading">Socket test</h1> | |
| <script> | |
| var body = document.getElementById('body'); | |
| function log(msg, data){ | |
| console.log(msg, (data) ? data : ''); | |
| var p = document.createElement('p'); | |
| p.innerHTML = (data) ? msg + data : msg; | |
| body.appendChild(p); | |
| } | |
| function httpGet(theUrl, callback) | |
| { | |
| var xmlHttp = null; | |
| xmlHttp = new XMLHttpRequest(); | |
| xmlHttp.open("GET", theUrl, true); | |
| xmlHttp.send(); | |
| xmlHttp.onreadystatechange = function(){ | |
| console.log('processing ajax request...', xmlHttp.readyState); | |
| if (xmlHttp.readyState==4 && xmlHttp.status==200){ | |
| console.log('ajax request complete'); | |
| if(callback) callback(); | |
| } | |
| } | |
| } | |
| var socket = eio('wss://localhost:3000'); | |
| socket.on('open', function(){ | |
| var msg = 'socket opened'; | |
| log(msg); | |
| }); | |
| socket.on('close', function(){}); | |
| socket.on('message', function(data){ | |
| parsed = JSON.parse(data); | |
| /*Handle client id assignment*/ | |
| if(parsed.clientId){ | |
| log('Granted clientId! This should be passed for subsequent requests ', parsed.clientId); | |
| log('Now trying a download...should receive progress updates via socket'); | |
| httpGet('/api/pdfJoin/865034-1000/0?socketNotify='+parsed.clientId); | |
| } else { | |
| log('Received socket message from server', data); | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment