diff --git a/README.md b/README.md index 92ab05a..46171b5 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,11 @@ Type: `String` If set, allows for overriding the `WebSocket` address, which corresponds to the server address by default. Values for this option should be in a valid `{host}:{port}` format. e.g. `localhost:433`. +#### `client.protocol` +Type: `String` + +If set, allows for overriding the `WebSocket` protocol scheme string, which corresponds to the server protocol scheme by default. Values for this option should be one of the following: `ws` or `wss`. + #### `client.retry` Type: `Boolean` diff --git a/lib/client/client.js b/lib/client/client.js index 3dde442..fee2f52 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -24,7 +24,7 @@ const run = (buildHash, options) => { const { error, info, warn } = require('./log')(); const protocol = secure ? 'wss' : 'ws'; - const socket = new ClientSocket(client, `${protocol}://${client.address || address}/wps`); + const socket = new ClientSocket(client, `${client.protocol || protocol}://${client.address || address}/wps`); const { compilerName } = options; diff --git a/lib/validate.js b/lib/validate.js index a6f2793..b38535a 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -35,6 +35,7 @@ module.exports = { allowMany: boolean(), client: partial({ address: string(), + protocol: union([literal('ws'), literal('wss')]), retry: boolean(), silent: boolean() }), diff --git a/test/validate.test.js b/test/validate.test.js index 372641f..c837d9e 100644 --- a/test/validate.test.js +++ b/test/validate.test.js @@ -10,8 +10,14 @@ test('defaults', (t) => { }); test('client', (t) => { - const result = validate({ client: { address: '0', retry: false, silent: false } }); + const result = validate({ client: { address: '0', protocol: "wss", retry: false, silent: false } }); t.falsy(result.error); + + const resultWs = validate({ client: { address: '0', protocol: "ws", retry: false, silent: false } }); + t.falsy(resultWs.error); + + const resultProtocolBad = validate({ client: { address: '0', protocol: "lala", retry: false, silent: false } }); + t.truthy(resultProtocolBad.error); }); test('error', (t) => {