Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help with socket.io please #272

Closed
TrangNguyen opened this issue Feb 10, 2014 · 3 comments
Closed

help with socket.io please #272

TrangNguyen opened this issue Feb 10, 2014 · 3 comments

Comments

@TrangNguyen
Copy link

Is there a special way to integrate socket.io with mean? I tried adding these lines to server.js

var server = require('http').createServer(app);
//socket io
var io = require('socket.io').listen(server, {
    'log level': 2
});
io.sockets.on('connection', function(socket) {
    console.log('Client Connected');
}); //<<<<<< socket not used, does not console.log
...
server.listen(port); //<<<<<<<< instead of app.listen(port)

and public/js/services/socket.js

angular.module('mean.socket').factory('socket', ['$rootScope',  function ($rootScope) {
    var socket = io.connect();
    return {
... // like Brian Ford did
    }
}]);

app/views/includes/foot.html

<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="/js/services/socket.js"></script>

and public/js/app.js

angular.module('mean', ['ngCookies', 'ngResource', 'ngRoute', 'ui.bootstrap', 'ui.route', 'mean.system', 'mean.articles', 'mean.socket']);
angular.module('mean.socket', []);

When I start the app, "socket.io started" (at least it said so on the terminal) but

Linting public/js/services/socket.js ...ERROR
[L4:C18] W117: 'io' is not defined.
  var socket = io.connect();

and socket is not used. Socket.io is part of package.json, I see no errors on chrome nor firefox, safari ("bad url" localhost) all scripts seems to load as expected. what am I missing? Thanx.

@TrangNguyen
Copy link
Author

i got it working , thanks.

@liorkesos
Copy link
Member

Can you write something about the integration I'd love to host it on our
blog http://blog.mean.io
Lior

On Mon, Mar 3, 2014 at 1:09 PM, Trang [email protected] wrote:

i got it working , thanks.

Reply to this email directly or view it on GitHubhttps://github.com//issues/272#issuecomment-36500425
.

Lior Kesos - http://www.linnovate.net
Linnovate - Community Infrastructure Care
mail: [email protected]
office: +972 722500881
cell: +972 524305252
skype: liorkesos

@TrangNguyen
Copy link
Author

I ended up using token based session with express-jwt, jsonwebtoken, socketio and socketio-jwt so it varies quite a bit from the original mean app. The app is developed as bachelor's project for a communication/interface design student to share sketches in realtime. The sketching part is done with raphael.sketchpad wrapped in an angular directive.
But I can share the concept if you wish.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants