1
0
Fork 0

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
};
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");
class RippleLink extends EventEmitter$1
@ -78,7 +89,7 @@ class RippleLink extends EventEmitter$1
send(message) {
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;
}

View File

@ -1,6 +1,6 @@
"use strict";
import WebSocketStates from './Utilities/WebsocketStates';
import { WebSocketStates, ReverseWebSocketStates } from './Utilities/WebSocketStates';
const EventEmitter = require("event-emitter-es6");
@ -52,7 +52,7 @@ class RippleLink extends EventEmitter
send(message) {
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;
}

View File

@ -4,7 +4,7 @@
* Constants for the different readyStates that a WebSocket can be in.
* @type {Object}
*/
const WebSocketStates = {
export const WebSocketStates = {
/**
* Indicates that the WebSocket is connecting to the remote server.
* @type {Number}
@ -27,4 +27,13 @@ const WebSocketStates = {
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"
}