Example #1
0
module.exports = function rtClient(trntStr, hostStr, user, pass) {
	if (arguments.length < 4) throw new Error('Not enough arguments to function rtClient')

	console.log(hostStr)
	var socket = new SocketIoClient(hostStr)

	socket.on('connect', function () {
		var sha1 = hash('sha1', pass)
		socket.emit('authenticate', user, sha1, function (success) {
			if (success) {
				socket.emit('download torrent', trntStr)
			}
		})
	})

	socket.on('file', save)
	socket.on('disconnect', quit.bind(null, 'Disconnected from server'))
	socket.on('msg', console.log)
	socket.on('quit', quit)

	function save(url, filename, next) {
		var src = request(hostStr + url)
		console.log('save', hostStr + url, filename)
		var dst = fs.createWriteStream(filename)
		src.pipe(dst)
		src.on('end', next)
	}
}
        socket.on('connect', () => {
            socket.on('onConnected', (data) => {
                const gameClient = ClientGame.create({
                    options: this.props.gameSettings
                });

                const network = Network.create({
                    game: gameClient,
                    pingTimeout: this.props.gameSettings.pingTimeout,
                    socket
                });

                gameClient.setNetwork(network);

                this.setState({
                    user: data.user,
                    socket: socket,
                    rooms: data.rooms,
                    gameClient: gameClient
                });
            });

            socket.on('roomCreated', (data) => {
                this.setState({
                    rooms: this.state.rooms.filter(room => room.id !== data.room.id).concat(data.room)
                });
            });

            socket.on('roomDeleted', (data) => {
                this.setState({
                    rooms: this.state.rooms.filter(room => room.id !== data.roomId)
                });
            });

            socket.on('onJoinedRoom', (data) => {
                this.setState({
                    currentRoomId: data.room.id
                });
            });

            socket.on('onLeftRoom', () => {
                this.setState({
                    currentRoomId: null
                });
            });

            socket.emit('register', {
                name: this.props.name
            });
        });
Example #3
0
function createServer (httpServer, casino) {
  var io = require('socket.io')(httpServer);

  io.on('connection', socket => {
    var query = socket.handshake.query;
    var name = query.name;
    var spectator = JSON.parse(query.spectator);
    var game = casino.join({
      name: name,
      onGameStart (state, makeBet) {
        socket.emit('onGameStart', [ state ], makeBet);
      },
      onGameTurn (state, makeMove) {
        socket.emit('onGameTurn', [ state ], makeMove);
      },
      onGameEnd (state) {
        socket.emit('onGameEnd', [ state ]);
      }
    }, {
      spectator: spectator
    });

    socket.on('quit', () => socket.disconnect());
    socket.on('disconnect', () => game.quit());
  });
}
  componentWillMount: function() {
    var self = this

    io.on('data-messages', function(messages) {
      self.setState({messages: messages});
    });

    io.on('data-files', function(files) {
      self.setState({files: files});
    });

    io.on('data-playlists', function(playlists) {
      self.setState({playlists: playlists});
    });

  },
Example #5
0
 getMessage = new Promise( (resolve, reject) => {
   const io = readline.createInterface({
     input: process.stdin,
     output: process.stdout
   })
   let buffer = []
   io.write('Enter message to send: ')
   io.on('line', (line) => {
     if(line) {
       buffer.push(line)
     }
     else {
       io.close()
     }
   })
   io.on('close', () => resolve(buffer.join('\n')) )
 })
 constructor(services) {
   this.services = {};
   this.socket = new SocketClient();
   this.feathers = Feathers().configure(Feathers.socketio(this.socket));
   this.socket.on('authenticated', (data) => {
     window.controller.signals.feathers.setUser({data});
   });
   for (let service of services) { this.addService(service); };
 }
Example #7
0
File: index.js Project: mapfap/chat
exports.server = function() {
  
  var express = require('express')
  var app = express()
  var server = require('http').createServer(app)
  var io = require('socket.io').listen(server)

  io.on('connection', function(socket) {
    socket.on('pressure', function(pressure) {
      io.sockets.emit('pressure', pressure)
    })
  })

  app.use(express.static(__dirname + '/static'))

  return server

}
Example #8
0
onmessage = function (event: {data: string}) {

    const data = JSON.parse(event.data);

    if (data.type === 'init') {
        const {endpoint, options} = data;
        socket = socketIO(endpoint, options);
    }

    if (data.type === 'observe') {
        const eventFunction = function (reply) {
            doPostMessage({
                type: 'emit',
                event: data.event,
                data: reply
            });
        };
        events[data.id] = eventFunction;
        socket.on(data.event, eventFunction);
    }

    if (data.type === 'unobserve') {
        const eventFunction = events[data.id];
        socket.removeListener(data.event, eventFunction);
        delete events[data.id];
    }

    if (data.type === 'subscribe') {
        socket.emit('subscribe', data.event, ...data.values);
    }

    if (data.type === 'send') {
        socket.send(data.message, (reply) => {
            doPostMessage({
                type: 'sendReply',
                reply: reply,
                id: data.id
            });
        });
    }
};
Example #9
0
File: api.js Project: knsv/crib-mq
module.exports.create = function(port){

    console.log('Creating message queue');
    var io         = require('socket.io')();
    var middleware = require('socketio-wildcard')();

    io.use(middleware);


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

        socket.on('*', function(message){
            log.trace('Got => ',message.data[0],' ',message.data[1]);
            io.emit(message.data[0], message.data[1]);

        });

        socket.on('disconnect', function (data) { console.log('Got disconnect',data);});


    });

    io.listen(port);
};
    componentWillMount () {
        const socket = new SocketClient(this.props.serverUrl);

        socket.on('connect_error', () => {
            this.props.onLobbyError('Error connecting to server.');
            socket.close();
        });

        socket.on('connect', () => {
            socket.on('onConnected', (data) => {
                const gameClient = ClientGame.create({
                    options: this.props.gameSettings
                });

                const network = Network.create({
                    game: gameClient,
                    pingTimeout: this.props.gameSettings.pingTimeout,
                    socket
                });

                gameClient.setNetwork(network);

                this.setState({
                    user: data.user,
                    socket: socket,
                    rooms: data.rooms,
                    gameClient: gameClient
                });
            });

            socket.on('roomCreated', (data) => {
                this.setState({
                    rooms: this.state.rooms.filter(room => room.id !== data.room.id).concat(data.room)
                });
            });

            socket.on('roomDeleted', (data) => {
                this.setState({
                    rooms: this.state.rooms.filter(room => room.id !== data.roomId)
                });
            });

            socket.on('onJoinedRoom', (data) => {
                this.setState({
                    currentRoomId: data.room.id
                });
            });

            socket.on('onLeftRoom', () => {
                this.setState({
                    currentRoomId: null
                });
            });

            socket.emit('register', {
                name: this.props.name
            });
        });

        if (debugMode) {
            this.onCreateRoom();
        }
    }
Example #11
0
var io = require("socket.io-client");
var stripAnsi = require('strip-ansi');
var scriptElements = document.getElementsByTagName("script");
io = io.connect(typeof __resourceQuery === "string" && __resourceQuery ?
	__resourceQuery.substr(1) :
	scriptElements[scriptElements.length-1].getAttribute("src").replace(/\/[^\/]+$/, "")
);

var hot = false;
var initial = true;
var currentHash = "";

io.on("hot", function() {
	hot = true;
	console.log("[WDS] Hot Module Replacement enabled.");
});

io.on("invalid", function() {
	console.log("[WDS] App updated. Recompiling...");
});

io.on("hash", function(hash) {
	currentHash = hash;
});

io.on("still-ok", function() {
	console.log("[WDS] Nothing changed.")
});

io.on("ok", function() {
	if(initial) return initial = false;
Example #12
0
$(function() {
	var body = $("body").html(require("./page.jade")());
	var status = $("#status");
	var okness = $("#okness");
	var $errors = $("#errors");
	var iframe = $("#iframe");
	var header = $(".header");
	var hot = false;
	var currentHash = "";

	var contentPage = window.location.pathname.substr("/webpack-dev-server".length) + window.location.search;

	status.text("Connecting to socket.io server...");
	$errors.hide(); iframe.hide();
	header.css({borderColor: "#96b5b4"});
	io = io.connect();

	io.on("hot", function() {
		hot = true;
		iframe.attr("src", contentPage + window.location.hash);
	});

	io.on("invalid", function() {
		okness.text("");
		status.text("App updated. Recompiling...");
		header.css({borderColor: "#96b5b4"});
		$errors.hide(); if(!hot) iframe.hide();
	});

	io.on("hash", function(hash) {
		currentHash = hash;
	});

	io.on("still-ok", function() {
		okness.text("");
		status.text("App ready.");
		header.css({borderColor: ""});
		$errors.hide(); if(!hot) iframe.show();
	});

	io.on("ok", function() {
		okness.text("");
		$errors.hide();
		reloadApp();
	});

	io.on("warnings", function(warnings) {
		okness.text("Warnings while compiling.");
		$errors.hide();
		reloadApp();
	});

	io.on("errors", function(errors) {
		status.text("App updated with errors. No reload!");
		okness.text("Errors while compiling.");
		$errors.text("\n" + stripAnsi(errors.join("\n\n\n")) + "\n\n");
		header.css({borderColor: "#ebcb8b"});
		$errors.show(); iframe.hide();
	});

	io.on("proxy-error", function(errors) {
		status.text("Could not proxy to content base target!");
		okness.text("Proxy error.");
		$errors.text("\n" + stripAnsi(errors.join("\n\n\n")) + "\n\n");
		header.css({borderColor: "#ebcb8b"});
		$errors.show(); iframe.hide();
	});

	io.on("disconnect", function() {
		status.text("");
		okness.text("Disconnected.");
		$errors.text("\n\n\n  Lost connection to webpack-dev-server.\n  Please restart the server to reestablish connection...\n\n\n\n");
		header.css({borderColor: "#ebcb8b"});
		$errors.show(); iframe.hide();
	});

	iframe.load(function() {
		status.text("App ready.");
		header.css({borderColor: ""});
		iframe.show();
	});

	function reloadApp() {
		if(hot) {
			status.text("App hot update.");
			try {
				iframe[0].contentWindow.postMessage("webpackHotUpdate" + currentHash, "*");
			} catch(e) {
				console.warn(e);
			}
			iframe.show();
		} else {
			status.text("App updated. Reloading app...");
			header.css({borderColor: "#96b5b4"});
			try {
				var old = iframe[0].contentWindow.location + "";
				if(old.indexOf("about") == 0) old = null;
				iframe.attr("src", old || (contentPage + window.location.hash));
				old && iframe[0].contentWindow.location.reload();
			} catch(e) {
				iframe.attr("src", contentPage + window.location.hash);
			}
		}
	}

});
Example #13
0
	});
	
	textGrabber.on("data", function (data) {
		data = data.toString();
		var contentIn = new payloads.TranscriptContentInPayload(data);
		communication.routeMessage(
			constants.COMMUNICATION_TARGET_TRANSCRIPT,
			contentIn.getPayload(),
			constants.COMMUNICATION_SOCKET_SERVER);
	});
} else if(config.stream.type == constants.STREAM_TYPE_SERVER) {
	ioClient = ioClient.connect(config.stream.location, {
		port: config.stream.port
	});
	ioClient.on('connect', function() {
		console.log("Connected to stream");
	});
	ioClient.on('message', function(message) {
		if(message.payload.type == constants.COMMUNICATION_TRANSCRIPT_PAYLOAD_CONTENT) {
			var contentIn = new payloads.TranscriptContentInPayload(message.payload.data.body);
			communication.routeMessage(
				constants.COMMUNICATION_TARGET_TRANSCRIPT,
				contentIn.getPayload(),
				constants.COMMUNICATION_SOCKET_SERVER);
		}
	});
}

// Proxy Mode
if(config.proxy.mode == constants.PROXY_MODE_ENABLED) {
	ioProxy = ioClient.connect(config.proxy.location, {