v2.2.0 - new major version for mempool-js (#2)

* - Refactoring code.
- Refactoring folder structure.
- Adding apiEndpoint and websocketEndpoint to Mempool config.
- Adding brownserify feature.
- Adding MIT LICENSE

* - Changing package.json information.
- Reorganizing README.md information.
- Default export for CommonJs and ES6 Modules.
- Changing default variable to mempoolJS.
- Organizing the API and WS providers.
- Splitting websocket connection types: client and server.

* Change version to 2.2.0.
Reorder keywords in alphabetical order.
This commit is contained in:
Miguel Medeiros
2021-04-08 10:15:30 -03:00
committed by GitHub
parent 3bfae54069
commit f39361263a
40 changed files with 5581 additions and 1386 deletions

10
src/services/api.ts Normal file
View File

@@ -0,0 +1,10 @@
import axios, { AxiosInstance } from 'axios';
export const makeAPI = (apiEndpoint?: string): { api: AxiosInstance } => {
const api = axios.create({
baseURL: apiEndpoint,
});
return {
api,
};
};

25
src/services/wsClient.ts Normal file
View File

@@ -0,0 +1,25 @@
const browserWS = (
options: string[],
defaultWs: string,
websocketEndpoint?: string
): WebSocket => {
const ws = new WebSocket(websocketEndpoint || defaultWs);
ws.addEventListener('open', function open() {
handleMessage(ws, options);
});
return ws;
};
const handleMessage = (ws: WebSocket, options: string[]) => {
ws.send(JSON.stringify({ action: 'init' }));
setInterval(function timeout() {
ws.send(
JSON.stringify({
action: 'want',
data: options,
})
);
}, 500);
};
export default browserWS;

26
src/services/wsServer.ts Normal file
View File

@@ -0,0 +1,26 @@
import WebSocket from 'ws';
const serverWS = (
options: string[],
defaultWs: string,
websocketEndpoint?: string
): WebSocket => {
const ws = new WebSocket(websocketEndpoint || defaultWs);
ws.on('open', function open() {
handleMessage(ws, options);
});
return ws;
};
const handleMessage = (ws: WebSocket, options: string[]) => {
ws.send(JSON.stringify({ action: 'init' }));
setInterval(function timeout() {
ws.send(
JSON.stringify({
action: 'want',
data: options,
})
);
}, 500);
};
export default serverWS;