Permalink
Browse files

inserita subscription.callback e gestione clientId

  • Loading branch information...
1 parent 3f3d014 commit 932fbdfadccb28a4b75aaf4096fc26206283be44 @mikosh75 committed Oct 18, 2011
Showing with 16 additions and 8 deletions.
  1. +13 −5 public/post.html
  2. +1 −1 public/style.css
  3. +2 −2 server.js
View
@@ -50,8 +50,7 @@
var subscription = client.subscribe('/channel/' + urlParams["ch"], function(message) {
var time = formatTime(ExtractInteger(message.timestamp)),
- row = $("<div></div>")
- .addClass("chat-msg");
+ row = $("<div></div>").addClass("chat-msg");
$("<span></span>")
.addClass("chat-time")
@@ -72,9 +71,18 @@
// $("#chatlog").append("<p>" + message.text + "</p>");
});
-
+
subscription.callback(function() {
- alert('Subscription is now active!');
+ // alert('Subscription is now active with client id: ' + client.getClientId());
+
+ var row = $("<div></div>").addClass("chat-msg");
+
+ $("<span></span>")
+ .addClass("chat-text")
+ .text('utente con id ' + client.getClientId() + ' collegato')
+ .appendTo(row);
+
+ row.appendTo(log);
});
$("#message").val("").focus();
@@ -94,7 +102,7 @@
var message = $("#message").val();
var data = (new Date()).getTime();
- var dataString = 'text='+ message + '&timestamp=' + data +'&ch=' + urlParams["ch"];
+ var dataString = 'text='+ message + '&timestamp=' + data +'&ch=' + urlParams["ch"] + '&clientid=' + client.getClientId();
//alert (dataString);return false;
$.ajax({
type: "POST",
View
@@ -9,7 +9,7 @@ body {
border:0; /* This removes the border around the viewport in old versions of IE */
width:100%;
background:#fff;
- min-width:600px; /* Minimum width of layout - remove line if not required */
+ /* min-width:600px; /* Minimum width of layout - remove line if not required */
/* The min-width property does not work in old versions of Internet Explorer */
font-size:90%;
/*height:100%; */
View
@@ -28,7 +28,7 @@ app.configure('production', function(){
});
app.post('/message', function(req, res) {
- bayeux.getClient().publish('/channel/' + req.body.ch, { text: req.body.text, timestamp: req.body.timestamp, ch: req.body.ch });
+ bayeux.getClient().publish('/channel/' + req.body.ch, { text: req.body.text, timestamp: req.body.timestamp, ch: req.body.ch, clientid: req.body.clientid });
res.send(200);
});
@@ -45,5 +45,5 @@ app.listen(Number(port));
console.log('Listening on port ' + port );
bayeux.getClient().subscribe('/channel/*', function(message) {
- console.log(message.timestamp + ' [' + message.ch + ']: ' + message.text);
+ console.log(message.timestamp + ' [' + message.ch + '] ' + message.clientid + ' ' + message.text);
});

0 comments on commit 932fbdf

Please sign in to comment.