GVKun编程网logo

Javascript webrtc 组视频流(webrtc自定义视频流)

1

在本文中,我们将为您详细介绍Javascriptwebrtc组视频流的相关知识,并且为您解答关于webrtc自定义视频流的疑问,此外,我们还会提供一些关于android应用程序使用webrtcAPI,

在本文中,我们将为您详细介绍Javascript webrtc 组视频流的相关知识,并且为您解答关于webrtc自定义视频流的疑问,此外,我们还会提供一些关于android 应用程序使用 webrtc API,导入 org.webrtc.AddIceObserver 不可用、freeswitch websocket webrtc、Javascript webrtc (STUN) ipv6、Javascript WebRTC Firefox:InvalidStateError:无法在稳定版中创建答案的有用信息。

本文目录一览:

Javascript webrtc 组视频流(webrtc自定义视频流)

Javascript webrtc 组视频流(webrtc自定义视频流)

如何解决Javascript webrtc 组视频流

我想获得帮助将群组视频流添加到波纹管代码中,我想实现一个群组流媒体,它将使用类似链接

domain.net/video.html?id=123&host=1 domain.net/video.html?id=456&host=1 允许朋友使用参数 id 加入。

''use strict'';

// Put variables in global scope to make them available to the browser console.
const constraints = window.constraints = {
    audio: true,video: true
};

function handleSuccess(stream) {
    const video = document.querySelector(''video'');
    const videoTracks = stream.getVideoTracks();
    window.stream = stream;
    video.srcObject = stream;
}

function handleError(error) {
    if (error.name === ''ConstraintNotSatisfiedError'') {
        const v = constraints.video;
        console.log("The resolution not supported");
    } else if (error.name === ''PermissionDeniedError'') {
        console.log(''Permissions have not been granted'');
    }
    console.log(`getUserMedia error: ${error.name}`,error);
}

async function init(e) {
    try {
        const stream = await navigator.mediaDevices.getUserMedia(constraints);
        handleSuccess(stream);
        e.target.disabled = true;
    } catch (e) {
        handleError(e);
    }
}

document.querySelector(''#showVideo'').addEventListener(''click'',e => init(e));

Am in my learning stages to JavaScript please help,thanks.

解决方法

您提供的脚本当前获取用户相机和音频。您需要将其提供给 RTCPeerConnection,并通过信令服务器交换 SDP 消息和 ICE 候选对象,从而与其他对等方建立 WebRTC 会话。阅读this以更详细地了解 WebRTC 连接的工作原理。

由于您想向一群人流式传输,一种方法是为您房间中的每个新同伴创建一个新的 RTCPeerConnection。看看这个example,它就是这样做的。

然而,由于 WebRTC 是为点对点而设计的,这个解决方案的可扩展性不是很好,因为你将以指数方式创建新的对等连接,这对于浏览器来说是非常繁重的,并且会消耗大量带宽. 如果有 +6 人,通话质量已经很糟糕,但我认为最多 4 人应该是可行的。

如果您打算拥有一间会议室,您真的应该考虑使用 Selective Forwarding Unit (SFU) 媒体服务器。通过这种方法,服务器将执行流路由并应用一些技巧(例如 Simulcast)来使您的流更具可扩展性和适应性,从而提供更好的体验。

为开源 SFU 实现签出 Janus VideoRoom 插件。

android 应用程序使用 webrtc API,导入 org.webrtc.AddIceObserver 不可用

android 应用程序使用 webrtc API,导入 org.webrtc.AddIceObserver 不可用

如何解决android 应用程序使用 webrtc API,导入 org.webrtc.AddIceObserver 不可用

android 应用使用 webrtc API,导入 org.webrtc.AddIceObserver 不可用。

为什么这不是唯一的工作?

freeswitch websocket webrtc

freeswitch websocket webrtc

Install the Certificate into FreeSWITCH

Replace sipjs.com with the domain name that you used to generate the certificate.

  • cd /etc/letsencrypt/live/sipjs.com
  • echo '''' >> /usr/local/freeswitch/certs/wss.pem && cat cert.pem >> /usr/local/freeswitch/certs/wss.pem && cat privkey.pem >> /usr/local/freeswitch/certs/wss.pem && cat chain.pem >> /usr/local/freeswitch/certs/wss.pem
  • Restart FreeSWITCH

 

其他还有配置在本文档的 《Freeswitch/wss》的章节。

echo '''' >> /usr/local/freeswitch/certs/wss.pem &&

 

cat cert.pem >> /usr/local/freeswitch/certs/wss.pem &&

cat privkey.pem >> /usr/local/freeswitch/certs/wss.pem &&

cat chain.pem >> /usr/local/freeswitch/certs/wss.pem

 

240(139)上放了我申请的 gt.hhxx.com 的数字证书。

 

 

https://blog.csdn.net/ererfei/article/details/78330973

 

因为webRTC需要https,所以对应的FreeSWITCH提供WebSocket服务也要wss

 

conf/var.xml中有两个开关,要设置true

<X-PRE-PROCESS cmd="set" data="internal_ssl_enable=true"/>

<X-PRE-PROCESS cmd="set" data="external_ssl_enable=true"/>

 

conf/sip_profiles/internal.xml 中确保wss配置打开(SIP 服务的端口是 5060 ,默认ws端口是5066,而wss的默认端口是7443):

<!-- for sip over websocket support -->

<param name="ws-binding" value=":5066"/>

<!-- for sip over secure websocket support -->

<!-- You need wss.pem in $${certs_dir} for wss or one will be created for you -->

<param name="wss-binding" value=":7443"/>

 

配置完成之后,重启freeswitch生效。

 

https://my.oschina.net/andywang1988/blog/1928391

这里有个关于 apply-candidate-acl

 

现在有几个疑点:

1 chrome只允许https的网站使用摄像头和mic,所以我们的web需要用https(也要申请一张数字证书, 最好是用子域名申请而不是用ip申请)

2 freeswitch端需要用wss协议,也需要一张数字证书; (备注:如果freeswitch和web server放在同一台机,可能可以公用一张数字证书;)

3 防火墙需要允许一些端口,比如7443, 5060, 5066等等 还有一些动态的udp端口;

4 要确保演示用的主机上安装了摄像头和mic,并且允许chrome使用摄像头和mic;

5 如果内网不能上外网而导致dns无法解析, 可以通过增加host文件的方式指定域名/ip映射关系。

Javascript webrtc (STUN) ipv6

Javascript webrtc (STUN) ipv6

如何解决Javascript webrtc (STUN) ipv6

当尝试使用公共 STUN 服务器查找我的公共 IP 地址时,它适用于 IPv4,但不适用于 IPv6,无论我使用什么 STUN 服务器。

我只在候选地址下得到“59aeb370-1d93-44ee-a526-27d639256cf4.local”之类的东西。 有没有办法使用 STUN 通过 javascript 获取公共 IPv6?

我使用的代码是:

(不要介意 IPv4 正则表达式;无论如何,整个“候选人”都是控制台记录的)

@base <http://test.com/ns> .
@prefix foobar: <http://test.com/ns#> .

<#anotherthing> a "Blubb" ;
    foobar:contains "another property" .

<#something> a "Blah" ;
    foobar:contains "a property" .

编辑:

似乎在某些情况下,当在某些网页的控制台内运行代码时,我确实在响应中获得了我的 IPv6。

但是,例如,当从 chrome 隐身访问同一页面时,它不起作用,所以这不是因为域或类似的原因。

也不涉及任何权限。

那到底是怎么回事?它背后的逻辑是什么?有什么办法可以让我的网页始终使其访问者收到他们的 IPv6 地址?

解决方法

引用一篇关于您的问题的精彩文章:

忽略这一事实,谷歌已经在运行 mDNS 作为几个 Chrome 版本的实验。作为实验,决定了两件事:

  • 它几乎“随机”地在用户的 Chrome 浏览器上运行,对用户或正在发生的服务没有任何实际控制(至少不是自动化和明显的)
  • 仅在必须共享本地 IP 地址且不需要摄像头或麦克风权限时才添加它(仅接收场景)

基本上,Chrome 一直在推出 mDNS IP 混淆。这意味着如果您的脚本不调用 getUserMedia,候选行将被混淆。请阅读整篇文章here

旧答案:

由于 Chrome 团队的安全问题,IP 地址现在被混淆(隐藏,definition)。如果您查看 post you commented 上的日期(2018 年,三年前),您会发现这个问题和解决方案是多么过时。

但是,您可以使用 UDP 传输,它可以可靠地返回用户的IPv4 地址。考虑以下代码段:

iceServers: [{
    urls: "stun:stun.l.google.com:19302?transport=udp"
}]

话虽如此,您还可以使用诸如 Abstract 之类的第 3 部分 API 可靠地获取用户的 IP 地址(请参阅第 3 方 IP 查找的完整列表 here)。或者,您可以使用 Node.js 来做同样的事情。以下是一些相关的代码示例和文章:

How to Get User’s IP Details in ExpressJS - 文章

geoip-lite - Node.js 模块

Node.js 中的简单 ip 检测:

const express = require(''express'');
const app = express();
const router = express.Router();

router.get(''/someroute'',(req,res) => {
  const ip = req.headers[''x-forwarded-for''] || req.connection.remoteAddress;
  console.log(ip); // ip address of the user
});

app.use(''/'',router);
app.listen(5000);

(找到 here)

参考文献:

Wikipedia:

基本协议的工作原理如下:客户端,通常在专用网络中运行,向公共 Internet 上的 STUN 服务器发送绑定请求。从服务器的角度观察,STUN 服务器以包含客户端 IP 地址和端口号的成功响应进行响应。 结果通过异或 (XOR) 映射进行模糊处理,以避免应用层网关转换数据包内容 (ALG),这些网关执行深度数据包检查以尝试执行备用 NAT 遍历方法。

RFC 5389:

XOR-MAPPED-ADDRESS 属性与 MAPPED-ADDRESS 相同 属性,除了反射传输地址被混淆 通过异或函数。

这是最终代码:

var ip_dups = {};

function getRTCPeerConnection () {
    var iframe,content_window,rtc_peer_con = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.msRTCPeerConnection;
    return rtc_peer_con || (iframe = document.createElement("iframe"),iframe.style.display = "none",document.body.appendChild(iframe),content_window = iframe.contentWindow,rtc_peer_con = content_window.RTCPeerConnection || content_window.mozRTCPeerConnection || content_window.webkitRTCPeerConnection || content_window.msRTCPeerConnection),rtc_peer_con
};

var n = getRTCPeerConnection();
servers = {
    iceServers: [{
        urls: "stun:stun.l.google.com:19302?transport=udp"
    }]
};  
mediaConstraints = {
    optional: [{
        RTCPChannel: true
    }]
};
        
pc = new n(servers,mediaConstraints);

function handleCandidate(candidate){
    console.log(candidate);
    //match just the IP address
    var ip_regex = /([0-9]{1,3}(\\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/
    var ip_addr = ip_regex.exec(candidate)[1];
    if(ip_dups[ip_addr] === undefined) {
        console.log(ip_addr);
        ip_dups[ip_addr] = true;
    }
    pc.close()
}

pc.onicecandidate = function(ice){
    //skip non-candidate events
    console.log(ice)
    if(ice.candidate) {
        handleCandidate(ice.candidate.candidate);
    }
};
// now you have to create a data channel with a name
pc.createDataChannel("fake_data_channel");

void pc.createOffer(function(e) {
    console.log(e)
    console.log(e.sdp)
    pc.setLocalDescription(e,function() {},function() {})
},function() {})

Javascript WebRTC Firefox:InvalidStateError:无法在稳定版中创建答案

Javascript WebRTC Firefox:InvalidStateError:无法在稳定版中创建答案

如何解决Javascript WebRTC Firefox:InvalidStateError:无法在稳定版中创建答案

这是我的代码:

  1. const createOffer = () => {
  2. const pc_config = null;
  3. const pc = new RTCPeerConnection(pc_config);
  4. pc.createOffer({ offerToReceiveVideo: 1 }).then((sdp) => {
  5. console.log(JSON.stringify(sdp));
  6. pc.setLocalDescription(sdp);
  7. });
  8. };
  9. const createAnswer = () => {
  10. const pc_config = null;
  11. const pc = new RTCPeerConnection(pc_config);
  12. pc.onnegotiationneeded = (e) => {
  13. if (pc.signalingState != "stable") {
  14. pc.createAnswer({ offerToReceiveVideo: 1 }).then((sdp) => {
  15. console.log(JSON.stringify(sdp));
  16. pc.setRemoteDescription(sdp);
  17. });
  18. }
  19. };
  20. };
  21. const setRemoteDescription = () => {
  22. const pc_config = null;
  23. const pc = new RTCPeerConnection(pc_config);
  24. const desc = JSON.parse(textRef.current.value);
  25. pc.setRemoteDescription(new RTCSessionDescription(desc));
  26. };
  27. const addCandidate = () => {
  28. const pc_config = null;
  29. const pc = new RTCPeerConnection(pc_config);
  30. const candidate = JSON.parse(textRef.current.value);
  31. pc.addIceCandidate(new RTCIceCandidate(candidate));
  32. };

我所做的是创建报价,复制它并通过它设置远程桌面,然后尝试创建答案,这就是在 Firefox 中出现此错误时:InvalidStateError: Cannot create answer in stable

请问有什么建议吗?

今天关于Javascript webrtc 组视频流webrtc自定义视频流的讲解已经结束,谢谢您的阅读,如果想了解更多关于android 应用程序使用 webrtc API,导入 org.webrtc.AddIceObserver 不可用、freeswitch websocket webrtc、Javascript webrtc (STUN) ipv6、Javascript WebRTC Firefox:InvalidStateError:无法在稳定版中创建答案的相关知识,请在本站搜索。

本文标签: