UNPKG

raptor-client

Version:

A transport-agnostic RPC client that follows the JSON-RPC 2.0 spec. Works in the browser and on the server.

22 lines (17 loc) 474 B
var urlParse = require('url').parse var glueAjax = require('./lib/glue-ajax') var glueWebSocket = require('./lib/glue-websocket') function createClient (url) { var info = urlParse(url) switch (info.protocol) { case 'http:': case 'https:': return glueAjax(url) case 'ws:': case 'wss:': return glueWebSocket(url, window.WebSocket) default: throw new Error('Unknown protocol: ' + info.protocol) } } module.exports = createClient