]> granicus.if.org Git - ejabberd/commitdiff
Use binary framing in MQTT WebSockets
authorEvgeny Khramtsov <ekhramtsov@process-one.net>
Thu, 25 Apr 2019 11:30:42 +0000 (14:30 +0300)
committerEvgeny Khramtsov <ekhramtsov@process-one.net>
Thu, 25 Apr 2019 11:30:42 +0000 (14:30 +0300)
src/ejabberd_http_ws.erl
src/ejabberd_websocket.erl
src/mod_mqtt_ws.erl

index dbde28caa97234716332b8103bd39de5e088f6cd..26e68fdaa63e7cec7a59fe29288405bbadbf92ff 100644 (file)
@@ -201,15 +201,15 @@ handle_sync_event({send_xml, Packet}, _From, StateName,
     case Packet2 of
         {xmlstreamstart, Name, Attrs3} ->
             B = fxml:element_to_binary(#xmlel{name = Name, attrs = Attrs3}),
-            WsPid ! {send, <<(binary:part(B, 0, byte_size(B)-2))/binary, ">">>};
+            WsPid ! {text, <<(binary:part(B, 0, byte_size(B)-2))/binary, ">">>};
         {xmlstreamend, Name} ->
-            WsPid ! {send, <<"</", Name/binary, ">">>};
+            WsPid ! {text, <<"</", Name/binary, ">">>};
         {xmlstreamelement, El} ->
-            WsPid ! {send, fxml:element_to_binary(El)};
+            WsPid ! {text, fxml:element_to_binary(El)};
         {xmlstreamraw, Bin} ->
-            WsPid ! {send, Bin};
+            WsPid ! {text, Bin};
         {xmlstreamcdata, Bin2} ->
-            WsPid ! {send, Bin2};
+            WsPid ! {text, Bin2};
         skip ->
             ok
     end,
@@ -224,7 +224,7 @@ handle_sync_event(close, _From, StateName, #state{ws = {_, WsPid}, rfc_compilant
   when StateName /= stream_end_sent ->
     Close = #xmlel{name = <<"close">>,
                    attrs = [{<<"xmlns">>, <<"urn:ietf:params:xml:ns:xmpp-framing">>}]},
-    WsPid ! {send, fxml:element_to_binary(Close)},
+    WsPid ! {text, fxml:element_to_binary(Close)},
     {stop, normal, StateData};
 handle_sync_event(close, _From, _StateName, StateData) ->
     {stop, normal, StateData}.
index edc602f55ebaa9b275f1454557be9b6d715d5a4e..2b5a01460a6f52f6950b6866d1962f26c8816268 100644 (file)
@@ -202,10 +202,14 @@ ws_loop(FrameInfo, Socket, WsHandleLoopPid, SocketMode) ->
                    end,
             erlang:demonitor(Ref),
             websocket_close(Socket, WsHandleLoopPid, SocketMode, Code);
-        {send, Data} ->
+        {text, Data} ->
             SocketMode:send(Socket, encode_frame(Data, 1)),
             ws_loop(FrameInfo, Socket, WsHandleLoopPid,
                     SocketMode);
+       {data, Data} ->
+           SocketMode:send(Socket, encode_frame(Data, 2)),
+            ws_loop(FrameInfo, Socket, WsHandleLoopPid,
+                    SocketMode);
         {ping, Data} ->
             SocketMode:send(Socket, encode_frame(Data, 9)),
             ws_loop(FrameInfo, Socket, WsHandleLoopPid,
index 8725534451a42dfeaf7749e6df87cbe48a0c09e4..820b09d62c8f94ca7bf9519670b4e218daf7ab46 100644 (file)
@@ -98,7 +98,7 @@ init([{#ws{ip = IP, http_opts = ListenOpts}, WsPid}]) ->
     end.
 
 handle_call({send, Data}, _From, #state{ws_pid = WsPid} = State) ->
-    WsPid ! {send, Data},
+    WsPid ! {data, Data},
     {reply, ok, State};
 handle_call(Request, From, State) ->
     ?WARNING_MSG("Got unexpected call from ~p: ~p", [From, Request]),