opentok-network-test-js
opentok-network-test-js copied to clipboard
Constructor Error in Angular 2+
I'm using this import statement to instantiate an instance of the test object import * as OT from '@opentok/client'; import NetworkTest, { ErrorNames } from 'opentok-network-test-js';
const otNetworkTest = new NetworkTest(OT, { apiKey: '123456', // Add the API key for your OpenTok project here. sessionId: '1_MX40NzIwMzJ-fjE1MDElGQkJJfn4', // Add a test session ID for that project token: 'T1==cGFydG5lcXN0PQ==' // Add a token for that session here }); And it throws: error TS2345: Argument of type 'typeof OT' is not assignable to parameter of type 'Client'. Type 'OT.Publisher' is not assignable to type 'Publisher'. Types of property 'stream' are incompatible. Type 'OT.Stream' is not assignable to type 'Stream'. Types of property 'videoDimensions' are incompatible. Types of property 'width' are incompatible. Type 'string' is not assignable to type 'number'.
I tried almost everything and anything works
@JC47 I have the same problem, could you solve it?
Sure, for some reason the object interface in node_modules/opentok doesn't fit with a constructor like this, so the solution is modify all the files with that interface object in opentok module
If you don't care about type safety (which in this case is not really needed)
declare var require: any;
const NetworkTest = require('opentok-network-test-js').default;
const ErrorNames = require('opentok-network-test-js').ErrorNames;
And than continue with the example...
@JC47 I have the same problem, could you solve it?