From 5d82b91592efc017dbe5688110913fd0e3bd9220 Mon Sep 17 00:00:00 2001 From: Jan Lelis Date: Sun, 21 Jun 2020 21:49:38 +0200 Subject: [PATCH] Fix passing around turn credentials --- coffee/room.coffee | 6 +++++- coffee/session.coffee | 12 +++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/coffee/room.coffee b/coffee/room.coffee index 9f1590e..bc3e790 100644 --- a/coffee/room.coffee +++ b/coffee/room.coffee @@ -58,7 +58,11 @@ class palava.Room extends @EventEmitter for peer in msg.peers offers = !palava.browser.isChrome() newPeer = new palava.RemotePeer(peer.peer_id, peer.status, @, offers) - @emit "joined", msg.own_id, msg.turn_user, msg.turn_password + if msg.turn_user + turnCredentials = { user: msg.turn_user, password: msg.turn_password } + else + turnCredentials = null + @emit "joined", msg.own_id, turnCredentials @distributor.on 'new_peer', (msg) => offers = msg.status.user_agent == 'chrome' diff --git a/coffee/session.coffee b/coffee/session.coffee index 5fccfba..c5eee6e 100644 --- a/coffee/session.coffee +++ b/coffee/session.coffee @@ -159,10 +159,8 @@ class palava.Session extends @EventEmitter @tearDown(true) @emit 'room_join_error', @room @room.on 'full', => @emit 'room_full', @room - @room.on 'joined', (u, p) => - @turnCredentials = - user: tu - password: tpw + @room.on 'joined', (ownId, turnCredentials) => + @turnCredentials = turnCredentials @emit 'room_joined', @room @room.on 'left', => @emit 'room_left', @room @room.on 'peer_joined', (p) => @emit 'peer_joined', p @@ -173,9 +171,9 @@ class palava.Session extends @EventEmitter @room.on 'peer_stream_removed', (p) => @emit 'peer_stream_removed', p @room.on 'peer_connection_pending', (p) => @emit 'peer_connection_pending', p @room.on 'peer_connection_established', (p) => @emit 'peer_connection_established', p - @room.on 'peer_connection_failed', (p) => - if !p.hasTriedTurn && @turnCredentials - p.tryTurn @turnCredentials + @room.on 'peer_connection_failed', (peer) => + if !peer.hasTriedTurn && @turnCredentials + peer.tryTurn @turnCredentials else @emit 'peer_connection_failed', p @room.on 'peer_connection_disconnected', (p) => @emit 'peer_connection_disconnected', p