stompjs
Version:
STOMP for JavaScript apps (Web browser & node.js)
93 lines (70 loc) • 2.72 kB
text/coffeescript
WebSocketMock = require('./websocket.mock.js').WebSocketMock
Stomp = require('../../lib/stomp.js').Stomp
console = require 'console'
class StompServerMock extends WebSocketMock
# WebSocketMock handlers
handle_send: (msg) =>
handle_close: =>
handle_open: =>
# Stomp server implementation
stomp_init: ->
= {}
= {}
= []
stomp_send: (command, headers, body=null) ->
stomp_send_receipt: (frame) ->
if frame.headers.message?
else
stomp_send_message: (destination, subscription, message_id, body) ->
stomp_dispatch: (frame) ->
handler = "stomp_handle_#{frame.command.toLowerCase()}"
if this[handler]?
this[handler](frame)
if frame.receipt
else
console.log "StompServerMock: Unknown command: #{frame.command}"
stomp_handle_connect: (frame) ->
= Math.random()
stomp_handle_begin: (frame) ->
[frame.headers.transaction] = []
stomp_handle_commit: (frame) ->
transaction = [frame.headers.transaction]
for frame in transaction
.push(frame.body)
delete [frame.headers.transaction]
stomp_handle_abort: (frame) ->
delete [frame.headers.transaction]
stomp_handle_send: (frame) ->
if frame.headers.transaction
[frame.headers.transaction].push(frame)
else
.push(frame)
stomp_handle_subscribe: (frame) ->
sub_id = frame.headers.id or Math.random()
cb = (id, body) =>
[sub_id] = [frame.headers.destination, cb]
stomp_handle_unsubscribe: (frame) ->
if frame.headers.id in Object.keys( )
delete [frame.headers.id]
else
frame.headers.message = "Subscription does not exist"
stomp_handle_disconnect: (frame) ->
# Test helpers
test_send: (sub_id, message) ->
msgid = 'msg-' + Math.random()
[sub_id][1](msgid, message)
exports.StompServerMock = StompServerMock