-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
10 changed files
with
257 additions
and
3 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,2 @@ | ||
*.DS_Store | ||
node_modules/ |
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 |
---|---|---|
@@ -1 +1,83 @@ | ||
# remood.js | ||
|
||
## How it works | ||
|
||
#### You start by creating an app. | ||
|
||
```js | ||
var express = require('express'), | ||
remood = require('remood'), | ||
app = express(), | ||
server = remood(app); | ||
|
||
// Mount routes to your app | ||
app.get('/', function(req, res) { | ||
res.send('remood.js rocks!'); | ||
}); | ||
|
||
// BUT listen on the RETURNED server instance | ||
server.listen(1337); | ||
``` | ||
|
||
#### Then include frontend functionality | ||
|
||
```html | ||
<script src="js/remood.js"></script> | ||
``` | ||
|
||
### Use it | ||
|
||
#### Receiver | ||
|
||
```js | ||
// Initialize remood | ||
var r = new remood(); | ||
|
||
// Register remood events | ||
r.on('yourEventId', function(msg) { | ||
console.log(msg); | ||
}); | ||
``` | ||
|
||
#### Remote | ||
|
||
```js | ||
// Initialize remood as remote | ||
var r = new remood({ remote: true }); | ||
|
||
r.send({ | ||
id: 'yourEventId', | ||
type: eventName, // Most of the time 'click' or 'input' | ||
data: 'my payload' | ||
}); | ||
``` | ||
|
||
#### jQuery | ||
|
||
Or use build in jQuery connector | ||
|
||
```html | ||
<div id="play">Click me!</div> | ||
``` | ||
|
||
```js | ||
$('#play').connect('click', function() { | ||
// Callback after payload { | ||
// id: 'play', | ||
// type: 'click', | ||
// data: '' | ||
// } has been sent | ||
|
||
console.log('#play has been clicked'); | ||
}); | ||
``` | ||
|
||
## Development | ||
|
||
In case you need to have the latest versions of dependencies: | ||
|
||
```sh | ||
$ cd node_modules/remood/ | ||
$ npm update --dev --depth 0 | ||
$ node ./node_modules/gulp/bin/gulp.js assets | ||
``` |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
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,38 @@ | ||
var browserify = require('browserify'); | ||
var gulp = require('gulp'); | ||
var source = require('vinyl-source-stream'); | ||
var buffer = require('vinyl-buffer'); | ||
var uglify = require('gulp-uglify'); | ||
var sourcemaps = require('gulp-sourcemaps'); | ||
var gutil = require('gulp-util'); | ||
var del = require('del'); | ||
|
||
gulp.task('assets:js', function () { | ||
// set up the browserify instance on a task basis | ||
var b = browserify({ | ||
entries: './assets/js/remood.js', | ||
debug: true | ||
}); | ||
|
||
return b.bundle() | ||
.pipe(source('./assets/js/remood.js')) | ||
.pipe(buffer()) | ||
//.pipe(sourcemaps.init({loadMaps: true})) | ||
// Add transformation tasks to the pipeline here. | ||
// .pipe(uglify()) | ||
.on('error', gutil.log) | ||
//.pipe(sourcemaps.write('./')) | ||
.pipe(gulp.dest('./dist/')); | ||
}); | ||
|
||
gulp.task('clean', function(done) { | ||
del(['./dist/*', '!./dist/.keep'], done); | ||
}); | ||
|
||
gulp.task('default', | ||
['assets'] | ||
); | ||
|
||
gulp.task('assets', | ||
['clean', 'assets:js'] | ||
); |
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 @@ | ||
module.exports = require('./lib/app'); |
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,50 @@ | ||
var express = require('express'), | ||
http = require('http'), | ||
socketIO = require('socket.io'), | ||
RemoodConnection = require('./remood.connection'); | ||
|
||
module.exports = function(app, options) { | ||
var server = http.createServer(app), | ||
io = socketIO(server); | ||
|
||
app.use(express.static(__dirname + '/../dist/assets')); | ||
|
||
app.use(function noop(req, res, next) { | ||
next(); | ||
}); | ||
|
||
io.on('connection', function(socket) { | ||
|
||
console.log('Incomming connection, shaking hands:'); | ||
|
||
// Handshake | ||
socket.on('remood-auth', function(msg) { | ||
|
||
var createConnection = function(id) { | ||
var con = new RemoodConnection(socket, msg.type, id); | ||
console.log('+ Created new connection with id:', con.id()); | ||
socket.emit('remood-auth', { id: con.id() }); | ||
}; | ||
|
||
console.log('+ Socket is a ' + msg.type); | ||
|
||
if (msg.id) { | ||
con = RemoodConnection.find(msg.id); | ||
if (con) { | ||
con.setSocketForType(socket, msg.type); | ||
console.log('+ Successfully connected to connection with id:', msg.id); | ||
console.log(con.statusString(true)); | ||
} else { | ||
console.log('- No conection found for given id, creating new one'); | ||
createConnection(msg.id); | ||
} | ||
} else { | ||
createConnection(); | ||
} | ||
}); | ||
|
||
socket.emit('remood-auth'); | ||
}); | ||
|
||
return server; | ||
}; |
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
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,44 @@ | ||
{ | ||
"name": "remood.js", | ||
"version": "0.1.0", | ||
"description": "Add remote-control features to your webapp", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/h-w-z/remood.js.git" | ||
}, | ||
"keywords": [ | ||
"socket" | ||
], | ||
"author": "HWZ", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/h-w-z/remood.js/issues" | ||
}, | ||
"homepage": "https://github.com/h-w-z/remood.js", | ||
"dependencies": { | ||
"express": "~4.12.3", | ||
"lodash": "~3.6.0", | ||
"pluralize": "~1.1.2", | ||
"randomstring": "~1.0.5", | ||
"socket.io": "~1.3.5" | ||
}, | ||
"devDependencies": { | ||
"amp-each": "~1.0.1", | ||
"amp-filter": "~1.0.1", | ||
"amp-pluck": "~1.0.0", | ||
"browserify": "~9.0.8", | ||
"del": "~1.1.1", | ||
"gulp": "~3.8.11", | ||
"gulp-sourcemaps": "~1.5.1", | ||
"gulp-uglify": "~1.2.0", | ||
"gulp-util": "~3.0.4", | ||
"jquery": "~2.1.3", | ||
"socket.io-client": "~1.3.5", | ||
"vinyl-buffer": "~1.0.0", | ||
"vinyl-source-stream": "~1.1.0" | ||
} | ||
} |