Unverified Commit 23c8e8f7 authored by Dan Jones's avatar Dan Jones
Browse files

docs: add doc blocks for new adapter methods

parent c0424102
Pipeline #114567 failed with stages
in 32 seconds
......@@ -93,6 +93,10 @@ class Adapter {
});
}
/**
* Setup a timer to call poll every interval seconds
* @param {int} interval
*/
pollEveryXSeconds(interval) {
if (this.pollTimer) clearTimeout(this.pollTimer);
this.pollTimer = setTimeout(this.pollEveryXSeconds.bind(this, interval), interval*1000);
......@@ -138,6 +142,11 @@ class Adapter {
});
}
/**
* Process a message received either from poll
* or from socket.onMessage
* @param {object} message
*/
receive(message) {
try {
const parsed = JSON.parse(message.message);
......@@ -153,21 +162,30 @@ class Adapter {
}
}
/**
* Decide whether to use http or socket for comms
* with the backbone
* @returns string
*/
getMode() {
return ('mode' in this.config) ? this.config.mode : 'http';
}
/**
* Create a new socket connection and send an authentication
* message. Websocket doesn't support headers so as soon
* as the socket is open a message is sent containing
* the authorisation header to authenticate the connection
*/
openSocket() {
this.getAuthorizationHeader()
.then((headers) => {
const protocols = [];
const options = { headers };
const socket = new WebSocket(
this.config.socket,
protocols,
options,
);
socket.addEventListener('open', () => {
......@@ -193,6 +211,11 @@ class Adapter {
});
}
/**
* If the socket connection is lost ensure that a new socket
* is opened rather than continuing to send messages on this
* socket
*/
closeSocket() {
this.socket = null;
}
......@@ -203,7 +226,6 @@ class Adapter {
* Messages should be passed through encode before sending
* @param {string} topic
* @param {string} body
* @param {boolean} is_retry
* @returns
*/
publish(topic, body) {
......@@ -216,6 +238,13 @@ class Adapter {
return response;
}
/**
* Send via a POST to /send
* @param {string} topic
* @param {string} body
* @param {boolean} is_retry
* @returns Promise
*/
http_publish(topic, body, is_retry = false) {
let adapterConfig = this.config;
return this.getAuthorizationHeader()
......@@ -252,6 +281,11 @@ class Adapter {
});
}
/**
* Publish via websocket socket.send
* @param {string} topic
* @param {string} body
*/
socket_publish(topic, body) {
if (this.socket) {
this.socket.send(JSON.stringify({ topic, message: body }));
......@@ -271,7 +305,6 @@ class Adapter {
*
* Messages should be passed through encode before sending
* @param {string} body
* @param {boolean} is_retry
* @returns
*/
broadcast(body) {
......@@ -284,6 +317,12 @@ class Adapter {
return response;
}
/**
* Broadcast via POST to /notify
* @param {string} body
* @param {boolean} is_retry
* @returns Promise
*/
http_broadcast(body, is_retry = false) {
let adapterConfig = this.config;
return this.getAuthorizationHeader()
......@@ -319,6 +358,10 @@ class Adapter {
});
}
/**
* Broadcast via websocket socket.send
* @param {string} body
*/
socket_broadcast(body) {
if (this.socket) {
this.socket.send(JSON.stringify({ message: body }));
......
......@@ -95,6 +95,10 @@ class Adapter {
});
}
/**
* Setup a timer to call poll every interval seconds
* @param {int} interval
*/
pollEveryXSeconds(interval) {
if (this.pollTimer) clearTimeout(this.pollTimer);
this.pollTimer = setTimeout(this.pollEveryXSeconds.bind(this, interval), interval*1000);
......@@ -140,6 +144,11 @@ class Adapter {
});
}
/**
* Process a message received either from poll
* or from socket.onMessage
* @param {object} message
*/
receive(message) {
try {
const parsed = JSON.parse(message.message);
......@@ -155,21 +164,30 @@ class Adapter {
}
}
/**
* Decide whether to use http or socket for comms
* with the backbone
* @returns string
*/
getMode() {
return ('mode' in this.config) ? this.config.mode : 'http';
}
/**
* Create a new socket connection and send an authentication
* message. Websocket doesn't support headers so as soon
* as the socket is open a message is sent containing
* the authorisation header to authenticate the connection
*/
openSocket() {
this.getAuthorizationHeader()
.then((headers) => {
const protocols = [];
const options = { headers };
const socket = new WebSocket(
this.config.socket,
protocols,
options,
);
socket.addEventListener('open', () => {
......@@ -195,6 +213,11 @@ class Adapter {
});
}
/**
* If the socket connection is lost ensure that a new socket
* is opened rather than continuing to send messages on this
* socket
*/
closeSocket() {
this.socket = null;
}
......@@ -205,7 +228,6 @@ class Adapter {
* Messages should be passed through encode before sending
* @param {string} topic
* @param {string} body
* @param {boolean} is_retry
* @returns
*/
publish(topic, body) {
......@@ -218,7 +240,14 @@ class Adapter {
return response;
}
http_publish(topic, body, body, is_retry = false) {
/**
* Send via a POST to /send
* @param {string} topic
* @param {string} body
* @param {boolean} is_retry
* @returns Promise
*/
http_publish(topic, body, is_retry = false) {
let adapterConfig = this.config;
return this.getAuthorizationHeader()
.then((headers) => {
......@@ -254,6 +283,11 @@ class Adapter {
});
}
/**
* Publish via websocket socket.send
* @param {string} topic
* @param {string} body
*/
socket_publish(topic, body) {
if (this.socket) {
this.socket.send(JSON.stringify({ topic, message: body }));
......@@ -273,7 +307,6 @@ class Adapter {
*
* Messages should be passed through encode before sending
* @param {string} body
* @param {boolean} is_retry
* @returns
*/
broadcast(body) {
......@@ -286,6 +319,12 @@ class Adapter {
return response;
}
/**
* Broadcast via POST to /notify
* @param {string} body
* @param {boolean} is_retry
* @returns Promise
*/
http_broadcast(body, is_retry = false) {
let adapterConfig = this.config;
return this.getAuthorizationHeader()
......@@ -321,6 +360,10 @@ class Adapter {
});
}
/**
* Broadcast via websocket socket.send
* @param {string} body
*/
socket_broadcast(body) {
if (this.socket) {
this.socket.send(JSON.stringify({ message: body }));
......
......@@ -93,6 +93,10 @@ export class Adapter {
});
}
/**
* Setup a timer to call poll every interval seconds
* @param {int} interval
*/
pollEveryXSeconds(interval) {
if (this.pollTimer) clearTimeout(this.pollTimer);
this.pollTimer = setTimeout(this.pollEveryXSeconds.bind(this, interval), interval*1000);
......@@ -138,6 +142,11 @@ export class Adapter {
});
}
/**
* Process a message received either from poll
* or from socket.onMessage
* @param {object} message
*/
receive(message) {
try {
const parsed = JSON.parse(message.message);
......@@ -153,21 +162,30 @@ export class Adapter {
}
}
/**
* Decide whether to use http or socket for comms
* with the backbone
* @returns string
*/
getMode() {
return ('mode' in this.config) ? this.config.mode : 'http';
}
/**
* Create a new socket connection and send an authentication
* message. Websocket doesn't support headers so as soon
* as the socket is open a message is sent containing
* the authorisation header to authenticate the connection
*/
openSocket() {
this.getAuthorizationHeader()
.then((headers) => {
const protocols = [];
const options = { headers };
const socket = new WebSocket(
this.config.socket,
protocols,
options,
);
socket.addEventListener('open', () => {
......@@ -193,6 +211,11 @@ export class Adapter {
});
}
/**
* If the socket connection is lost ensure that a new socket
* is opened rather than continuing to send messages on this
* socket
*/
closeSocket() {
this.socket = null;
}
......@@ -203,7 +226,6 @@ export class Adapter {
* Messages should be passed through encode before sending
* @param {string} topic
* @param {string} body
* @param {boolean} is_retry
* @returns
*/
publish(topic, body) {
......@@ -216,6 +238,12 @@ export class Adapter {
return response;
}
/**
* Send via a POST to /send
* @param {string} topic
* @param {string} body
* @returns Promise
*/
http_publish(topic, body, is_retry = false) {
let adapterConfig = this.config;
return this.getAuthorizationHeader()
......@@ -252,6 +280,11 @@ export class Adapter {
});
}
/**
* Publish via websocket socket.send
* @param {string} topic
* @param {string} body
*/
socket_publish(topic, body) {
if (this.socket) {
this.socket.send(JSON.stringify({ topic, message: body }));
......@@ -271,7 +304,6 @@ export class Adapter {
*
* Messages should be passed through encode before sending
* @param {string} body
* @param {boolean} is_retry
* @returns
*/
broadcast(body) {
......@@ -284,6 +316,12 @@ export class Adapter {
return response;
}
/**
* Broadcast via POST to /notify
* @param {string} body
* @param {boolean} is_retry
* @returns Promise
*/
http_broadcast(body, is_retry = false) {
let adapterConfig = this.config;
return this.getAuthorizationHeader()
......@@ -319,6 +357,10 @@ export class Adapter {
});
}
/**
* Broadcast via websocket socket.send
* @param {string} body
*/
socket_broadcast(body) {
if (this.socket) {
this.socket.send(JSON.stringify({ message: body }));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment