Genvid Forum

Node web-api seems broken


At the moment, the node web-api doesn’t work for me.

Calling IGenvidClient.start() always throws an error:

TypeError: Cannot read property 'createWebSocket' of undefined
    at GenvidClient.start (7f8a16fb6c7a7b8839304325170aa4d9.js:99)
    at 7f8a16fb6c7a7b8839304325170aa4d9.js:18007
    at (<anonymous>)
    at fulfilled (7f8a16fb6c7a7b8839304325170aa4d9.js:17960)
    at <anonymous>

Investigating in the source-code I found the cause, I believe in genvidFactory.js. IGenvidClient.start() tries to create a websocket by calling getFactory().createWebSocket(...), which simply returns _factory.

However, _factory is never set ,and the only function setting it (registerFactory) is called nowhere in the source-code.

A temporary work-around for me was to quickly whip up my own factory and register it before calling IGenvidClient.start()

import { registerFactory } from 'genvid/lib/genvidFactory';

  getWindow: () => window,
  createWebSocket: (url: string, protocols?: string | string[]) => new WebSocket(url, protocols)

This fixes the problem, and I get a stream. Is there something wrong with my setup or did I stumble upon a bug?


We have 3 distributions

  • browser, commonjs and node.

The commonjs distribution is targeting application using modules in a browser and the node distribution is targeting application running in nodejs.

The commonjs distribution creates a factory for you.

Unfortunately, we do not have a sample using it at the moment.