Skip to content

Instantly share code, notes, and snippets.

@NhanHo
Last active December 29, 2016 14:07
Show Gist options
  • Save NhanHo/87c679ca456c83185b82 to your computer and use it in GitHub Desktop.
Save NhanHo/87c679ca456c83185b82 to your computer and use it in GitHub Desktop.
var http = require('http');
var sockjs = require('sockjs-client');
var request = require('request');
var sock = new sockjs('https://screeps.com/socket');
var user_id = "";
var user_name = "";
var password = "";
var sleep = require('sleep');
sock.onopen = function() {
console.log('open');
var x;
request.post({url:"https://screeps.com/api/auth/signin", json:true, body: {email: user_name, password:password }}, function(err,httpResponse,body){
sock.send('auth '+body.token);
});
};
sock.onmessage = function(e) {
console.log(e.data);
if (e.data.substring(0,7 === "auth ok")) {
// Subscribe to your console log
//sock.send("subscribe user:"+user_id+"/console");
//sock.send("subscribe user:+user_id+/cpu");
//sock.send("subscribe room:E8S3");
}
};
sock.onclose = function() {
console.log('close');
};
//sock.close();
var server = http.createServer();
server.listen(9999, '127.0.0.1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment