2014-10-02 73 views
2

不知道是否有人對我做錯了什麼任何想法:的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的發送到解析操作的擴展類:

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) 
       } 
      } 
     } 
    } 

} 

現在,這是在瀏覽器上會發生什麼:

--- SERVER:

首先在服務器上,我們登錄到哪裏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/

這給我們我們登錄爲立方厘米以上

聊天用戶然後訪問的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值,似乎icecandidate JSON是不是WebSocket的好評。因爲這對後端沒有日誌..也許它的緩衝相關..

https://gist.github.com/vahidhedayati/918b731788118de348d0 - 服務器或所有者的瀏覽器登錄

https://gist.github.com/vahidhedayati/a51796f3dcbb14088a31 - 客戶機/其它用戶瀏覽器記錄。

回答

1

那麼我認爲我最近的調查幫助我回答了我自己的問題,那就是緩衝區大小。

因此,如果您使用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}" 
     } 
    }