DetectRTC
DetectRTC copied to clipboard
`import DetectRTC from 'detectrtc';` ES6 import giving error on typescript checking
Hi @muaz-khan and all the contributor, I am use detectrtc with my typescript code.
When I try to use ES6 import, it's giving error on typescript checking. PFA for the same.
import DetectRTC from 'detectrtc';

const DetectRTC = require('detectrtc');
This works fine,
Can you please fix this ? So we can use it with ES6 import. Thanks for the help.
Since this issue hasn't had any updates lately and it doesn't look like it gets fixed anytime soon a quick workaround for this issue:
add a custom definitions file where you correct the errors:
// ...
declare namespace DetectRTC {
// ...
export function checkWebSocketsSupport(callback: () => void): any;
// ...
export function DetectLocalIPAddress(callback: (localIpAddress: string) => void): any;
And add this to your tsconfig.json
:
{
"compilerOptions": {
"paths": {
"detectrtc": ["definitions/detectrtc.d.ts"]
}
},
}
Here the definitions folder is a folder where your definition is located. Might be different for your setup.
This should enable you to still use ES6 imports.
@Neeraj-swarnkar I see that the PR for this issue was merged. I was use wildcard for import DetectRTC
import * as DetectRTC from 'detectrtc';
Hi, I had the problem too. I looked if the commit with the fix was available in the latest version currently (1.4.1) alas not. So I imported the master version which has the patch and here's how to fix it temporarily while waiting for a new version.
Change your import in the package.json
to
"detectrtc": "muaz-khan/DetectRTC#master",