|Description||RPC via WebSockets|
|Node Version||>= 0.6|
Vein uses ES5 features so be sure to include es5shim on your page.
var Vein = require'vein';var server = httpcreateServerlisten8080;var vein = VeincreateServerserver;veinadd'multiply'resreplynumOne * numTwo;;
Note: Express 3 is no longer a httpServer so you need to do something like:
var server = require'http'createServerapplisten8080;
before passing it to Vein.createServer
var vein = VeincreateClient;veinreadyveinmultiply2 5// num === 10;;
-- Options --resource - change to allow multiple servers on one port (default: "default")
var Vein = require'vein';var vein = VeincreateServerhttpServer options;
Arguments passed to res.reply() will be applied to the callback on the client
veinadd'getNumber'resreply"Hey there " + name + " I got your number " + num;;
You can use middleware to add layers in front of your services. Any arguments passed into next will be thrown as an error on the client and end the middleware chain.
veinuseif reqservice == 'login'next;elseif rescookie'login' == 'success!'next;elseresdisconnect;;
Vein supports calling the res object as a function. This makes it easier to integrate vanilla-JS services into vein. The only difference is that you still have to put the callback first (this is to prevent headaches with variable arguments from the client).
-- Options --host - server location (default: window.location.hostname)port - server port (default: window.location.port)secure - use SSL (default: window.location.protocol)resource - change to allow multiple servers on one port (default: "default")
var vein = VeincreateClientoptions;
When the connection has been established your callback will be called with an array of services available.
veinon'ready'//Start doing stuff!;
When calling a service the format is vein.serviceName(args..., callback)
If the connection has been closed this will be called.
veinon'close'console.log"Connection lost due to" reason;;
You can view a tiny addition sample and more in the example folder.
Copyright (c) 2012 Fractal firstname.lastname@example.org
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.