1
0
Fork 0
mirror of https://github.com/sbrl/Nibriboard.git synced 2018-01-10 21:33:49 +00:00

Fiddle with RippleLink

This commit is contained in:
Starbeamrainbowlabs 2017-02-07 21:49:55 +00:00
parent 18eb1abb11
commit 679e667cf2
3 changed files with 25 additions and 5 deletions

View file

@ -28,6 +28,17 @@ const WebSocketStates = {
closed: 3 closed: 3
}; };
const ReverseWebSocketStates = {
// The WebSocket is in the process of connecting.
0: "connecting",
// The WebSocket is connected and ready to exchange data with the remote server.
1: "ready",
// The WebSocket is in the process of closing.
2: "closing",
// The WebSocket is closed.
3: "closed"
};
const EventEmitter$1 = require("event-emitter-es6"); const EventEmitter$1 = require("event-emitter-es6");
class RippleLink extends EventEmitter$1 class RippleLink extends EventEmitter$1
@ -78,7 +89,7 @@ class RippleLink extends EventEmitter$1
send(message) { send(message) {
if(this.websocket.readyState !== WebSocketStates.ready) if(this.websocket.readyState !== WebSocketStates.ready)
{ {
console.error(`Attempt to send data on the RippleLine when it is not ready (state ${this.websocket.readyState})`); console.error(`Attempt to send data on the RippleLink when it is not ready (state ${ReverseWebSocketStates[this.websocket.readyState]})`);
return false; return false;
} }

View file

@ -1,6 +1,6 @@
"use strict"; "use strict";
import WebSocketStates from './Utilities/WebsocketStates'; import { WebSocketStates, ReverseWebSocketStates } from './Utilities/WebSocketStates';
const EventEmitter = require("event-emitter-es6"); const EventEmitter = require("event-emitter-es6");
@ -52,7 +52,7 @@ class RippleLink extends EventEmitter
send(message) { send(message) {
if(this.websocket.readyState !== WebSocketStates.ready) if(this.websocket.readyState !== WebSocketStates.ready)
{ {
console.error(`Attempt to send data on the RippleLine when it is not ready (state ${this.websocket.readyState})`); console.error(`Attempt to send data on the RippleLink when it is not ready (state ${ReverseWebSocketStates[this.websocket.readyState]})`);
return false; return false;
} }

View file

@ -4,7 +4,7 @@
* Constants for the different readyStates that a WebSocket can be in. * Constants for the different readyStates that a WebSocket can be in.
* @type {Object} * @type {Object}
*/ */
const WebSocketStates = { export const WebSocketStates = {
/** /**
* Indicates that the WebSocket is connecting to the remote server. * Indicates that the WebSocket is connecting to the remote server.
* @type {Number} * @type {Number}
@ -27,4 +27,13 @@ const WebSocketStates = {
closed: 3 closed: 3
}; };
export default WebSocketStates; export const ReverseWebSocketStates = {
// The WebSocket is in the process of connecting.
0: "connecting",
// The WebSocket is connected and ready to exchange data with the remote server.
1: "ready",
// The WebSocket is in the process of closing.
2: "closing",
// The WebSocket is closed.
3: "closed"
}