Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@geckos.io/common

Package Overview
Dependencies
Maintainers
1
Versions
52
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@geckos.io/common - npm Package Compare versions

Comparing version 1.7.1 to 2.0.0-dev.0

9

lib/helpers.d.ts

@@ -1,6 +0,7 @@

import { RawMessage, Data } from './types';
declare const isRawMessage: (data: Data | RawMessage) => boolean;
import { Data } from './types';
declare const isStringMessage: (data: any) => boolean;
declare const isBufferMessage: (data: any) => boolean;
declare const isObject: (data: Data) => boolean;
declare const isJSONString: (data: Data) => boolean;
export { isRawMessage, isObject, isJSONString };
declare const isJSONMessage: (data: Data) => boolean;
export { isStringMessage, isBufferMessage, isObject, isJSONMessage };
//# sourceMappingURL=helpers.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isJSONString = exports.isObject = exports.isRawMessage = void 0;
exports.isJSONMessage = exports.isObject = exports.isBufferMessage = exports.isStringMessage = void 0;
var types_1 = require("./types");
var isRawMessage = function (data) {
return typeof data === 'string' || data instanceof ArrayBuffer || data instanceof types_1.ArrayBufferView;
// const isRawMessage = (data: Data | RawMessage) => {
// return typeof data === 'string' || isBufferMessage(data)
// }
var isStringMessage = function (data) {
return typeof data === 'string';
};
exports.isRawMessage = isRawMessage;
exports.isStringMessage = isStringMessage;
var isBufferMessage = function (data) {
return data instanceof ArrayBuffer || data instanceof types_1.ArrayBufferView;
};
exports.isBufferMessage = isBufferMessage;
var isObject = function (data) {

@@ -13,3 +20,3 @@ return typeof data === 'object';

exports.isObject = isObject;
var isJSONString = function (data) {
var isJSONMessage = function (data) {
try {

@@ -30,3 +37,3 @@ // check if it is a string

};
exports.isJSONString = isJSONString;
exports.isJSONMessage = isJSONMessage;
//# sourceMappingURL=helpers.js.map

@@ -7,21 +7,39 @@ "use strict";

var data = ev.data;
var key;
var parsedData;
var JSONString = helpers_1.isJSONString(data);
if (!JSONString && helpers_1.isRawMessage(data)) {
key = constants_1.EVENTS.RAW_MESSAGE;
parsedData = data;
if (!data)
data = ev;
// console.log('data', data)
var isBuffer = helpers_1.isBufferMessage(data);
// console.log('isBuffer', isBuffer)
var isJson = helpers_1.isJSONMessage(data);
// console.log('isJson', isJson)
var isString = helpers_1.isStringMessage(data);
// console.log('isString', isString)
// if (!data && isRaw) return { key: EVENTS.RAW_MESSAGE, data }
// console.log('here?')
// // probably server-side
// if (!data) {
// if (isRawMessage(data)) {
// return { key: EVENTS.RAW_MESSAGE, data: data }
// } else {
// const json = JSON.parse(data as any)
// const key = Object.keys(json)[0]
// const value = Object.values(json)[0]
// return { key: key, data: value }
// }
// }
if (isJson) {
var object = JSON.parse(data);
var key = Object.keys(object)[0];
var value = object[key];
return { key: key, data: value };
}
else if (JSONString) {
data = JSON.parse(data);
key = Object.keys(data)[0];
parsedData = data[key];
if (isBuffer) {
return { key: constants_1.EVENTS.RAW_MESSAGE, data: data };
}
else {
key = 'error';
parsedData = new Error(constants_1.ERRORS.COULD_NOT_PARSE_MESSAGE);
if (isString) {
return { key: constants_1.EVENTS.RAW_MESSAGE, data: data };
}
return { key: key, data: parsedData };
return { key: 'error', data: new Error(constants_1.ERRORS.COULD_NOT_PARSE_MESSAGE) };
};
exports.default = ParseMessage;
//# sourceMappingURL=parseMessage.js.map
import { Data, RawMessage, EventName } from './types';
declare const SendMessage: (dataChannel: RTCDataChannel, maxMessageSize: number | undefined, eventName: EventName, data?: Data | RawMessage | null) => any;
declare const SendMessage: (dataChannel: any | RTCDataChannel, maxMessageSize: number | undefined, eventName: EventName, data?: Data | RawMessage | null) => any;
export default SendMessage;
//# sourceMappingURL=sendMessage.d.ts.map

@@ -7,4 +7,5 @@ "use strict";

var _a;
var _b;
if (data === void 0) { data = null; }
var send = function (data) {
var send = function (data, isBuffer) {
var _a;

@@ -17,13 +18,25 @@ var bytes = (_a = data.byteLength) !== null && _a !== void 0 ? _a : data.length * 2; // (times 2 for characters that uses 2 bytes per char)

Promise.resolve().then(function () {
dataChannel.send(data);
// server-side (send() does not exist on the server side)
// console.log('data', data)
if (dataChannel.send)
dataChannel.send(data);
else {
// console.log('buffer', isBuffer)
if (!isBuffer)
dataChannel.sendMessage(data);
else
dataChannel.sendMessageBinary(data);
}
});
}
};
if (dataChannel.readyState === 'open') {
if (!dataChannel)
return;
if (dataChannel.readyState === 'open' || ((_b = dataChannel.isOpen) === null || _b === void 0 ? void 0 : _b.call(dataChannel))) {
try {
if (eventName === constants_1.EVENTS.RAW_MESSAGE && data !== null && helpers_1.isRawMessage(data)) {
send(data);
if (eventName === constants_1.EVENTS.RAW_MESSAGE && data !== null && (helpers_1.isStringMessage(data) || helpers_1.isBufferMessage(data))) {
send(data, helpers_1.isBufferMessage(data));
}
else {
send(JSON.stringify((_a = {}, _a[eventName] = data, _a)));
send(JSON.stringify((_a = {}, _a[eventName] = data, _a)), false);
}

@@ -30,0 +43,0 @@ }

{
"name": "@geckos.io/common",
"version": "1.7.1",
"version": "2.0.0-dev.0",
"description": "The common module for @geckos.io/server and @geckos.io/client.",

@@ -5,0 +5,0 @@ "main": "lib",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc