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:
10
src/services/api.ts
Normal file
10
src/services/api.ts
Normal 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
25
src/services/wsClient.ts
Normal 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
26
src/services/wsServer.ts
Normal 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;
|
||||
Reference in New Issue
Block a user