Created
April 27, 2013 21:22
-
-
Save nickman/5474781 to your computer and use it in GitHub Desktop.
Signature & Options for Generalized WebSocket Service Invoker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Generalized websocket service invoker | |
* @param command A (mandatory) JSON subscription request | |
* @param options:<ul> | |
* <li><b>timeout</b>: The timeout in ms. on the request invocation confirm. (i.e. not a subscriber timeout) Default is 2000 ms.</li> | |
* <li><b>onresponse</b>: A callback invoked when the immediate response of the command invocation is received.</li> | |
* <li><b>ontimeout</b>: A callback invoked when the request times out</li> | |
* <li><b>onevent</b>: A callback invoked when an asynchronous event is received associated to the original invocation.</li> | |
* <li><b>oncancel</b>: A callback invoked the asynchronous event subscription associated to the original invocation is cancelled</li> | |
* </ul> | |
* @return the unique request identifier which is also the handle to the subscription. | |
*/ | |
function wsinvoke(command, options) { | |
if(command==null || !$.isPlainObject(command)) throw "The command must be a valid object"; | |
if(command.svc==null || $.trim(command.svc)=="") throw "The command must specicy a valid service name"; | |
if(command.op==null || $.trim(command.op)=="") throw "The command must specicy a valid service operation name"; | |
if(command.t==null || $.trim(command.op)=="") command.op = "req"; | |
command.rid = _RID_FACTORY_++; | |
$.websocket.send(command); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment