diff --git a/lib/rocketChat.js b/lib/rocketChat.js index 666bfa9..5031097 100644 --- a/lib/rocketChat.js +++ b/lib/rocketChat.js @@ -2,7 +2,8 @@ var net = require("./net"); function RocketChatClient(protocol, host, port, username, password, onConnected) { let basepath = ""; - + let useragent = ""; + if (arguments.length === 1) { host = arguments[0].host || "localhost"; port = arguments[0].port || 3000; @@ -10,12 +11,17 @@ function RocketChatClient(protocol, host, port, username, password, onConnected) password = arguments[0].password || ""; onConnected = arguments[0].onConnected; basepath = (arguments[0].basepath || "").replace(/^\/+|\/+$/g, ""); + useragent = arguments[0].useragent || ""; protocol = arguments[0].protocol || "http"; } - + onConnected = onConnected || function() {}; var restClient = new net.RestClient(protocol, host, port, basepath + "/api/v1/"); - var wsClient = new net.WsClient("ws", host, port, basepath + "/websocket"); + var wsClient = new net.WsClient((protocol === "http") ? "ws" : "wss", host, port, basepath + "/websocket"); + + if (useragent) { + restClient.setHeader("User-Agent", useragent); + } this.authentication = new (require("./api/authentication"))(restClient);