Skip to content

Commit

Permalink
add message type
Browse files Browse the repository at this point in the history
  • Loading branch information
lvzixun authored and cloudwu committed Mar 30, 2020
1 parent 7efa799 commit fd27676
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples/simplewebsocket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions lualib/http/websocket.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit fd27676

Please sign in to comment.