cscheid / rserve-js

Javascript implementation of the Rserve protocol
MIT License
47 stars 32 forks source link

allow named oob messages in ocap mode #25

Open gordonwoodhull opened 9 years ago

gordonwoodhull commented 9 years ago

Rserve now supports direct input through the oob message "console.in". However, rserve.js disables named oob messages when in ocap_mode.

This PR is an attempt to fix that. I still want to test it further, but I thought I would open the PR now to make sure I am not breaking the design of rserve.js somehow.

+@s-u

Details below from commit message:

instead of switching on opts.ocap_mode, switch on the type of the wrapped payload's first element:

  1. if it's a string, check if on_oob_message supplied. if so, call it with the usual function(error, result) callback.

NOTE: the signature was the opposite before, function(message, error), so this is a breaking change! but (error, result) is the standard asynchronous javascript signature, so i think this is correct.

  1. if it's a function, make sure we are in ocap mode. if so, call the function exactly as before.
  2. if it's anything else, report "Unknown oob message type".