-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9b8ccfc
commit 002bc0a
Showing
4 changed files
with
245 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
|
||
# Created by https://www.gitignore.io/api/win,windows,macos,sublimetext,node | ||
|
||
#!! ERROR: win is undefined. Use list command to see defined gitignore types !!# | ||
|
||
### Windows ### | ||
# Windows image file caches | ||
Thumbs.db | ||
ehthumbs.db | ||
|
||
# Folder config file | ||
Desktop.ini | ||
|
||
# Recycle Bin used on file shares | ||
$RECYCLE.BIN/ | ||
|
||
# Windows Installer files | ||
*.cab | ||
*.msi | ||
*.msm | ||
*.msp | ||
|
||
# Windows shortcuts | ||
*.lnk | ||
|
||
|
||
### macOS ### | ||
*.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
# Icon must end with two \r | ||
Icon | ||
|
||
|
||
# Thumbnails | ||
._* | ||
|
||
# Files that might appear in the root of a volume | ||
.DocumentRevisions-V100 | ||
.fseventsd | ||
.Spotlight-V100 | ||
.TemporaryItems | ||
.Trashes | ||
.VolumeIcon.icns | ||
.com.apple.timemachine.donotpresent | ||
|
||
# Directories potentially created on remote AFP share | ||
.AppleDB | ||
.AppleDesktop | ||
Network Trash Folder | ||
Temporary Items | ||
.apdisk | ||
|
||
|
||
### SublimeText ### | ||
# cache files for sublime text | ||
*.tmlanguage.cache | ||
*.tmPreferences.cache | ||
*.stTheme.cache | ||
|
||
# workspace files are user-specific | ||
*.sublime-workspace | ||
|
||
# project files should be checked into the repository, unless a significant | ||
# proportion of contributors will probably not be using SublimeText | ||
# *.sublime-project | ||
|
||
# sftp configuration file | ||
sftp-config.json | ||
|
||
# Package control specific files | ||
Package Control.last-run | ||
Package Control.ca-list | ||
Package Control.ca-bundle | ||
Package Control.system-ca-bundle | ||
Package Control.cache/ | ||
Package Control.ca-certs/ | ||
bh_unicode_properties.cache | ||
|
||
# Sublime-github package stores a github token in this file | ||
# https://packagecontrol.io/packages/sublime-github | ||
GitHub.sublime-settings | ||
|
||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules | ||
jspm_packages | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const _oauth = require( 'googleapis' ).auth.OAuth2; | ||
|
||
exports.connect = function( oauth, accessToken, liveChatId, callback ) | ||
{ | ||
const oauthClient = _getOAuthClient( oauth ); | ||
|
||
oauthClient.setCredentials({ | ||
access_token: accessToken | ||
}); | ||
|
||
const _responseHandler = _curryHandleResponse( callback ); | ||
|
||
const stream = require( './src/stream.js' ); | ||
|
||
stream._init( oauthClient, liveChatId, _responseHandler ); | ||
|
||
return stream; | ||
}; | ||
|
||
const _curryHandleResponse = function( callback ) | ||
{ | ||
return function( err, response ) | ||
{ | ||
_handleResponse( err, response, callback ); | ||
}; | ||
}; | ||
|
||
const _handleResponse = function( err, response, callback ) | ||
{ | ||
if( err ) | ||
{ | ||
callback( err ); | ||
return; | ||
} | ||
|
||
response.items.map(function( thisMessage ) | ||
{ | ||
callback( err, thisMessage ); | ||
}); | ||
}; | ||
|
||
const _getOAuthClient = function( oauth ) | ||
{ | ||
return new _oauth(oauth.client_id, oauth.client_secret, oauth.redirect_uris[0]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "youtube-stream", | ||
"version": "0.0.1", | ||
"description": "Stream Youtube live stream chat", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "James Frost <[email protected]> (http://jamesfrost.me)", | ||
"license": "MIT", | ||
"dependencies": { | ||
"googleapis": "^14.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/JamesFrost/youtube-stream" | ||
}, | ||
"keywords": [ | ||
"youtube", | ||
"live", | ||
"stream", | ||
"chat", | ||
"messaging" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const _youtube = require( 'googleapis' ).youtube( 'v3' ); | ||
var _currentStep; | ||
|
||
exports._init = function( auth, liveChatId, callback ) | ||
{ | ||
_step( auth, liveChatId, undefined, callback ); | ||
}; | ||
|
||
const _step = function( auth, liveChatId, pageToken, callback ) | ||
{ | ||
_getMessages(auth, liveChatId, pageToken, function( err, response ) | ||
{ | ||
callback( err, response ); | ||
|
||
if( err ) | ||
{ | ||
console.log( err ); | ||
} | ||
|
||
const pollingInterval = response == undefined ? 10000 : response.pollingIntervalMillis; | ||
const pageToken = response == undefined ? undefined : response.nextPageToken; | ||
|
||
if( _currentStep === false ) | ||
return; | ||
|
||
_currentStep = setTimeout(function() | ||
{ | ||
_step( auth, liveChatId, pageToken, callback ); | ||
|
||
}, pollingInterval); | ||
|
||
console.log( 'Polling in: ', pollingInterval ); | ||
}); | ||
}; | ||
|
||
const _getMessages = function( accessToken, liveChatId, pageToken, callback ) | ||
{ | ||
_youtube.liveChatMessages.list({ part: 'snippet', liveChatId: liveChatId, auth: accessToken, pageToken : pageToken, maxResults : 2000 }, callback ); | ||
}; | ||
|
||
exports.stop = function() | ||
{ | ||
clearTimeout( _currentStep ); | ||
_currentStep = false; | ||
}; |