Skip to content

Commit

Permalink
Merge pull request #261 from esl/fix-ws-close
Browse files Browse the repository at this point in the history
Handle ws 'close' element properly
  • Loading branch information
NelsonVides authored Dec 22, 2023
2 parents db7671d + b3d9b0f commit afe1ef9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/escalus_ws.erl
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,15 @@ handle_data(Data, State = #state{parser = Parser,
NewState,
Stanzas,
fun forward_to_owner/3, Timestamp),
case lists:filter(fun is_stream_end/1, Stanzas) of
case lists:filter(fun(Stanza) -> is_stream_end(Stanza, State) end, Stanzas) of
[] -> {noreply, NewState};
_ -> {stop, normal, NewState}
end.

-spec is_stream_end(exml_stream:element()) -> boolean().
is_stream_end(#xmlstreamend{}) -> true;
is_stream_end(_) -> false.
-spec is_stream_end(exml_stream:element(), state()) -> boolean().
is_stream_end(#xmlstreamend{}, #state{legacy_ws = true}) -> true;
is_stream_end(#xmlel{name = <<"close">>}, #state{legacy_ws = false}) -> true;
is_stream_end(_, _) -> false.

forward_to_owner(Stanzas, #state{owner = Owner,
event_client = EventClient}, Timestamp) ->
Expand Down

0 comments on commit afe1ef9

Please sign in to comment.