Skip to content

Commit

Permalink
Added Facebook live chat support
Browse files Browse the repository at this point in the history
No documentation yet, will come soon.
  • Loading branch information
Ole Henrik Stabell committed Oct 11, 2017
1 parent 9b122a9 commit 6fbd797
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
5 changes: 4 additions & 1 deletion auth.example.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"channel_id": "YouTube Channel ID Here",
"youtube_key": "YouTube Data API Key Here"
"youtube_key": "YouTube Data API Key Here",

"user_id": "Facebook User ID Here",
"user_access_token": "Facebook User Access Token Here"
}
40 changes: 39 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var favicon = require('serve-favicon');
var path = require('path')
var io = require('socket.io')(http);
var yt = require('youtube-live-chat');
var fb = require('facebook-live-chat');
var jade = require('jade');

//try {
Expand All @@ -25,14 +26,39 @@ try {

//var ips = (ipwhitelist.ips);
var ytClient
var fbClient

function onFBStopSignal() {
console.log('[INFO/Facebook API]: Received Facebook stop signal.');
fbClient.emit('stop', 'Received stop signal!');
}

function onFBStartSignal() {
fbClient = new fb(authDetails.user_id, authDetails.user_access_token);

fbClient.on('ready', () => {
console.log('[INFO/Facebook Live API]:' + ' ready!');
fbClient.listen(1100);
})

// if the facebook api fails, print the error output to console.
fbClient.on('error', err => {
console.log('[INFO/Facebook Live API]:' + ' ' + err);
})

// Emit every new facebook chat message to Socket.io.
fbClient.on('chat', json => {
io.emit('chat message', json.id, 'https://scontent.fsvg1-1.fna.fbcdn.net/v/t31.0-1/c379.0.1290.1290/10506738_10150004552801856_220367501106153455_o.jpg?oh=c388fe6f7c9e7d5f9a69dcd4208b0fd8&oe=5A7F107C', json.from.name, json.message);
});

}

function onYTStopSignal() {
console.log('[INFO/YouTube API]: Received YouTube stop signal.');
ytClient.emit('stop', 'Received stop signal!');
}

function onYTStartSignal() {

console.log('[INFO/YouTube API]: Received YouTube start signal.');
console.log('[INFO/YouTube API]: Attempting to find live stream');

Expand Down Expand Up @@ -117,6 +143,18 @@ app.get('/stopyt', function (req, res) {
onYTStopSignal();
})

app.get('/startfb', function (req, res) {
console.log('[INFO/Express]:' + ' sending Facebook start signal')
res.send("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/styles.css\"><h1>Facebook start signal sent!</h1>")
onFBStartSignal();
})

app.get('/stopfb', function (req, res) {
console.log('[INFO/Express]:' + ' sending Facebook stop signal')
res.send("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/styles.css\"><h1>Facebook stop signal sent!</h1>")
onFBStopSignal();
})

io.on('connection', function (socket) {

socket.on('chat message', function (id, img, name, msg) {
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

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

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mrc-youtube-questions-approver",
"version": "1.0.0",
"version": "1.1.0",
"description": "A simple server and client project for flagging youtube live chat comments as questions, then generating a lower third for the flagged comments.",
"main": "index.js",
"scripts": {
Expand All @@ -16,10 +16,15 @@
"dependencies": {
"express": "^4.16.2",
"express-ipfilter": "^0.3.1",
"facebook-live-chat": "^1.0.1",
"jade": "^1.11.0",
"serve-favicon": "^2.4.5",
"socket.io": "^2.0.3",
"socket.io-redis": "^5.2.0",
"youtube-live-chat": "git+https://github.com/Hennamann/youtube-live-chat.git"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Hennamann/Live-Chat-Question-Flagger.git"
}
}
5 changes: 2 additions & 3 deletions views/mainview.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@
$('<p>').text(msg).attr('id', 'message'), $('<b>').append('<a>').text('Mark as Question ').attr(
'id', 'question-btn').attr('onclick', 'markQuestion(\'' + id + '\', \'' + img +
'\', \'' + name + '\', \'' + msg + '\')'), $('<b>').append($('<a>').text(
' Generate Lower Third').attr('id', 'lowerthird-btn').attr('style', 'visibility:hidden;').attr('onclick',
' Generate Lower Third').attr('id', 'lowerthird-btn').attr('onclick',
'genLowerThird(\'' + id + '\', \'' + img +
'\', \'' + name + '\', \'' + msg + '\')')))));
})

socket.on('chat question', function (id, img, name, msg) {
document.getElementById(id).style.backgroundColor = "rgba(255, 255, 0, 0.5)"
document.getElementById(id).childNodes[1].childNodes[3].childNodes[0].style.visibility = "visible";
})
});
</script>
Expand All @@ -48,7 +47,7 @@

<div class="container">
<div id="messages">
<h1>YouTube Live Chat Comments:</h1>
<h1>Live Chat Comments:</h1>
</div>
</div>

Expand Down

0 comments on commit 6fbd797

Please sign in to comment.