Permalink
Browse files

unico file per client e post

  • Loading branch information...
1 parent 244f90f commit 3f3d01400994249b6784377491dea822f8f604fb @mikosh75 committed Oct 18, 2011
Showing with 436 additions and 69 deletions.
  1. +4 −2 public/client.html
  2. +0 −23 public/client2.html
  3. +0 −19 public/jquery-1.3.2.min.js
  4. +110 −22 public/post.html
  5. +318 −0 public/style.css
  6. +4 −3 server.js
View
@@ -7,9 +7,10 @@
<script src="/faye.js"></script>
<script type="text/javascript">
- var client = new Faye.Client('/faye', {
+
+ var client = new Faye.Client('/faye', {
timeout: 120
- });
+ });
client.subscribe('/channel/1', function(message) {
$("#messages").append("<p>" + message.text1 + "</p>");
@@ -18,6 +19,7 @@
//subscription.callback(function() {
// alert('Subscription is now active!');
// });
+
</script>
</body>
</html>
View
@@ -1,23 +0,0 @@
-<html>
- <body>
- <h1>NodeCasts.org - Realtime pubsub with Faye Channel 2</h1>
- <div id="messages"></div>
-
- <script src="/jquery-1.6.3.min.js"></script>
- <script src="/faye.js"></script>
-
- <script type="text/javascript">
- var client = new Faye.Client('/faye', {
- timeout: 120
- });
-
- client.subscribe('/channel/2', function(message) {
- $("#messages").append("<p>" + message.text1 + "</p>");
- });
-
- //subscription.callback(function() {
- // alert('Subscription is now active!');
- // });
- </script>
- </body>
-</html>
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,32 +1,88 @@
<!DOCTYPE html>
<html>
- <body>
- <h1>NodeCasts.org - Realtime pubsub with Faye</h1>
-
- <form name="send_message_form" accept-charset="utf-8">
+<head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+ <title>post</title>
+ <script src="/jquery-1.6.3.min.js"></script>
+ <script src="/faye.js"></script>
+ <script src="http://api.jquery.com/scripts/events.js"></script>
+ <link rel="stylesheet" href="/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
+
+</head>
+<body>
+ <div id="chatlog"></div>
+ <div id="footer">
+ <div id="type_here">
<label for="message">messaggio da inviare</label>
<input type="text" name="message" value="" id="message">
-
- </form>
-
- <p><button id="invia_button">Invia</button>
- <div id="stato"></div>
- </p>
- <script src="/jquery-1.6.3.min.js"></script>
- <script src="http://api.jquery.com/scripts/events.js"></script>
+ <button id="invia_button">Invia</button>
+ <span id="stato"></span>
+ </div>
+
+ </div>
+</body>
<script type="text/javascript" charset="utf-8">
- $(function() {
+ (function($) {
+
+ var urlParams = {};
+ (function () {
+ var e,
+ a = /\+/g, // Regex for replacing addition symbol with a space
+ r = /([^&=]+)=?([^&]*)/g,
+ d = function (s) { return decodeURIComponent(s.replace(a, " ")); },
+ q = window.location.search.substring(1);
+
+ while (e = r.exec(q))
+ urlParams[d(e[1])] = d(e[2]);
+ })();
+
+
+ log = $("#chatlog");
+
+ var client = new Faye.Client('/faye', {
+ timeout: 120
+ });
+
+ var subscription = client.subscribe('/channel/' + urlParams["ch"], function(message) {
+
+ var time = formatTime(ExtractInteger(message.timestamp)),
+ row = $("<div></div>")
+ .addClass("chat-msg");
+
+ $("<span></span>")
+ .addClass("chat-time")
+ .text(time)
+ .appendTo(row);
+
+ // $("<span></span>")
+ // .addClass("chat-nick")
+ // .text(message.nick)
+ // .appendTo(row);
+
+ $("<span></span>")
+ .addClass("chat-text")
+ .text(message.text)
+ .appendTo(row);
+
+ row.appendTo(log);
+
+ // $("#chatlog").append("<p>" + message.text + "</p>");
+ });
+
+ subscription.callback(function() {
+ alert('Subscription is now active!');
+ });
+
+ $("#message").val("").focus();
$("#message").keypress(function(event) {
if ( event.which == 13 ) {
event.preventDefault();
$("#invia_button").click();
-
-
}
});
@@ -35,25 +91,57 @@
//$("#message").keypress();
- var message = $("input#message").val();
- var data = new Date();
+ var message = $("#message").val();
+ var data = (new Date()).getTime();
- var dataString = 'inputfield='+ message + '&timestamp=' + data;
+ var dataString = 'text='+ message + '&timestamp=' + data +'&ch=' + urlParams["ch"];
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "http://localhost:8000/message",
data: dataString,
success: function() {
$('#stato').text("messaggio inviato!").show().fadeOut(500);
- $("input#message").val("");
+ $("#message").val("");
}
});
//return false;
- });
- });
+ });
+
+ function formatTime(timestamp) {
+ var date = new Date(timestamp),
+ hours = date.getHours(),
+ minutes = date.getMinutes(),
+ ampm = "AM";
+
+ if (hours > 12) {
+ hours -= 12;
+ ampm = "PM";
+ }
+
+ if (minutes < 10) {
+ minutes = "0" + minutes;
+ }
+
+ return hours + ":" + minutes + " " + ampm;
+ }
+
+ function ExtractInteger(sValue)
+ {
+ var sDigits = "";
+ for (var i = sValue.length - 1; i >= 0; i--)
+ {
+ var c = sValue.charAt(i);
+ if (c < "0" || c > "9")
+ break;
+ sDigits = c + sDigits;
+ }
+ return (sDigits.length > 0) ? parseInt(sDigits, 10) : NaN;
+ }
+
+
+ })(jQuery);
</script>
- </body>
</html>
Oops, something went wrong.

0 comments on commit 3f3d014

Please sign in to comment.