From fd27676869dbc4ae15d08ea93542d39353d67064 Mon Sep 17 00:00:00 2001 From: zixun Date: Mon, 30 Mar 2020 17:26:06 +0800 Subject: [PATCH] add message type --- examples/simplewebsocket.lua | 3 ++- lualib/http/websocket.lua | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/simplewebsocket.lua b/examples/simplewebsocket.lua index 99848209..dde6fda5 100755 --- a/examples/simplewebsocket.lua +++ b/examples/simplewebsocket.lua @@ -21,7 +21,8 @@ if MODE == "agent" then print("--------------") end - function handle.message(id, msg) + function handle.message(id, msg, msg_type) + assert(msg_type == "binary" or msg_type == "text") websocket.write(id, msg) end diff --git a/lualib/http/websocket.lua b/lualib/http/websocket.lua index c9b8ecd9..a2220a49 100755 --- a/lualib/http/websocket.lua +++ b/lualib/http/websocket.lua @@ -273,7 +273,7 @@ local function resolve_accept(self) try_handle(self, "pong") else if fin and #recv_buf == 0 then - try_handle(self, "message", payload_data) + try_handle(self, "message", payload_data, op) else recv_buf[#recv_buf+1] = payload_data recv_count = recv_count + #payload_data @@ -282,7 +282,7 @@ local function resolve_accept(self) end if fin then local s = table.concat(recv_buf) - try_handle(self, "message", s) + try_handle(self, "message", s, op) recv_buf = {} -- clear recv_buf recv_count = 0 end