GithubHelp home page GithubHelp logo

mean-socket's Introduction

Annoucement

This package is now obsolete. The new package which is actively being developed is at https://git.mean.io/linnovate/socket.

As new code is no longer being pushed on this repo, it is unlikely that issues will be tracked here effectively. So the new alternative should be used as soon as possible as issues will be acitvely tracked and fixed on git.mean.io for all mean-packages.

#Instructions Please do mean install socket to install the package

mean-socket's People

Contributors

liorkesos avatar pratik60 avatar rivkatzur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mean-socket's Issues

Client-site ip

Hi there,
the module needs to work not only locally, but on a given system. p2p over sockets on a single machine is not that interesting (and the auth-system of mean.io does not really help at this point).
Is there a way to set the hosts-IP address during installation of the package? I'm thinking about the post-installation process or the aggregation of the javascript files during building/starting the server-process. One would have to modify the 'baseUrl' in '/public/services/meanSocket.js'. Is it worth to think about that? Getting the IP-address should be possible on most systems (with one established fixed eth), but how to bring it automatically in the file before releasing it to the client with the 'aggregate.js'?

mean.io socket not working on server

Hi I use the mean socket package , it works fine on my local system but on server it throughs error

WebSocket connection to 'ws://ip.ip.ip.ip:3000/socket.io/?EIO=2&transport=websocket&sid=Ja9UDR8v1rCoHTKUAAAN' failed: Connection closed before receiving a handshake response

POST http://ip.ip.ip.ip:3000/socket.io/?EIO=2&transport=polling&t=1423493734491-8&sid=Ja9UDR8v1rCoHTKUAAAN 400 (Bad Request)

Response to the request mention above is
{
"code": 1,
"message": "Session ID unknown"
}

Proposed alternate solution

@rivkatzur Thanks for this awesome plugin, it certainly helped me get started integrating chat into my application. However, I faced a few issues when I tried to deploy it in production environment, as my own app was running on one port, and this particular plugin needed to listen on another port of its own.

So, I had to rethink the implementation and finally came up with a solution listed below. The solution is totally non-invasive and would be a good starting point for anyone else who's still looking to add chat to their mean.io app.

app.js

In this file, I just invoke the code that creates and sets up a socket.io object for me, which is then passed to the routes module.

'use strict';

/*
 * Defining the Package
 */
var Module = require('meanio').Module;

var MeanSocket = new Module('chat');

/*
 * All MEAN packages require registration
 * Dependency injection is used to define required modules
 */
MeanSocket.register(function(app, http) {

    var io = require('./server/config/socketio')(http);

    //We enable routing. By default the Package Object is passed to the routes
    MeanSocket.routes(io);

    return MeanSocket;
});

server/config/socketio.js

This file simply configures the socket.io object. Please note that I had to upgrade meanio module to version 0.5.26 for this work, as http object (express server) is not available in older meanio versions. Moreover, in case you want to use ssl, you can inject https instead of http.

'use strict';

var config = require('meanio').loadConfig(),
    cookie = require('cookie'),
    cookieParser = require('cookie-parser'),
    socketio = require('socket.io');

module.exports = function(http) {

    var io = socketio.listen(http);

    io.use(function(socket, next) {
        var data = socket.request;

        if (!data.headers.cookie) {
            return next(new Error('No cookie transmitted.'));
        }

        var parsedCookie = cookie.parse(data.headers.cookie);
        var sessionID = parsedCookie[config.sessionName];
        var parsedSessionID = cookieParser.signedCookie(parsedCookie[config.sessionName], config.sessionSecret);

        if (sessionID === parsedSessionID) {
            return next(new Error('Cookie is invalid.'));
        }

        next();
    });

    return io;
};

routes/chat.js

Finally, use the routes file to define the socket events, etc.

'use strict';

// The Package is passed automatically as first parameter
module.exports = function(MeanSocket, io) {

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

        console.log('Client Connected');

        socket.on('authenticate', function(data, callback) {

        });
    });
};

Thoughts?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.