Created
July 25, 2014 09:06
-
-
Save SeyitOzanOzdil/b9d31174ed9a4678f328 to your computer and use it in GitHub Desktop.
This file contains 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> | |
<html> | |
<head lang="en"> | |
<meta charset="UTF-8"> | |
<title></title> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script> | |
<script type="text/javascript" src="js/noty/packaged/jquery.noty.packaged.min.js"></script> | |
<script src="socket.io.js"></script> | |
<script type="text/javascript"> | |
function generate(layout, message) { | |
var n = noty({ | |
text : message, | |
type : 'information', | |
dismissQueue: true, | |
layout : layout, | |
theme : 'defaultTheme' | |
}); | |
console.log('html: ' + n.options.id); | |
} | |
$(function(){ | |
var sock = new io.connect('http://localhost:8001', { | |
query: $.param({token: 'i271az2Z0PMjhd6w0rX019g0iS7c2q4R'}) | |
}); | |
var socket = new io.connect('http://localhost:8001/socket') | |
sock.on('disconnect', function() { | |
sock.socket.reconnect(); | |
}); | |
socket.on('message', function(data){ | |
generate('bottomRight', data) | |
}); | |
socket.on('old_message', function(data){ | |
$('#msg').append('<div>' + data + '</div>'); | |
}); | |
$('#msgform').submit(function (evt){ | |
var line = $('#msgform [type=text]').val() | |
$('#msgform [type=text]').val('') | |
socket.send(line); | |
return false; | |
}); | |
$("#join").click(function(e) { | |
socket.emit('join', $("#room").val()); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<h3>Socket</h3> | |
<div id="msg" style="width: 60em; height: 20em; overflow:auto; border: 1px solid black"> | |
</div> | |
<form id="msgform"> | |
<input type="text" value="join room" id="room" /> | |
<input type="submit" id="join"/> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment