I created a component with Angular 2 and Typescript that allow create a video calls using a library Twilio Video. I trying to create a custom typing for typescript of library twilio-video, the way used in other posts like:
declare var Twilio:any;
work for my only when I used a twilio client library, but not with twilio video.
interface Twilio {
//Other declarations here
Video: any;
}
declare namespace Twilio {
//Others interface here like Connection and Device from client library
interface Video {
connect(token: string, options?:Object): Promise;
createLocalTracks(options?:Object): Promise;
//Other declarations of methods
}
}
and finally can declare:
declare var Twilio:Twilio;
With these custom type work a video call, I can create a room and create a local tracks, but cannot use a disable or enable methods from LocalTrack, I review a code of library twilio-video and read about create custom types and I think that the library is necesary used a template like that show here, something like that:
export as namespace Twilio;
export = Video;
declare class Video {
connect(token:string, options: Object): Promise;
createLocalTracks(options?: Object): Promise;
//Other declarations of functions of Video
}
declare namespace Video {
export interface LocalVideoTrack {
new(mediaStream:any, mediaStreamTrack:any, options:Object);
disable():void;
enable():void;
}
}
That way can used as namespace Twilio, but cannot declare nothing using Twilio.Video as library used, I cannot use instanceof to cast a var, and don't have relationship with the code of library.
The primary problem for me is that I cannot declare correctly a custom typescript typing that used all functions declared in twilio video library. I am new using typescript only a few weeks ago.