Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Communications Backbone System
backbone-adapter-javascript
Commits
23c8e8f7
Unverified
Commit
23c8e8f7
authored
2 years ago
by
Dan Jones
Browse files
Options
Download
Email Patches
Plain Diff
docs: add doc blocks for new adapter methods
parent
c0424102
Pipeline
#114567
failed with stages
in 32 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
144 additions
and
16 deletions
+144
-16
dist/adapter.esm.js
dist/adapter.esm.js
+48
-5
dist/adapter.js
dist/adapter.js
+49
-6
src/adapter/index.js
src/adapter/index.js
+47
-5
No files found.
dist/adapter.esm.js
View file @
23c8e8f7
...
...
@@ -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
}));
...
...
This diff is collapsed.
Click to expand it.
dist/adapter.js
View file @
23c8e8f7
...
...
@@ -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
}));
...
...
This diff is collapsed.
Click to expand it.
src/adapter/index.js
View file @
23c8e8f7
...
...
@@ -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
}));
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment