Skip to content

Commit

Permalink
Fix passing around turn credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
janlelis committed Jun 21, 2020
1 parent 2999fc8 commit 5d82b91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 5 additions & 1 deletion coffee/room.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
12 changes: 5 additions & 7 deletions coffee/session.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5d82b91

Please sign in to comment.