javascriptliveserversocket.io-client

Is there a way of solving Uncaught Reference error and stating correct ORIGIN of a socket.io server on the client side when using vscode live server


I ran a socket.io client code using the liveserver extension on vscode and because i am using the version 2.5.0 i had to make use of socket.io wildcard I then ran the code and got 2 errors in the console..here is the picture from the first error there's apparently a problem with the second line of the code which is var BuiltInEmitter = require('events').EventEmitter

'use strict'
var BuiltInEmitter = require('events').EventEmitter

module.exports = function (CustomEmitter) {
  var Emitter = CustomEmitter || BuiltInEmitter
  var emit = Emitter.prototype.emit

  function onevent (packet) {
    var args = packet.data || []
    if (packet.id != null) {
      args.push(this.ack(packet.id))
    }
    emit.call(this, '*', packet)
    return emit.apply(this, args)
  }

  return function (socket, next) {
    if (socket.onevent !== onevent) {
      socket.onevent = onevent
    }
    return next ? next() : null
  }
}

the other error is from the client code I inputted var patch = require('socketio-wildcard')(io.Manager); patch(socket);.... it doesn't recognise the 'require' ..And as for the other question, the server I'm trying to make this connection to has a set ORIGIN header let's say its https://xterm.com how can I make the ORIGIN header on the client side https://xterm.com instead of http://127.0.0.1:5500 ... thanks


Solution

  • For the wildcard issue, I had to install the library.. and as for the origin issue.. it can't be changed in the browser.. the browser automatically sets it.. if you want to change it you could make use of proxy servers