javascript - webrtc 通过 websocket 客户端/服务器连接问题

标签 javascript node.js groovy websocket webrtc

想知道是否有人对我在这里做错了什么有任何想法:

我一直在关注:http://blog.felixhagspiel.de/index.php/posts/create-your-own-videochat-application-with-html-and-javascript

正如所解释的那样,该指南工作得非常好,我已经通过 nodejs 对其进行了测试,并且一切正常。

我现在正在尝试将示例移植到 groovy 中。在 grails 插件中遇到了一些问题。

所以这就是我所在的位置:请原谅实际代码的状态,我的头撞在砖墙上了一会儿:)

所有者/服务器创建房间 - 很好

客户端出现并发送报价(收到报价但客户端上的 websocket 断开连接)

服务器/所有者收到报价,但在尝试发回答复时 - 由于客户端断开连接,因此没有任何内容发回....

https://github.com/vahidhedayati/playground/blob/master/grails-wschat-plugin/src/groovy/grails/plugin/wschat/WsCamEndpoint.groovy#L72

这是 websocket 发送到解析 Action 的扩展类的地方:

https://github.com/vahidhedayati/playground/blob/master/grails-wschat-plugin/src/groovy/grails/plugin/wschat/ChatUtils.groovy#L244

调用:

https://github.com/vahidhedayati/playground/blob/master/grails-wschat-plugin/src/groovy/grails/plugin/wschat/ChatUtils.groovy#L570

https://github.com/vahidhedayati/playground/blob/master/grails-wschat-plugin/src/groovy/grails/plugin/wschat/ChatUtils.groovy#L598

https://github.com/vahidhedayati/playground/blob/master/grails-wschat-plugin/src/groovy/grails/plugin/wschat/ChatUtils.groovy#L575

private void jsonmessageUser(Session userSession,String msg) {
    userSession.getBasicRemote().sendText(msg as String)
}

private void jsonmessageOther(Session userSession,String msg) {
    Iterator<Session> iterator=camsessions?.iterator()
    if (iterator) {
        while (iterator?.hasNext())  {
            def crec=iterator?.next()
            if (crec.isOpen()) {
                def cuser=crec.getUserProperties().get("camuser").toString()
                def cmuser=crec.getUserProperties().get("camusername").toString()
                println "OM ACTIVE USER : ------- ${cuser}"
                if (!cuser.toString().endsWith(cmuser)) {
                    println "----OTHER ||| ${cmuser} ::  ${msg}"
                    crec.getBasicRemote().sendText(msg as String)
                }
            }
        }
    }
}


private void jsonmessageOwner(Session userSession,String msg) {
    Iterator<Session> iterator=camsessions?.iterator()
    if (iterator) {
        while (iterator?.hasNext())  {
            def crec=iterator?.next()
            if (crec.isOpen()) {
                def cuser=crec.getUserProperties().get("camuser").toString()
                def cmuser=crec.getUserProperties().get("camusername").toString()
                if (cuser.toString().endsWith(cmuser)) {
                    println "----OWNER ||| ${cuser} ::  ${msg}"
                    crec.getBasicRemote().sendText(msg as String)
                }
            }
        }
    }

}

现在这是在浏览器上发生的事情:

--- 服务器:

首先在服务器上我们登录到 local.ip 和 remote.ip 是 192.168.1.6 所以在客户端和服务器上都使用相同的 ip 以确保它的所有部分都属于同一连接

http://local.ip.address:8080/testwschat/wsChat/

这给了我们一个聊天用户,我们在上面以 ff 身份登录

然后手动访问webrtc发送器

http://local.ip.address:8080/testwschat/wsChat/webrtcsend?user=ff

webkit client.js?compile=false:305
Thu Oct 02 2014 16:48:23 GMT+0100 (BST) Connection successfully established client.js?compile=false:220
offer received, answer will be created client.js?compile=false:255
Object {sdp: "v=0
↵o=- 5155933685262328996 2 IN IP4 127.0.0.1
↵s…5748 label:c32aa4ec-9238-4045-b791-0a94ba741b41
↵", type: "offer"} client.js?compile=false:62
stream added client.js?compile=false:168
2icecandidate send to room ff client.js?compile=false:177
Thu Oct 02 2014 16:48:38 GMT+0100 (BST) Connection was closed client.js?compile=false:231
icecandidate send to room ff client.js?compile=false:177
WebSocket is already in CLOSING or CLOSED state. client.js?compile=false:28
icecandidate send to room ff client.js?compile=false:177
WebSocket is already in CLOSING or CLOSED state. client.js?compile=false:28
icecandidate send to room ff client.js?compile=false:177
WebSocket is already in CLOSING or CLOSED state. 

--- 在客户端:

首先在我们登录的服务器上 http://remote.ip.address:8080/testwschat/wsChat/

这为我们提供了一个以 cc 身份登录的聊天用户

然后手动访问webrtc接收器

http://remote.ip.address:8080/testwschat/wsChat/webrtcrec?user=ff

sending offer to: ff client.js?compile=false:138
Sending 2 client.js?compile=false:38
4icecandidate send to room ff client.js?compile=false:124
Thu Oct 02 2014 16:48:38 GMT+0100 (BST) Connection was closed client.js?compile=false:231
icecandidate send to room ff client.js?compile=false:124
WebSocket is already in CLOSING or CLOSED state. client.js?compile=false:28
icecandidate send to room ff client.js?compile=false:124
WebSocket is already in CLOSING or CLOSED state. client.js?compile=false:28
icecandidate send to room ff client.js?compile=false:124
WebSocket is already in CLOSING or CLOSED state. client.js?compile=false:28
icecandidate send to room ff client.js?compile=false:124
WebSocket is already in CLOSING or CLOSED state. client.js?compile=false:28
icecandidate send to room ff client.js?compile=false:124
WebSocket is already in CLOSING or CLOSED state. client.js?compile=false:28

根据上面套接字代码中的 printlns 的实际后端 websocket 日志可以在这里看到:

https://gist.github.com/vahidhedayati/6dbd74a1c4a87d373c05

这次通过网页登录来控制 sendServer 值的更多日志,websocket 似乎没有收到 icecandidate json。因为后端没有这个日志..也许它的缓冲区相关..

https://gist.github.com/vahidhedayati/918b731788118de348d0 -- 服务器或所有者浏览器日志

https://gist.github.com/vahidhedayati/a51796f3dcbb14088a31 -- 客户端/其他用户浏览器日志。

最佳答案

伙计们,我认为我上次的调查帮助我回答了我自己的问题,即缓冲区大小。

因此,如果您使用 Java/Groovy 编写代码并希望与 webrtc 交互。你可能会遇到这个问题。解决方法是增加您的

session.setMaxTextMessageBufferSize(1000000)

当用户打开websocket时

@OnOpen
    public void whenOpening(Session userSession,EndpointConfig c,@PathParam("user") String user,@PathParam("viewer") String viewer) {
        if (loggedIn(user)) {
            userSession.setMaxBinaryMessageBufferSize(1024*512)
            userSession.setMaxTextMessageBufferSize(1000000)
            //userSession.setmaxMessageSize(-1L)
            if (viewer.equals(user)) {
                userSession.getUserProperties().put("camuser", user+":"+user);
            }else{
                userSession.getUserProperties().put("camuser", user+":"+viewer);
            }
            if (!camLoggedIn(user)) {
                userSession.getUserProperties().put("camusername", user);
                camsessions.add(userSession)
            }
        }else{
            log.info "could not find chat user ! ${user}"
        }
    }

关于javascript - webrtc 通过 websocket 客户端/服务器连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26164909/

相关文章:

javascript - 我正在尝试使用 "Rick and Morty"REST API 在屏幕上呈现名称,但实际上没有任何内容呈现,并且我的状态没有更新

javascript - 使用 PHP、jQuery 登录网站

javascript - peerjs webrtc调用响应

node.js - 在 mongo 脚本中打印对象

java - 将字符串拆分为相等的部分(java/groovy)

javascript - 将对象数组的值映射到对象属性

javascript - 使用 AND if 语句的多个条件,javascript

javascript - 检查 mongodb 文档是否存在的最快方法是什么?

algorithm - Groovy 中的简单排名算法

testing - spring 尝试在 Mocked 实例中注入(inject) @Autowired 依赖项