Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Tremho sbg parser fixes #97

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 27 additions & 21 deletions src/websockets-base.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const _WebSocket = org.java_websocket.client.WebSocketClient.extend( {
if (this.debug) {
console.log("WebSocket Event: OnOpen");
}
const wrapper = this.wrapper?.get?.();
const wrapper = this.wrapper && this.wrapper.get && this.wrapper.get()
if (wrapper) {
wrapper._notify("open", [wrapper]);
}
Expand All @@ -47,7 +47,7 @@ const _WebSocket = org.java_websocket.client.WebSocketClient.extend( {
if (this.debug) {
console.log("WebSocket Event: OnClose", code, reason);
}
const wrapper = this.wrapper?.get?.();
const wrapper = this.wrapper && this.wrapper.get && this.wrapper.get()
if (wrapper) {
// org.java_websocket.WebSocketImpl.closeConnection() currently executes this callback prior to updating readystate to CLOSED
// and as such there are cases when the readystate is still showing as OPEN when this called. In short, the websocket connection
Expand Down Expand Up @@ -76,7 +76,7 @@ const _WebSocket = org.java_websocket.client.WebSocketClient.extend( {
return;
}

const wrapper = this.wrapper?.get?.();
const wrapper = this.wrapper && this.wrapper.get && this.wrapper.get()
// Should be a JavaScript String or ArrayBuffer
if (wrapper) {
wrapper._notify("message", [wrapper, message]);
Expand All @@ -88,7 +88,7 @@ const _WebSocket = org.java_websocket.client.WebSocketClient.extend( {
console.log("WebSocket Event: OnMessageBinary");
}

const wrapper = this.wrapper?.get?.();
const wrapper = this.wrapper && this.wrapper.get && this.wrapper.get()
if (wrapper && binaryMessage) {

// Is a Native JAVA Buffer type
Expand Down Expand Up @@ -126,7 +126,7 @@ const _WebSocket = org.java_websocket.client.WebSocketClient.extend( {
console.log("WebSocket Event: onError", err);
}

const wrapper = this.wrapper?.get?.();
const wrapper = this.wrapper && this.wrapper.get && this.wrapper.get()
if (wrapper) {
wrapper._notify("error", [wrapper, err]);
}
Expand All @@ -138,7 +138,7 @@ const _WebSocket = org.java_websocket.client.WebSocketClient.extend( {
console.log("WebSocket Event: onFragment", optCode);
}

const wrapper = this.wrapper?.get?.();
const wrapper = this.wrapper && this.wrapper.get && this.wrapper.get()
if (!wrapper) {
return;
}
Expand Down Expand Up @@ -195,7 +195,7 @@ const _WebSocket = org.java_websocket.client.WebSocketClient.extend( {
if (this.debug) {
console.log("WebSocket Event: Handshake Received", handshake);
}
const wrapper = this.wrapper?.get?.();
const wrapper = this.wrapper && this.wrapper.get && this.wrapper.get()
if (wrapper) {
wrapper._notify("handshake", [wrapper, handshake]);
}
Expand Down Expand Up @@ -677,21 +677,27 @@ class NativeWebSockets {
return true;
}

/**
* This is a list standardized Close Codes
*/
static CLOSE_CODE = {NORMAL: 1000, GOING_AWAY: 1001, PROTOCOL_ERROR: 1002, REFUSE: 1003, NOCODE: 1005, ABNORMAL_CLOSE:1006, NO_UTF8: 1007, POLICY_VALIDATION: 1008, TOOBIG: 1009, EXTENSION: 1010, UNEXPECTED_CONDITION: 1011, SERVICE_RESTART: 1012, TRY_AGAIN_LATER: 1013, BAD_GATEWAY: 1014, TLS_ERROR: 1015, NEVER_CONNECTED: -1, BUGGYCLOSE: -2, FLASHPOLICY: -3};

/**
* Standard Connection values
* @type {number}
*/
static NOT_YET_CONNECTED = -1;
static CONNECTING = 0;
static OPEN = 1;
static CLOSING = 2;
static CLOSED = 3;
// /**
// * This is a list standardized Close Codes
// */
// static CLOSE_CODE = {NORMAL: 1000, GOING_AWAY: 1001, PROTOCOL_ERROR: 1002, REFUSE: 1003, NOCODE: 1005, ABNORMAL_CLOSE:1006, NO_UTF8: 1007, POLICY_VALIDATION: 1008, TOOBIG: 1009, EXTENSION: 1010, UNEXPECTED_CONDITION: 1011, SERVICE_RESTART: 1012, TRY_AGAIN_LATER: 1013, BAD_GATEWAY: 1014, TLS_ERROR: 1015, NEVER_CONNECTED: -1, BUGGYCLOSE: -2, FLASHPOLICY: -3};
//
// /**
// * Standard Connection values
// * @type {number}
// */
// static NOT_YET_CONNECTED = -1;
// static CONNECTING = 0;
// static OPEN = 1;
// static CLOSING = 2;
// static CLOSED = 3;
}
NativeWebSockets.CLOSE_CODE = {NORMAL: 1000, GOING_AWAY: 1001, PROTOCOL_ERROR: 1002, REFUSE: 1003, NOCODE: 1005, ABNORMAL_CLOSE:1006, NO_UTF8: 1007, POLICY_VALIDATION: 1008, TOOBIG: 1009, EXTENSION: 1010, UNEXPECTED_CONDITION: 1011, SERVICE_RESTART: 1012, TRY_AGAIN_LATER: 1013, BAD_GATEWAY: 1014, TLS_ERROR: 1015, NEVER_CONNECTED: -1, BUGGYCLOSE: -2, FLASHPOLICY: -3};
NativeWebSockets.NOT_YET_CONNECTED = -1;
NativeWebSockets.CONNECTING = 0;
NativeWebSockets.OPEN = 1;
NativeWebSockets.CLOSING = 2;
NativeWebSockets.CLOSED = 3;

module.exports = NativeWebSockets;

Expand Down
2 changes: 1 addition & 1 deletion src/websockets-base.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class NativeWebSockets {
}

if (this._timeout !== -1) {
urlRequest.timeoutInterval = this._timeout;
urlRequest.timeoutInterval = this._timeout / 1000; // Convert to seconds for NSURLRequest. This honors the API spec for timeout cross-platform.
}

this._webSocketDelegate = WebSocketDelegate.alloc().init();
Expand Down