File tree Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Expand file tree Collapse file tree 3 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -23,4 +23,12 @@ sock = new WebSocket("ws://localhost:4000/websocket")
23
23
24
24
The ` role ` field is a role a peer that received info JSON should use to avoid role conflict.
25
25
26
- 3 . Send any message via WS, it will be forwarded to the other side.
26
+ 3 . Send any message via WS, it will be forwarded to the other side.
27
+
28
+ 4 . When a peer leaves, the other one receives JSON message:
29
+
30
+ ``` json
31
+ {
32
+ "type" : " peer_left"
33
+ }
34
+ ```
Original file line number Diff line number Diff line change @@ -74,8 +74,16 @@ defmodule SignallingServer.Room do
74
74
75
75
state =
76
76
if ref == state . p1_ref do
77
+ if state . p2 do
78
+ send ( state . p2 , { :forward , Jason . encode! ( % { type: "peer_left" } ) } )
79
+ end
80
+
77
81
% { state | p1_ref: nil , p1: nil }
78
82
else
83
+ if state . p1 do
84
+ send ( state . p1 , { :forward , Jason . encode! ( % { type: "peer_left" } ) } )
85
+ end
86
+
79
87
% { state | p2_ref: nil , p2: nil }
80
88
end
81
89
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ defmodule SignallingServer.Router do
17
17
18
18
get "/websocket" do
19
19
conn
20
- |> WebSockAdapter . upgrade ( SignallingServer.PeerHandler , [ ] , timeout: 2_000 )
20
+ |> WebSockAdapter . upgrade ( SignallingServer.PeerHandler , [ ] , [ ] )
21
21
|> halt ( )
22
22
end
23
23
You can’t perform that action at this time.
0 commit comments