Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: 510220cda7
Fetching contributors…

Cannot retrieve contributors at this time

91 lines (79 sloc) 2.803 kB
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<!-- Copyright (c) 2008 Dustin Sallings <> -->
<html lang="en">
<style type="text/css" media="screen">
#messages {
width: 400px;
height: 250px;
overflow: auto;
<h1>Welcome to Chat</h1>
<div id="messages">
<span class="from">First!:</span>
<span class="msg">Welcome to chat. Please don't hurt each other.</span>
<form id="chat-form" onsubmit="onSubmit(); return false;">
<div><label for="from">Nick:</label> <input id='from' type="text" name="from" value="Foo"/></div>
<div><label for="msg">Message:</label></div>
<div><textarea id='msg' name="msg" rows="3" cols="50"></textarea></div>
<div><input type="submit" value="Say it" id="submit"/></div>
<script type="text/javascript"
<script type="text/javascript" src="javascript/swfobject.js"></script>
<script type="text/javascript" src="javascript/FABridge.js"></script>
<script type="text/javascript" src="javascript/web_socket.js"></script>
<script type="text/javascript">
// Set URL of your WebSocketMain.swf here:
WebSocket.__swfLocation = "javascript/WebSocketMain.swf";
var ws;
function initConnection() {
// Connect to Web Socket.
// Change host/port here to your own Web Socket server.
ws = new WebSocket("ws://<%= request.host_with_port %>/websocket");
// Set event handlers.
ws.onopen = function() {
output([{message: "Connection opened"}]);
ws.onmessage = function(e) {
// contains received string.
ws.onclose = function() {
output([{message: "Connection closed"}]);
initConnection(); // reconnect
$(document).ready(function() {
function onSubmit() {
function output(data) {
$.each(data, function(i, item) {
if (item.from != null) {
$("#messages").append( "<div><span class=\"from\">" + item.from + ":</span>\n<span class=\"msg\">" + item.msg + "</span></div>");
if (item.message != null) {
$("#messages").append( "<p>" + item.message + "</p>");
var messages = document.getElementById("messages");
messages.scrollTop = messages.scrollHeight;
Jump to Line
Something went wrong with that request. Please try again.