Permalink
Browse files

first import

  • Loading branch information...
0 parents commit 8b5965c164c859173e09cf0745116c8345faa1b5 @videlalvaro committed May 6, 2011
@@ -0,0 +1,3 @@
+ebin/
+deps/
+erl_crash.dump
@@ -0,0 +1,21 @@
+The MIT License
+
+Copyright (c) 2011 Alvaro Videla
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,20 @@
+DEPS_DIR=deps
+EBIN_DIR=ebin
+
+all: compile
+
+clean:
+ rm -rf $(EBIN_DIR)
+
+$(DEPS_DIR):
+ mkdir $(DEPS_DIR);
+ wget http://www.rabbitmq.com/releases/plugins/v2.4.1/amqp_client-2.4.1.ez
+ wget http://www.rabbitmq.com/releases/plugins/v2.4.1/rabbit_common-2.4.1.ez
+ unzip -d deps amqp_client-2.4.1.ez
+ unzip -d deps rabbit_common-2.4.1.ez
+ rebar get-deps
+ rm amqp_client-2.4.1.ez
+ rm rabbit_common-2.4.1.ez
+
+compile: $(DEPS_DIR)
+ ./rebar compile
@@ -0,0 +1,42 @@
+# RabbitMQ Chat #
+
+This project shows how to create a simple web chat room with RabbitMQ.
+
+The chat server uses Websockets to send messages to the connected users. This means it only works with Chrome and Safari. Some browsers like Firefox 4 can be configured to enable Websockets.
+
+On the RabbitMQ side there it uses a _custom exchange_ to store the last 20 messages, so new users connecting to the chat room can get a context of what's going on. See the project [Recent History Exchange](https://github.com/videlalvaro/rabbitmq-recent-history-exchange) for installation instructions.
+
+## How does it work ##
+
+Each user that connects to the server will get a _private auto delete anonymous queue_. This queue will be managed by an AMQP consumer. Whenever the AMQP consumer recieves a message it will forward it to the Websockets process and this one will send it to the user browser.
+
+When the user is disconnects from the server his consumer gets closed and the queue deleted.
+
+## Building: ##
+
+Get the source code:
+
+ $ git clone git://github.com/videlalvaro/rabbitmq-chat.git
+ $ cd rabbitmq-chat
+
+Compile the source code:
+
+ $ make
+
+## Usage ##
+
+- Install the [Recent History Exchange](https://github.com/videlalvaro/rabbitmq-recent-history-exchange) plugin if you haven't done so.
+
+- Start RabbitMQ if is not running already.
+
+- Start the server:
+
+ $ ./start-dev.sh
+
+Go with your browser to [http://localhost:8080/](http://localhost:8080/). Invite your friends. Enjoy!
+
+## Credits ##
+
+Inspired by [YakRiak](https://github.com/seancribbs/yakriak)
+
+Original design adapted from __YakRiak__. Thanks [Basho](http://basho.com/) and [@pharkmillups](http://twitter.com/#!/pharkmillups)
@@ -0,0 +1,138 @@
+/* Generic top-level elements */
+html, body {
+ height: 100%;
+ min-height: 100%;
+ font-family: Helvetica, Arial, sans-serif;
+ margin: 0;
+ padding: 0;
+}
+
+/* Layout top-level elements */
+h1 {
+ font-size: 14px;
+ line-height: 1em;
+ min-width: 99%;
+ max-width: 100%;
+ max-height: 5%;
+ margin: 0;
+ padding: 5px;
+ background-color: #FF9933;
+}
+
+ol#chatlog {
+ margin:0;
+ height: 75%;
+ min-height: 75%;
+ max-height: 75%;
+ overflow-y: auto;
+ overflow-x: hidden;
+ padding: 0 3px;
+}
+
+form#chatbox {
+ height: 75px;
+ min-height: 75px;
+ width: 100%;
+ min-width: 100%;
+ position: fixed;
+ bottom: 0;
+}
+
+form#login {
+ width: 300px;
+ margin: 20% auto 0;
+}
+
+/* Timeline styles */
+ol#chatlog li {
+ margin: 0;
+ border-bottom: 1px solid #d8d8d8;
+ list-style-type: none;
+ padding: 3px;
+ float: left;
+ min-width: 99%;
+ max-width: 100%;
+ width: 100%;
+ clear: both;
+ font-size: 14px;
+}
+
+ol#chatlog li span.timestamp {
+ float:right;
+ color: #999;
+ font-size: 10px;
+ margin: 0 3px;
+}
+
+ol#chatlog li span.name {
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border-radius: 5px;
+ background-color: #ddd;
+ font-size: 12px;
+ padding: 1px 6px;
+ margin-right: 10px;
+}
+
+ol#chatlog li img {
+ float: left;
+ padding: 1px;
+ margin: 0 3px 0 0;
+ border: 1px solid #eee;
+}
+
+ol#chatlog li.me {
+ background-color: #cfc;
+ border-bottom: 1px solid #696;
+}
+
+ol#chatlog li.me span.name {
+ color: white;
+ background-color: #060;
+}
+
+ol#chatlog li.me span.timestamp {
+ color: #696;
+}
+
+/* Generic form elements */
+form ol {
+ list-style-type: none;
+ padding: 0;
+}
+
+form ol li {
+ padding: 0;
+ margin-bottom: 0.5em;
+}
+
+fieldset {
+ border: none;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border-radius: 5px;
+ background-color: #FF9933;
+}
+
+fieldset legend {
+ background-color: #cdd;
+ -moz-border-radius: 5px;
+ -webkit-border-radius: 5px;
+ border-radius: 5px;
+ padding: 2px 5px;
+}
+
+label {
+ display: block;
+ font-size: 80%;
+ font-weight: bold;
+}
+
+label + input {
+ font-size: 18px;
+}
+
+input#message {
+ width: 99%;
+ max-width: 100%;
+}
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>RMQChat - The RabbitMQ-powered Chatroom</title>
+ <link rel="stylesheet" type="text/css" href="css/styles.css">
+ <link rel="icon" type="image/png" href="img/favicon.png">
+ </head>
+ <body>
+ <h1>RMQChat - The RabbitMQ-powered Chatroom</h1>
+ <ol id='chatlog' style='display: none'></ol>
+ <form id='login' method='post' action='nowhere'>
+ <fieldset>
+ <legend>Sign in</legend>
+ <ol>
+ <li>
+ <label for='name'>Name</label>
+ <input id='name' name='name' type='text'>
+ </li>
+ <li>
+ <label for='email'>Email (for gravatars)</label>
+ <input id='email' name='email' type='email'>
+ </li>
+ <li>
+ <input type='submit' value='Down the Rabbit Hole!'>
+ </li>
+ </ol>
+ </fieldset>
+ </form>
+ <form id='chatbox' method='post' style='display: none' action='nowhere'>
+ <fieldset>
+ <ol>
+ <li>
+ <label for='message'>Message</label>
+ <input type='text' id='message'>
+ </li>
+ </ol>
+ </fieldset>
+ </form>
+ <script type="text/javascript" src="js/jquery.min.js"></script>
+ <script type="text/javascript" src="js/jquery.base64.min.js"></script>
+ <script type="text/javascript" src="js/cookie.js"></script>
+ <script type="text/javascript" src="js/json2.js"></script>
+ <script type="text/javascript" src="js/md5-min.js"></script>
+ <script type="text/javascript" src="js/rmqchat.js"></script>
+ </body>
+</html>
@@ -0,0 +1,80 @@
+/*
+ cookie.js
+
+ Copyright (c) 2007, 2008 Maxime Haineault
+ (http://www.haineault.com/code/cookie-js/, http://code.google.com/p/cookie-js/)
+
+ Portions Copyright (c) 2008, John W. Long
+
+ Permission is hereby granted, free of charge, to any person obtaining
+ a copy of this software and associated documentation files (the
+ "Software"), to deal in the Software without restriction, including
+ without limitation the rights to use, copy, modify, merge, publish,
+ distribute, sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so, subject to
+ the following conditions:
+
+ The above copyright notice and this permission notice shall be
+ included in all copies or substantial portions of the Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+Cookie = {
+ get: function(name) {
+ // Still not sure that "[a-zA-Z0-9.()=|%/]+($|;)" match *all* allowed characters in cookies
+ tmp = document.cookie.match((new RegExp(name +'=[a-zA-Z0-9.()=|%/]+($|;)','g')));
+ if (!tmp || !tmp[0]) {
+ return null;
+ } else {
+ return unescape(tmp[0].substring(name.length + 1, tmp[0].length).replace(';', '')) || null;
+ }
+ },
+
+ set: function(name, value, expireInHours, path, domain, secure) {
+ var cookie = [
+ name + '=' + escape(value),
+ 'path=' + ((!path || path == '') ? '/' : path)
+ ];
+ if (Cookie._notEmpty(domain)) cookie.push('domain=' + domain);
+ if (Cookie._notEmpty(expireInHours)) cookie.push(Cookie._hoursToExpireDate(expireInHours));
+ if (Cookie._notEmpty(secure)) cookie.push('secure');
+ return document.cookie = cookie.join(';');
+ },
+
+ erase: function(name, path, domain) {
+ path = (!path || typeof path != 'string') ? '' : path;
+ domain = (!domain || typeof domain != 'string') ? '' : domain;
+ if (Cookie.get(name)) Cookie.set(name, '', 'Thu, 01-Jan-70 00:00:01 GMT', path, domain);
+ },
+
+ // Returns true if cookies are enabled
+ accept: function() {
+ Cookie.set('b49f729efde9b2578ea9f00563d06e57', 'true');
+ if (Cookie.get('b49f729efde9b2578ea9f00563d06e57') == 'true') {
+ Cookie.erase('b49f729efde9b2578ea9f00563d06e57');
+ return true;
+ }
+ return false;
+ },
+
+ _notEmpty: function(value) {
+ return (typeof value != 'undefined' && value != null && value != '');
+ },
+
+ // Private function for calculating the date of expiration based on hours
+ _hoursToExpireDate: function(hours) {
+ if (parseInt(hours) == 'NaN' ) return '';
+ else {
+ now = new Date();
+ now.setTime(now.getTime() + (parseInt(hours) * 60 * 60 * 1000));
+ return now.toGMTString();
+ }
+ }
+}
Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 8b5965c

Please sign in to comment.