I want to include socket.io to my meteor-angular2 app. But I'm finding difficulties to add socket.io/socketjs.
I'm trying to explore this https://github.com/Akryum/meteor-socket-io but that is not meteor-angular2.
trying this simple code on server/main.ts
var io = require('socket.io')(server); io.on('connection', function(socket) { socket.emit('welcome', { message: 'Welcome!', id: socket.id }); });
then this error showed on console
Error: Cannot find module './client' W20170307-11:49:09.344(7)? (STDERR) at require (packages\modules-runtime.js:123:19) W20170307-11:49:09.344(7)? (STDERR) at meteorInstall.node_modules.socket.io.lib.index.js (packages\modules.js:1131:14) W20170307-11:49:09.345(7)? (STDERR at fileEvaluate (packages\modules-runtime.js:197:9) W20170307-11:49:09.345(7)? (STDERR) at require (packages\modules-runtime.js:120:16)
Anyone may share config, setup or boilerplate to join meteor-angular2 and socket.io?
To use socket at client side you have to install
socket.io-clientfirst and then need to import it in your component or service for using it.Install
socket.io-clientwithnpm install socket.io-client --save.Import it in Component with
import * as io from 'socket.io-client';Connect socket in your component with below code :