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

Cannot set property ws of undefined #77

Open
quesurifn opened this issue Jun 22, 2017 · 2 comments
Open

Cannot set property ws of undefined #77

quesurifn opened this issue Jun 22, 2017 · 2 comments

Comments

@quesurifn
Copy link

quesurifn commented Jun 22, 2017

Hello,

On connection I get

Users/kylecameronryanfahey/Documents/Github/serverSentiment/node_modules/express-ws/lib/index.js:69
    request.ws = socket;
               ^

TypeError: Cannot set property 'ws' of undefined
    at WebSocketServer.<anonymous> (/Users/kylecameronryanfahey/Documents/Github/serverSentiment/node_modules/express-ws/lib/index.js:69:16)
    at emitTwo (events.js:106:13)
    at WebSocketServer.emit (events.js:194:7)
    at handleUpgrade (/Users/kylecameronryanfahey/Documents/Github/serverSentiment/node_modules/ws/lib/WebSocketServer.js:88:16)
    at WebSocketServer.completeUpgrade (/Users/kylecameronryanfahey/Documents/Github/serverSentiment/node_modules/ws/lib/WebSocketServer.js:270:5)
    at WebSocketServer.handleUpgrade (/Users/kylecameronryanfahey/Documents/Github/serverSentiment/node_modules/ws/lib/WebSocketServer.js:197:10)
    at Server.WebSocketServer._ultron.on (/Users/kylecameronryanfahey/Documents/Github/serverSentiment/node_modules/ws/lib/WebSocketServer.js:87:14)
    at emitThree (events.js:116:13)
    at Server.emit (events.js:197:7)
    at onParserExecuteCommon (_http_server.js:462:14)
    at onParserExecute (_http_server.js:421:3)

Google doesn't turn up anything...

Bin:

(() => {
 const APP = require('../app.js');
})();

app.js

'use strict';

var express = require('express');
var app = express();
var expressWs = require('express-ws')(app);
var port = 3000;

app.get('/', function(req, res) {
  res.send('Congratulations, you sent a GET request!');
  console.log('Received a GET request and sent a response');
});

app.listen(port, function() {
  console.log('App now listening on port', port);
});

require('dotenv').config()

var Twit = require('twit')

var T = new Twit({
  consumer_key:         process.env.TWITTER_CONSUMER_KEY,
  consumer_secret:      process.env.TWITTER_CONSUMER_SECRET,
  access_token:         process.env.TWITTER_ACCESS_TOKEN,
  access_token_secret:  process.env.TWITTER_ACCESS_SECRET,
})


app.use(function (req, res, next) {
  console.log('middleware');
  req.testing = 'testing';
  return next();
});

app.get('/', function(req, res, next){
  console.log('get route', req.testing);
  res.end();
});

app.ws('/', function(ws, req) {
  ws.on('message', function(msg) {
    console.log(msg);
  });
  console.log('socket', req.testing);
});

app.ws('/tweets', function(ws, req) {
  ws.on('connect', function(req) {
    console.log(req)
    ws.send(req);
  });
  const stream = T.stream('statuses/filter', { track: ['POTUS', 'trump', 'president', 'realDonaldTrump'] })
  stream.on('tweet', function(tweet){
    console.log(tweet)
    ws.send(tweet)
  })
})

app.ws('/trump', function(ws, req) {
  const stream = T.stream('statuses/user_timeline', { screen_name: ['POTUS', 'realDonaldTrump'] })
  stream.on('tweet', function(tweet) {
    console.log(tweet)
    ws.send(tweet)
  })
})
@yacinehmito
Copy link

yacinehmito commented Aug 27, 2017

I tracked the error to here: websockets/ws#1104

I'll try a fix.

EDIT: It turns out that the master branch already handles this. The updated code has simply never been published.

@HenningM, would you mind bumping the version and releasing?

@yacinehmito
Copy link

I just published @yacinehmito/express-ws if you urgently need a version of express-ws that works with ws v3.0.

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