opentok-network-test-js icon indicating copy to clipboard operation
opentok-network-test-js copied to clipboard

Constructor Error in Angular 2+

Open JC47 opened this issue 6 years ago • 4 comments

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 avatar Jan 29 '19 00:01 JC47

@JC47 I have the same problem, could you solve it?

FranLopezFreelance avatar Mar 03 '20 21:03 FranLopezFreelance

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

JC47 avatar Mar 04 '20 12:03 JC47

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...

DavyDeDurpel avatar Mar 12 '20 15:03 DavyDeDurpel

@JC47 I have the same problem, could you solve it?

pardeep-k avatar Sep 22 '20 10:09 pardeep-k