Skip to content

Commit

Permalink
Merge branch 'release/0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
pnavarrc committed Jul 14, 2014
2 parents 108e5ec + 2c9a651 commit f58255a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 40 deletions.
35 changes: 18 additions & 17 deletions chirp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chirp-server",
"version": "0.2.1",
"version": "0.2.2",
"description": "Twitter Streaming Server",
"main": "README.md",
"repository": {
Expand Down
40 changes: 18 additions & 22 deletions socketio-example.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,15 @@
<h1>Socket.IO Example</h1>

<!-- Input element to send messages -->
<div class="form-group">
<label class="sr-only" for="message">New Topic</label>
<input type="text" id="message" class="form-control input-sm"
placeholder="send a message to the server">
</div>
<form role="form" class="form-horizontal" id="msg-form">
<div class="form-group">
<label for="msgToServer" class="col-sm-1">Message</label>
<div class="col-sm-9">
<input type="text" class="form-control input-sm" id="msgToServer" placeholder="Send a message to the server.">
</div>
<button type="submit" class="btn btn-default btn-sm">Send</button>
</div>
</form>

<!-- List with messages -->
<ul id='msg-list' class='list-unstyled'>
Expand All @@ -49,8 +53,7 @@ <h1>Socket.IO Example</h1>
var socket = io('http://localhost:7000');

// Declare variables for the message list and the time formatter
var ENTER_KEY = 13
messages = [],
var messages = [],
dateFmt = d3.time.format('[%H:%M:%S]');

// Update the message list
Expand All @@ -76,22 +79,13 @@ <h1>Socket.IO Example</h1>
});
}

d3.select('#message').on('keypress', function() {
d3.select('#msg-form').on('submit', function() {

// Retrieve the current event (keypress)
var e = d3.event;

// Check if the user hits the Enter key
if (e.which !== ENTER_KEY) {
return;
}

// Retrieve the content of the input element and remove whitespaces
var message = this.value.trim();
var inputElement = d3.select('#message').node(),
message = inputElement.value.trim();

// Check that the message is not empty
if (message.length > 0) {

if (message) {
// Sends the message to the server
socket.emit('client-message', {msg: message});

Expand All @@ -100,10 +94,12 @@ <h1>Socket.IO Example</h1>

// Update the list of messages (DOM)
updateMessages();

// Resets the form, clearing the input element
this.reset();
}

// Cleans the input element
this.value = '';
d3.event.preventDefault();
});

socket.on('server-message', function(data) {
Expand Down

0 comments on commit f58255a

Please sign in to comment.