Open a Websocket connection from Meteor.js
javascript, meteor, node.js, npm, websocket
Solution
I created a new Meteor package `joncursi:socket-io-client` to solve this problem. Please see https://atmospherejs.com/joncursi/socket-io-client for more detail and example usage. Since I've bundled the NPM binaries into a package for you, you don't have to worry about installing NPM packages, declaring `NPM.require()` dependencies, etc. And best of all, you can deploy to `.meteor.com` without a hitch.
Problem
How can we open a Websockets connection from Meteor? Can we do something like: ``` ws = new WebSocket('ws://localhost/path'); ws.on('open', function() { ws.send('something'); }); ws.on('message', function(message) { console.log('received: %s', message); }); ``` Error: ReferenceError: WebSocket is not defined Using socket.io npm package ``` var io = Meteor.require('socket.io') var socket = io.connect('http://localhost'); ``` Error: TypeError: Object # has no method 'connect' Using ws npm package ``` var WebSocket = Meteor.require('ws'); var ws = new WebSocket('ws://localhost'); ``` Error: Error: Cannot find module '../build/default/bufferutil'