Revision 9be97339

View differences:

html/textroomtest.js
154 154
										msg = msg.replace(new RegExp('<', 'g'), '&lt');
155 155
										msg = msg.replace(new RegExp('>', 'g'), '&gt');
156 156
										var from = json["from"];
157
										var dateString = getDateString(json["date"]);
157 158
										var whisper = json["whisper"];
158 159
										if(whisper === true) {
159 160
											// Private message
160
											$('#chatroom').append('<p style="color: purple;"><b>[whisper from ' + participants[from] + ']</b> ' + msg);
161
											$('#chatroom').append('<p style="color: purple;">[' + dateString + '] <b>[whisper from ' + participants[from] + ']</b> ' + msg);
161 162
											$('#chatroom').get(0).scrollTop = $('#chatroom').get(0).scrollHeight;				
162 163
										} else {
163 164
											// Public message
164
											$('#chatroom').append('<p><b>' + participants[from] + ':</b> ' + msg);
165
											$('#chatroom').append('<p>[' + dateString + '] <b>' + participants[from] + ':</b> ' + msg);
165 166
											$('#chatroom').get(0).scrollTop = $('#chatroom').get(0).scrollHeight;				
166 167
										}
167 168
									} else if(what === "join") {
......
177 178
												sendPrivateMsg(username);
178 179
											});
179 180
										}
180
										$('#chatroom').append('<p style="color: green;"><i>' + participants[username] + ' joined</i></p>');
181
										$('#chatroom').append('<p style="color: green;">[' + getDateString() + '] <i>' + participants[username] + ' joined</i></p>');
181 182
										$('#chatroom').get(0).scrollTop = $('#chatroom').get(0).scrollHeight;				
182 183
									} else if(what === "leave") {
183 184
										// Somebody left
184 185
										var username = json["username"];
186
										var when = new Date();
185 187
										$('#rp' + username).remove();
186
										$('#chatroom').append('<p><i style="color: green;">' + participants[username] + ' left</i></p>');
188
										$('#chatroom').append('<p style="color: green;">[' + getDateString() + '] <i>' + participants[username] + ' left</i></p>');
187 189
										$('#chatroom').get(0).scrollTop = $('#chatroom').get(0).scrollHeight;				
188 190
										delete participants[username];
189 191
									} else if(what === "destroyed") {
......
291 293
							sendPrivateMsg(username);
292 294
						});
293 295
					}
294
					$('#chatroom').append('<p><i style="color: green;">' + participants[p.username] + ' joined</i></p>');
296
					$('#chatroom').append('<p style="color: green;">[' + getDateString() + '] <i>' + participants[p.username] + ' joined</i></p>');
295 297
					$('#chatroom').get(0).scrollTop = $('#chatroom').get(0).scrollHeight;				
296 298
				}
297 299
			}
......
324 326
				text: JSON.stringify(message),
325 327
				error: function(reason) { bootbox.alert(reason); },
326 328
				success: function() {
327
					$('#chatroom').append('<p style="color: purple;"><b>[whisper to ' + display + ']</b> ' + result);
329
					$('#chatroom').append('<p style="color: purple;">[' + getDateString() + '] <b>[whisper to ' + display + ']</b> ' + result);
328 330
					$('#chatroom').get(0).scrollTop = $('#chatroom').get(0).scrollHeight;				
329 331
				}
330 332
			});
......
352 354
	});
353 355
}
354 356

  
357
// Helper to format times
358
function getDateString(jsonDate) {
359
	var when = new Date();
360
	if(jsonDate) {
361
		when = new Date(Date.parse(jsonDate));
362
	}
363
	var dateString =
364
			("0" + when.getUTCHours()).slice(-2) + ":" +
365
			("0" + when.getUTCMinutes()).slice(-2) + ":" +
366
			("0" + when.getUTCSeconds()).slice(-2);
367
	return dateString;
368
}
369

  
355 370
// Just an helper to generate random usernames
356 371
function randomString(len, charSet) {
357 372
    charSet = charSet || 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
plugins/janus_textroom.c
694 694
		json_object_set_new(msg, "textroom", json_string("message"));
695 695
		json_object_set_new(msg, "room", json_integer(room_id));
696 696
		json_object_set_new(msg, "from", json_string(participant->username));
697
		time_t timer;
698
		time(&timer);
699
		struct tm *tm_info = localtime(&timer);
700
		char msgTime[64];
701
		strftime(msgTime, sizeof(msgTime), "%FT%T%z", tm_info);
702
		json_object_set_new(msg, "date", json_string(msgTime));
697 703
		json_object_set_new(msg, "text", json_string(message));
698 704
		if(username || usernames)
699 705
			json_object_set_new(msg, "whisper", json_true());

Also available in: Unified diff