Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dance command #18

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');
var sassMiddleware = require('node-sass-middleware');
var socketApi = require('./socketApi')

var indexRouter = require('./routes/index');
var animationStateRouter = require('./routes/animationState');
var animationStateData = {};

// Create instance of Express and Socket.io
var app = express();
io = socketApi.io;

// view engine setup
app.set('views', path.join(__dirname, 'views'));
Expand Down Expand Up @@ -59,9 +57,10 @@ const animationStateUpdater = () => {
animationStateData = data;
console.log(animationStateData);
animationStateRouter.setCurrentState(animationStateData);
io.emit('speech', animationStateData);
}
setTimeout(animationStateUpdater, 100);
}; animationStateUpdater();



module.exports = app;
12 changes: 12 additions & 0 deletions includes/_tmiAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,18 @@ const timeout = 1000 * 60 * 5;

// Function to greet a user when the send the first message in the chat and start a timeout timer
function greet (target, user) {
let newData = {};
newData.sent = Date.now();
const username = user.username;
logIt(`Greet Triggered with username: ${username}`);
tmiAPI.say(target,`Greetings ${username}, welcome to the channel`);
newData.command = 'greet';
newData.user = username;
activeUser[username] = true;
activeTimeout = setTimeout (timeoutFunc, timeout, username);
if (newData !== null) {
tmiData = newData;
}
}

// Function to reset the status of a user based on chat activity
Expand Down Expand Up @@ -62,6 +69,7 @@ tmiAPI.on('message', (target, context, msg, self) => {
if (speech.length > 0) {
newData.command = "talk";
newData.speech = speech;
newData.user = username;
} else {
newData = null;
}
Expand All @@ -78,6 +86,10 @@ tmiAPI.on('message', (target, context, msg, self) => {
newData = null;
}
break;
case (command.startsWith('!dance')):
console.log('dance');
newData.command = 'dance';
break;
default:
newData = null;
}
Expand Down
Binary file added public/images/cuteslime.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 38 additions & 2 deletions public/js/speech.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,44 @@
// Connect to websocket
var socket = io.connect('http://localhost:1337');

socket.on('connect', () => {
console.log(socket.id, 'connected');
});

// Display content in speech bubble when websocket sends data
socket.on('speech', (data) => {
socket.on('talk', (data) => {
$(".bubble").text(data.user + ' says: ' + data.speech).show(150);
setTimeout(() => {
$(".bubble").text('');
$(".bubble").hide(150);
}, 5000)
console.log(data);
});

socket.on('dice', (data) => {

$(".bubble").text('You rolled a ' + data.result + ' on your D' + data.sides).show(150);
setTimeout(() => {
$(".bubble").text('');
$(".bubble").hide(150);
}, 5000)
console.log(data);
});

socket.on('greet', (data) => {
$(".bubble").text('Welcome ' + data.user).show(150);
setTimeout(() => {
$(".bubble").text('');
$(".bubble").hide(150);
}, 5000)
console.log(data);
});

socket.on('dance', (data) => {
$(".bubble").hide();
$(".bubble").text(data.speech).show(150);
$(".fett").css("background-image", "url(../images/cuteslime.gif)");
setTimeout(() => {
$(".fett").css("background-image", "url(../images/boba-fett.gif)");
}, 3500);
console.log(data);
});
2 changes: 1 addition & 1 deletion public/stylesheets/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/stylesheets/style.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/stylesheets/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ body {

.fett {
width: 150px; height: 150px;
background-image: url(../images/boba-fett.gif);
background: url(../images/boba-fett.gif);
background-size: contain;
background-repeat: no-repeat;
position: absolute;
Expand Down
16 changes: 16 additions & 0 deletions socketApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,24 @@ var socketApi = {};

socketApi.io = io;

var animationStateData = {};

const tmi = require('./includes/_tmiAPI.js');

io.on('connection', (socket) => {
console.log('New connection with ID:', socket.id);

const animationStateUpdater = () => {
let data = tmi.getCurrentState();
if (data !== animationStateData) {
animationStateData = data;
console.log(animationStateData, 'on web socket', socket.id);
if (typeof animationStateData.command !== "undefined") {
io.emit(animationStateData.command, animationStateData);
}
}
setTimeout(animationStateUpdater, 100);
}; animationStateUpdater();
});

module.exports = socketApi;