From 1905fa4ca7f57bb55983896f741a94531cb79bd6 Mon Sep 17 00:00:00 2001 From: Pablo Navarro Castillo Date: Mon, 14 Jul 2014 00:19:36 -0400 Subject: [PATCH 1/2] Update the socket.io example --- chirp.js | 35 ++++++++++++++++++----------------- socketio-example.html | 40 ++++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 39 deletions(-) diff --git a/chirp.js b/chirp.js index a794650..37d8742 100644 --- a/chirp.js +++ b/chirp.js @@ -55,27 +55,28 @@ function twitOnLimit(limitMessage) { // A tweet is received (`tweet` event) function twitOnTweet(tweet) { - // Process only geotagged tweets - if (tweet.coordinates) { + // Exits if the tweet doesn't have geographic coordinates + if (!tweet.coordinates) { + return; + } - // Convert the tweet text to lowercase to find the topics - var tweetText = tweet.text.toLowerCase(); + // Convert the tweet text to lowercase to find the topics + var tweetText = tweet.text.toLowerCase(); - // Check if any of the topics is contained in the tweet text - topics.forEach(function(topic) { + // Check if any of the topics is contained in the tweet text + topics.forEach(function(topic) { - // Checks if the tweet text contains the topic - if (tweetText.indexOf(topic.word) !== -1) { + // Checks if the tweet text contains the topic + if (tweetText.indexOf(topic.word) !== -1) { - // Sends a simplified version of the tweet to the client - topic.socket.emit('tweet', { - id: tweet.id, - coordinates: tweet.coordinates, - word: topic.word - }); - } - }); - } + // Sends a simplified version of the tweet to the client + topic.socket.emit('tweet', { + id: tweet.id, + coordinates: tweet.coordinates, + word: topic.word + }); + } + }); } // Add listeners for the stream events to the new stream instance diff --git a/socketio-example.html b/socketio-example.html index a092e04..5c13ea0 100644 --- a/socketio-example.html +++ b/socketio-example.html @@ -30,11 +30,15 @@

Socket.IO Example

-
- - -
+
+
+ +
+ +
+ +
+