@@ -41,7 +41,7 @@ const debugUpdate = require('debug')('ctrlxcore:datalayer:subscription:update');
4141 * This class works as a facade around the EventSource interface (https://www.w3.org/TR/eventsource/).
4242 *
4343 * @example <caption>Example how to subscribe and print the updates.</caption>
44- * let subscription = new CtrlxDatalayerSubscription('192.168.1.1', 'Bearer ABCD1234', ['framework/metrics/system/cpu-utilisation-percent']);
44+ * let subscription = new CtrlxDatalayerSubscription('192.168.1.1', 443, '', 'Bearer ABCD1234', ['framework/metrics/system/cpu-utilisation-percent']);
4545 *
4646 * subscription.open((err, sub) => {
4747 * if (err) throw err;
@@ -58,19 +58,21 @@ class CtrlxDatalayerSubscription extends EventEmitter {
5858 /**
5959 * Creates an instance of CtrlxDatalayerSubscription.
6060 *
61- * @param {string } hostname - The hostname of the device. Can also be a ipv4-, ipv6-address or 'localhost'.
61+ * @param {string } hostname - The hostname of the device. Can also be an ipv4-, ipv6-address or 'localhost'.
62+ * @param {number } port - The port number of the device, where the web server is listening. Usually 443.
6263 * @param {string } servername - The TLS servername of the device as defined by RFC 6066. Empty string in case of an ip-address.
6364 * @param {string } authorization - The authorization token string for the http header.
6465 * @param {string[] } paths - An array of node addresses to subscribe to.
6566 * @param {number|undefined } publishIntervalMs - The interval in milliseconds that is requested as update interval from the server.
6667 * If omitted, then the server will chose a default value (usually 1s).
6768 * @memberof CtrlxCore
6869 */
69- constructor ( hostname , servername , authorization , paths , publishIntervalMs = undefined ) {
70+ constructor ( hostname , port = 443 , servername = '' , authorization , paths , publishIntervalMs = undefined ) {
7071 debug ( `constructor(${ hostname } , ...)` ) ;
7172 super ( ) ;
7273
7374 this . _hostname = hostname ;
75+ this . _port = port ;
7476 this . _servername = servername ;
7577 this . _authorization = authorization ;
7678 this . _nodes = paths ;
@@ -109,7 +111,7 @@ class CtrlxDatalayerSubscription extends EventEmitter {
109111 }
110112
111113 // Arguments are given as query parameter.
112- let url = `https://${ this . _hostname } :443 /automation/api/v2/events?nodes=${ this . _nodes } ` ;
114+ let url = `https://${ this . _hostname } :${ this . _port } /automation/api/v2/events?nodes=${ this . _nodes } ` ;
113115 if ( typeof this . _publishIntervalMs !== 'undefined' ) {
114116 url += `&publishIntervalMs=${ this . _publishIntervalMs } ` ;
115117 }
@@ -197,7 +199,7 @@ class CtrlxDatalayerSubscription extends EventEmitter {
197199 this . _es . onerror = ( e ) => {
198200 debug ( `onerror(${ e . type } )` ) ;
199201
200- if ( e . data !== 'undefined' ) {
202+ if ( typeof e . data !== 'undefined' ) {
201203
202204 // The error is of type 'MessageEvent'. This means, that not the stream has an error, but
203205 // an 'error' message is send over the stream (in contrast to an 'update' message if everything is fine).
0 commit comments