如何在 Agora.io 中全局访问摄像头和麦克风

How Can Access Camara And Mic Globally in Agora.io

我正在使用 Angular 7Angora.Io,我的问题是当我在本地 运行 我的 Angular 项目时,我成功地访问了我的相机和麦克风,但是当我尝试像“192.105.2.448”这样的全局 运行 然后我无法访问我的相机和麦克风,并抛出这样的错误。请帮帮我!

join(): void {

    this.client.setClientRole('host');
    this.localStream = this.agoraService.createStream({ streamID: this.uid, audio: true, video: true, screen: false });
    this.localStream.setVideoProfile('720p_3');
    this.assignLocalStreamHandlers();
    this.init();
    this.client.join(null , this.channel.value, this.uid);
}

publish(): void {

    this.liveplay = true;
    this.client.publish(this.localStream, err =>   console.log('Publish local stream error: ' + err));  }

protected init(): void {

    this.localStream.init(
        () => {
            // The user has granted access to the camera and mic.
            console.log('getUserMedia successfully' , this.localStream);
            this.localStream.play('agora_local');
            this.connected = true;
        },
        err => console.log('getUserMedia failed', err)
    );
}


private assignLocalStreamHandlers(): void {

    console.log('==========>>>>>>>2 ');
    this.localStream.on(StreamEvent.MediaAccessAllowed, () => {
        console.log('accessAllowed --->>> ', this.localStream);
    });
    // The user has denied access to the camera and mic.
        this.localStream.on(StreamEvent.MediaAccessDenied, () => {
        console.log('accessDenied');
    });
}

11:35:01:76 Agora-SDK [ERROR]: [3] Media access NOT_SUPPORTED: Only secure origins are allowed

[Deprecation] getUserMedia() no longer works on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS.

我不喜欢 Angular 但因为 agora 提供了一些 api 关于自定义 Audio/Video 来源。你可以查看 https://docs.agora.io/en/Interactive%20Broadcast/custom_video_web?platform=Web

您遇到的问题不是 Agora SDK 独有的问题,而是任何网络浏览器的预期行为。 为了访问 CameraMicrophone 权限,所有浏览器都要求您使用安全连接(阅读:HTTPS)并将阻止访问任何未通过安全连接访问的网站。

浏览器确实有一项特殊功能,它已列入白名单 localhost,因此任何 运行 在本地使用 localhost 的项目都将被允许访问设备权限。这就是为什么您的项目可以 "locally" 而不是 "globally".

为了能够测试您的项目 "globally" 然后您将需要使用带有 ssl 证书的域以便您看到 https在 url。虽然可以将 HTTPS 与 IP 地址一起使用,但不常见也不推荐 (Is it possible to have SSL certificate for IP address, not domain name?)

一个选项 (我喜欢使用) 用于测试的是 NGROK (https://ngrok.com),他们提供了一种隧道服务,可以从 "tunnel out"您的机器并提供 https url 使您能够测试在本地机器上 运行ning 的项目。

disclaimer: I am in no way affiliated with NGROK, this is a tool I that I find helpful and choose to use while testing my code, to work around the restrictions imposed by browsers without deploying my work to a remote server.