From 64c203256854bdd4c1138ef276360b20ad0e3fee Mon Sep 17 00:00:00 2001 From: Zalmoxisus Date: Thu, 21 Jan 2016 11:05:35 +0200 Subject: [PATCH] First release --- .gitignore | 6 ++++++ LICENSE.md | 21 +++++++++++++++++++++ README.md | 30 ++++++++++++++++++++++++++++++ bin/remotedev.js | 10 ++++++++++ bin/worker.js | 27 +++++++++++++++++++++++++++ package.json | 29 +++++++++++++++++++++++++++++ 6 files changed, 123 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE.md create mode 100644 README.md create mode 100755 bin/remotedev.js create mode 100644 bin/worker.js create mode 100644 package.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b7a60ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +node_modules +*.log +.DS_Store +lib +coverage +.idea diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..1a68f55 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2016 Mihail Diordiev + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c5f996 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +RemoteDev Server +================ + +Bridge for connecting [remotedev monitor app](https://github.com/zalmoxisus/remotedev-app) with [Remote Redux DevTools](https://github.com/zalmoxisus/remote-redux-devtools) or [RemoteDev](https://github.com/zalmoxisus/remotedev) using a local server. Running a local server is optional, you may use [remotedev.io](remotedev.io) server instead, which is by default. + +### Installation + +``` +npm install --save-dev remotedev-server +``` + +### Usage + +``` +remotedev --hostname=localhost --port=8000 +``` + +Change `hostaname` and `port` to the values you want. + +### Connect from Android device or emulator + +If you're running an Android 5.0+ device connected via USB or an Android emulator, use [adb command line tool](http://developer.android.com/tools/help/adb.html) to setup port forwarding from the device to your computer: + +``` +adb reverse tcp:8000 tcp:8000 +``` + +### License + +MIT diff --git a/bin/remotedev.js b/bin/remotedev.js new file mode 100755 index 0000000..3de63ae --- /dev/null +++ b/bin/remotedev.js @@ -0,0 +1,10 @@ +#! /usr/bin/env node +var argv = require('minimist')(process.argv.slice(2)); +var SocketCluster = require('socketcluster').SocketCluster; + +var socketCluster = new SocketCluster({ + host: argv.hostname || null, + port: Number(argv.port) || 8000, + workerController: __dirname + '/worker.js', + allowClientPublish: false +}); diff --git a/bin/worker.js b/bin/worker.js new file mode 100644 index 0000000..6a3192f --- /dev/null +++ b/bin/worker.js @@ -0,0 +1,27 @@ +module.exports.run = function(worker) { + var scServer = worker.scServer; + + scServer.addMiddleware(scServer.MIDDLEWARE_EMIT, function (socket, channel, data, next) { + if (channel.substr(0, 3) === 'sc-' || channel === 'respond' || channel === 'log') { + scServer.exchange.publish(channel, data); + } else if (channel === 'log-noid') { + scServer.exchange.publish('log', { id: socket.id, data: data }); + } + next(); + }); + + scServer.on('connection', function(socket) { + socket.on('login', function (credentials, respond) { + var channelName = credentials === 'master' ? 'respond' : 'log'; + worker.exchange.subscribe('sc-' + socket.id).watch(function(msg) { + socket.emit(channelName, msg); + }); + respond(null, channelName); + }); + socket.on('disconnect', function() { + var channel = worker.exchange.channel('sc-' + socket.id); + channel.unsubscribe(); channel.destroy(); + scServer.exchange.publish('log', { id: socket.id, type: 'DISCONNECTED' }); + }); + }); +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..4f9c790 --- /dev/null +++ b/package.json @@ -0,0 +1,29 @@ +{ + "name": "remotedev-server", + "version": "0.0.1", + "description": "Run remotedev monitor on your local server.", + "bin": { + "remotedev": "bin/remotedev.js" + }, + "files": [ + "bin" + ], + "repository": { + "type": "git", + "url": "https://github.com/zalmoxisus/remotedev-server.git" + }, + "keywords": [ + "devtools", + "remotedev" + ], + "author": "Mihail Diordiev (https://github.com/zalmoxisus)", + "license": "MIT", + "bugs": { + "url": "https://github.com/zalmoxisus/remotedev-server/issues" + }, + "homepage": "https://github.com/zalmoxisus/remotedev-server", + "dependencies": { + "minimist": "^1.2.0", + "socketcluster": "^3.0.0" + } +}