Permalink
Browse files

nome tecnico

  • Loading branch information...
1 parent f8f78f1 commit aeea2806850db27725cbcd652bc6e64bbc9e418b @mikosh75 committed Oct 27, 2011
Showing with 87 additions and 13 deletions.
  1. +36 −0 public/events.js
  2. +33 −11 public/post.html
  3. +3 −0 public/style.css
  4. +15 −2 server.js
View
@@ -0,0 +1,36 @@
+(function($) {
+ $.print = function( message, insertType ) {
+ insertType = insertType || "append";
+ if ( typeof(message) == "object" ) {
+ var string = "{<br>",
+ values = [],
+ counter = 0;
+ $.each( message, function( key, value ) {
+ if ( value && value.nodeName ) {
+ var domnode = "&lt;" + value.nodeName.toLowerCase();
+ domnode += value.className ? " class='" + value.className + "'" : "";
+ domnode += value.id ? " id='" + value.id + "'" : "";
+ domnode += "&gt;";
+ value = domnode;
+ }
+ values[counter++] = key + ": " + value;
+ });
+ string += values.join( ",<br>" );
+ string += "<br>}";
+ message = string;
+ }
+
+ var $output = $( "#print-output" );
+
+ if ( !$output.length ) {
+ $output = $( "<div id='print-output' />" ).appendTo( "body" );
+ }
+
+ var newMsg = $('<div />', {
+ "class": "print-output-line",
+ html: message
+ });
+
+ $output[insertType]( newMsg );
+ };
+})(jQuery);
View
@@ -5,7 +5,7 @@
<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>
+ <script src="/events.js"></script>
<link rel="stylesheet" href="/style.css" type="text/css" media="screen" title="no title" charset="utf-8">
</head>
@@ -40,24 +40,37 @@
urlParams[d(e[1])] = d(e[2]);
})();
-
log = $("#chatlog");
+ var tecnico_nome = urlParams["tecnico"];
+ //alert(tecnico_nome);
+
var client = new Faye.Client('http://' + localaddress + '/faye', {
timeout: 120
});
var subscription = client.subscribe('/channel/' + urlParams["ch"], function(message) {
- //alert(message.timestamp);
+ alert(message.timestamp);
- var time = formatTime(ExtractInteger(message.timestamp)),
+/* var time = formatTime(ExtractInteger(message.timestamp)),
row = $("<div></div>").addClass("chat-msg");
$("<span></span>")
.addClass("chat-time")
.text(time)
.appendTo(row);
+
+ if (message.utente=="cliente") {
+ message.utente="io: ";
+ } else {
+ message.utente=tecnico_nome + ': ';
+ }
+
+ $("<span></span>")
+ .addClass("chat-text")
+ .text(message.utente)
+ .appendTo(row);
// $("<span></span>")
// .addClass("chat-nick")
@@ -69,19 +82,28 @@
.text(message.text)
.appendTo(row);
- row.appendTo(log);
+ row.appendTo(log); */
// $("#chatlog").append("<p>" + message.text + "</p>");
});
-
+
+
subscription.callback(function() {
// alert('Subscription is now active with client id: ' + client.getClientId());
+ var ts = (new Date()).getTime();
+ var time = formatTime(ts);
var row = $("<div></div>").addClass("chat-msg");
+ $("<span></span>")
+ .addClass("chat-time")
+ .text(time)
+ .appendTo(row);
+
$("<span></span>")
.addClass("chat-text")
- .text('utente con id ' + client.getClientId() + ' collegato')
+ //.text('utente con id ' + client.getClientId() + ' collegato')
+ .text('Benvenuto! Sono ' + tecnico_nome + ', come posso aiutarla?')
.appendTo(row);
row.appendTo(log);
@@ -104,7 +126,7 @@
var message = $("#message").val();
var data = (new Date()).getTime();
- var dataString = 'text='+ message + '&timestamp=' + data +'&ch=' + urlParams["ch"] + '&clientid=' + client.getClientId();
+ var dataString = 'text='+ message + '&timestamp=' + data +'&ch=' + urlParams["ch"] + '&clientid=' + client.getClientId() +'&user=cliente';
//alert (dataString);return false;
$.ajax({
type: "POST",
@@ -116,10 +138,10 @@
}
});
//return false;
-
- });
+ });
- function formatTime(timestamp) {
+ function formatTime(timestamp)
+ {
var date = new Date(timestamp),
hours = date.getHours(),
minutes = date.getMinutes(),
View
@@ -162,6 +162,9 @@ img {
.chat-time {
margin-right: 10px;
}
+.chat-user {
+ margin-right: 10px;
+}
.centered {
text-align: center;
View
@@ -39,7 +39,17 @@ 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,
- clientid: req.body.clientid
+ clientid: req.body.clientid,
+ utente: req.body.user
+ }
+ );
+ res.send(200);
+});
+
+app.post('/is_typing', function(req, res) {
+ bayeux.getClient().publish('/is_typing/' + req.body.ch, { ch: req.body.ch,
+ utente: req.body.user,
+ timestamp: req.body.timestamp
}
);
res.send(200);
@@ -71,6 +81,9 @@ bayeux.getClient().subscribe('/channel/*', function(message) {
var ts = (new Date()).getTime();
console.log(ts + ' [' + message.ch + '] ' + message.id_chat);
} else {
- console.log(message.timestamp + ' [' + message.ch + '] ' + message.clientid + ' ' + message.text);
+ console.log(message.timestamp + ' [' + message.ch + '] ' + message.clientid + ' ' + message.utente + ' ' + message.text);
}
+ });
+bayeux.getClient().subscribe('/is_typing/*', function(message) {
+ console.log(message.timestamp + ' [' + message.ch + '] ' + message.utente + ' is typing');
});

0 comments on commit aeea280

Please sign in to comment.