tweetcast/twisted/client/js/script.js
author Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
Wed, 07 Dec 2011 19:28:46 +0100
changeset 409 f7ceddf99d6d
parent 311 13702105c5ee
permissions -rw-r--r--
improve the user management. try to complete user information whenever possible.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
311
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     1
// Web Socket definitions
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     2
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     3
WEB_SOCKET_SWF_LOCATION = "lib/websocket-js/WebSocketMain.swf";
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     4
WEB_SOCKET_DEBUG = true;
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     5
var ws, tweets = [];
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     6
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     7
$(document).ready(function() {
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     8
  ws = new WebSocket("ws://" + document.location.hostname + ":9000/");
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
     9
  ws.onopen = function() {
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    10
  	console.log("open");
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    11
  }
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    12
  ws.onmessage = function(e) {
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    13
	d = $.parseJSON(e.data);
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    14
	console.log(d);
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    15
	if (d.tweets) {
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    16
		tweets = tweets.concat(d.tweets);
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    17
		html = '';
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    18
		for (var i = d.tweets.length - 1; i >= 0; i--) {
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    19
			html += Mustache.to_html('<li class="tweet{{#annotations}} a_{{name}}{{/annotations}}" id="tweet_{{id}}"><img class="tweet_profile_image" src="{{profile_image_url}}" /><h4 class="tweet_title"><a href="http://twitter.com/{{screen_name}}" target="_blank">@{{screen_name}}:</a></h4><p class="tweet_created_at">{{created_at}}</p><p class="tweet_text">{{text}}</p></li>',d.tweets[i]);
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    20
		}
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    21
		console.log(html);
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    22
		$("#tweetlist").prepend(html);
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    23
	}
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    24
  };
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    25
  ws.onclose = function() {
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    26
	console.log("close");
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    27
  };
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    28
  ws.onerror = function() {
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    29
	console.log("error");
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    30
  };
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    31
  
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    32
  
13702105c5ee Réorganisation de Tweetcast
Raphael Velt <raph.velt@gmail.com>
parents:
diff changeset
    33
})