Search code examples
javascriptdenobrowser-api

Deno - access web apis


I am bundling my Deno code for the web using deno bundle and I know the browser has RTCPeerConnection from the WebRTC API which I would like to use.

I thought Deno was aiming to have web compatibility, so I don't see why WebRTC is not planned to be implemented.

But since it isn't at the moment, how can I tell Deno to trust that this global variable exists and to compile?


Solution

  • Using deno bundle will actually run fine for many web APIs that are supported by the Deno language.

    My temporary solution for other apis such as crypto is the following:

    declare crypto: any;
    

    This article might be useful to look at too (see the 'Compiling and bundling' section).


    EDIT: in order to support a wide variety of environments, dependency injection can be a great solution in many cases.