diff --git a/package-lock.json b/package-lock.json index 992e164e..7a006bab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "sockjs", - "version": "0.3.21", + "name": "sockjs-adv", + "version": "0.3.24", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/trans-websocket.coffee b/src/trans-websocket.coffee index 57716faf..bccca80f 100644 --- a/src/trans-websocket.coffee +++ b/src/trans-websocket.coffee @@ -68,7 +68,9 @@ class WebSocketReceiver extends transport.GenericReceiver try message = JSON.parse(payload) catch x - return @didClose(3000, 'Broken framing.') + # return raw message when not json string + message = payload + # return @didClose(3000, 'Broken framing.') if payload[0] is '[' for msg in message @session.didMessage(msg) diff --git a/src/transport.coffee b/src/transport.coffee index 3d370ca8..8f2b8530 100644 --- a/src/transport.coffee +++ b/src/transport.coffee @@ -28,8 +28,12 @@ class SockJSConnection extends stream.Stream toString: -> return '' - write: (string) -> - return @_session.send('' + string) + write: (data) -> + # binary buffer + if(data instanceof Buffer) + return @_session.send(data) + else + return @_session.send('' + data) end: (string) -> if string @@ -198,7 +202,10 @@ class Session send: (payload) -> if @readyState isnt Transport.OPEN return false - @send_buffer.push('' + payload) + if payload instanceof Buffer + @send_buffer.push(payload) + else + @send_buffer.push('' + payload) if @recv @tryFlush() return true @@ -265,9 +272,17 @@ class GenericReceiver @session.unregister() doSendBulk: (messages) -> - q_msgs = for m in messages - utils.quote(m) - @doSendFrame('a' + '[' + q_msgs.join(',') + ']') + q_msgs = [] + for m in messages + if !(m instanceof Buffer) + q_msgs.push(utils.quote(m)) + else + if q_msgs.length > 0 + @doSendFrame('a' + '[' + q_msgs.join(',') + ']') + q_msgs = [] + @doSendFrame(m) + if q_msgs.length > 0 + @doSendFrame('a' + '[' + q_msgs.join(',') + ']') heartbeat: -> @doSendFrame('h')