UNPKG

k-highway

Version:

Websocket and browserchannel transport for Racer

45 lines (40 loc) 1.26 kB
var path = require('path'); var through = require('through'); var extend = require('extend'); var defaultClientOptions = { base: '/ws', reconnect: true, browserChannelOnly: false, srvProtocol: undefined, srvHost: undefined, srvPort: undefined, srvSecurePort: undefined, timeout: 10000, timeoutIncrement: 10000 }; module.exports = function(clientOptions) { clientOptions = clientOptions || {}; clientOptions = extend({}, defaultClientOptions, clientOptions); var clientOptionsJson = JSON.stringify(clientOptions); // Add the client side script to the Browserify bundle. Set the clientOptions // needed to connect to the corresponding server by injecting them into the // file during bundling return function(bundle) { var browserFilename = path.join(__dirname, '../browser/index.js'); bundle.transform(function(filename) { if (filename !== browserFilename) return through(); var file = ''; return through( function write(data) { file += data; } , function end() { var rendered = file.replace('{{clientOptions}}', clientOptionsJson); this.queue(rendered); this.queue(null); } ); }); bundle.add(browserFilename); }; }