@geckos.io/common
Advanced tools
Comparing version 2.0.0-dev.4 to 2.0.0
@@ -1,2 +0,2 @@ | ||
import { ChannelId, Data, EventName, EventOptions, RoomId } from './types'; | ||
import { ChannelId, Data, EventName, EventOptions, RoomId } from './types.js'; | ||
import { Events } from '@yandeu/events'; | ||
@@ -3,0 +3,0 @@ interface BridgeEventMap { |
@@ -1,26 +0,20 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Bridge = void 0; | ||
var events_1 = require("@yandeu/events"); | ||
var Bridge = /** @class */ (function () { | ||
function Bridge() { | ||
this.eventEmitter = new events_1.Events(); | ||
import { Events } from '@yandeu/events'; | ||
export class Bridge { | ||
constructor() { | ||
this.eventEmitter = new Events(); | ||
} | ||
Bridge.prototype.emit = function (eventName, data, connection) { | ||
if (connection === void 0) { connection = {}; } | ||
emit(eventName, data, connection = {}) { | ||
this.eventEmitter.emit(eventName, data, connection); | ||
}; | ||
Bridge.prototype.on = function (eventName, cb) { | ||
return this.eventEmitter.on(eventName, function (data, options) { | ||
} | ||
on(eventName, cb) { | ||
return this.eventEmitter.on(eventName, (data, options) => { | ||
cb(data, options); | ||
}); | ||
}; | ||
Bridge.prototype.removeAllListeners = function () { | ||
} | ||
removeAllListeners() { | ||
this.eventEmitter.removeAllListeners(); | ||
}; | ||
return Bridge; | ||
}()); | ||
exports.Bridge = Bridge; | ||
var bridge = new Bridge(); | ||
exports.default = bridge; | ||
} | ||
} | ||
const bridge = new Bridge(); | ||
export default bridge; | ||
//# sourceMappingURL=bridge.js.map |
@@ -1,5 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ERRORS = exports.EVENTS = void 0; | ||
var EVENTS = { | ||
const EVENTS = { | ||
CONNECT: 'connect', | ||
@@ -16,4 +13,3 @@ CONNECTION: 'connection', | ||
}; | ||
exports.EVENTS = EVENTS; | ||
var ERRORS = { | ||
const ERRORS = { | ||
BROWSER_NOT_SUPPORTED: 'BROWSER_NOT_SUPPORTED', | ||
@@ -24,3 +20,3 @@ COULD_NOT_PARSE_MESSAGE: 'COULD_NOT_PARSE_MESSAGE', | ||
}; | ||
exports.ERRORS = ERRORS; | ||
export { EVENTS, ERRORS }; | ||
//# sourceMappingURL=constants.js.map |
@@ -1,2 +0,2 @@ | ||
import { Data } from './types'; | ||
import { Data } from './types.js'; | ||
declare const isStringMessage: (data: any) => boolean; | ||
@@ -3,0 +3,0 @@ declare const isBufferMessage: (data: any) => boolean; |
@@ -1,21 +0,15 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isJSONMessage = exports.isObject = exports.isBufferMessage = exports.isStringMessage = void 0; | ||
var types_1 = require("./types"); | ||
import { ArrayBufferView } from './types.js'; | ||
// const isRawMessage = (data: Data | RawMessage) => { | ||
// return typeof data === 'string' || isBufferMessage(data) | ||
// } | ||
var isStringMessage = function (data) { | ||
const isStringMessage = (data) => { | ||
return typeof data === 'string'; | ||
}; | ||
exports.isStringMessage = isStringMessage; | ||
var isBufferMessage = function (data) { | ||
return data instanceof ArrayBuffer || data instanceof types_1.ArrayBufferView; | ||
const isBufferMessage = (data) => { | ||
return data instanceof ArrayBuffer || data instanceof ArrayBufferView; | ||
}; | ||
exports.isBufferMessage = isBufferMessage; | ||
var isObject = function (data) { | ||
const isObject = (data) => { | ||
return typeof data === 'object'; | ||
}; | ||
exports.isObject = isObject; | ||
var isJSONMessage = function (data) { | ||
const isJSONMessage = (data) => { | ||
try { | ||
@@ -36,3 +30,3 @@ // check if it is a string | ||
}; | ||
exports.isJSONMessage = isJSONMessage; | ||
export { isStringMessage, isBufferMessage, isObject, isJSONMessage }; | ||
//# sourceMappingURL=helpers.js.map |
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
@@ -7,3 +5,3 @@ * IceServers for development only. | ||
// eslint-disable-next-line no-undef | ||
var defaultIceServers = [ | ||
const defaultIceServers = [ | ||
{ urls: 'stun:stun1.l.google.com:19302' }, | ||
@@ -14,3 +12,3 @@ { urls: 'stun:stun2.l.google.com:19302' }, | ||
]; | ||
exports.default = defaultIceServers; | ||
export default defaultIceServers; | ||
//# sourceMappingURL=iceServers.js.map |
@@ -1,8 +0,5 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var makeRandomId = function (length) { | ||
if (length === void 0) { length = 24; } | ||
var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
var id = ''; | ||
for (var i = 0; i < length; i++) { | ||
const makeRandomId = (length = 24) => { | ||
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
let id = ''; | ||
for (let i = 0; i < length; i++) { | ||
id += possible.charAt(Math.floor(Math.random() * possible.length)); | ||
@@ -12,3 +9,3 @@ } | ||
}; | ||
exports.default = makeRandomId; | ||
export default makeRandomId; | ||
//# sourceMappingURL=makeRandomId.js.map |
@@ -1,12 +0,10 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var constants_1 = require("./constants"); | ||
var helpers_1 = require("./helpers"); | ||
var ParseMessage = function (ev) { | ||
var data = ev.data; | ||
import { ERRORS, EVENTS } from './constants.js'; | ||
import { isBufferMessage, isJSONMessage, isStringMessage } from './helpers.js'; | ||
const ParseMessage = (ev) => { | ||
let { data } = ev; | ||
if (!data) | ||
data = ev; | ||
var isBuffer = helpers_1.isBufferMessage(data); | ||
var isJson = helpers_1.isJSONMessage(data); | ||
var isString = helpers_1.isStringMessage(data); | ||
const isBuffer = isBufferMessage(data); | ||
const isJson = isJSONMessage(data); | ||
const isString = isStringMessage(data); | ||
// if (!data && isRaw) return { key: EVENTS.RAW_MESSAGE, data } | ||
@@ -25,16 +23,16 @@ // // probably server-side | ||
if (isJson) { | ||
var object = JSON.parse(data); | ||
var key = Object.keys(object)[0]; | ||
var value = object[key]; | ||
const object = JSON.parse(data); | ||
const key = Object.keys(object)[0]; | ||
const value = object[key]; | ||
return { key: key, data: value }; | ||
} | ||
if (isBuffer) { | ||
return { key: constants_1.EVENTS.RAW_MESSAGE, data: data }; | ||
return { key: EVENTS.RAW_MESSAGE, data: data }; | ||
} | ||
if (isString) { | ||
return { key: constants_1.EVENTS.RAW_MESSAGE, data: data }; | ||
return { key: EVENTS.RAW_MESSAGE, data: data }; | ||
} | ||
return { key: 'error', data: new Error(constants_1.ERRORS.COULD_NOT_PARSE_MESSAGE) }; | ||
return { key: 'error', data: new Error(ERRORS.COULD_NOT_PARSE_MESSAGE) }; | ||
}; | ||
exports.default = ParseMessage; | ||
export default ParseMessage; | ||
//# sourceMappingURL=parseMessage.js.map |
@@ -1,17 +0,11 @@ | ||
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.makeReliable = void 0; | ||
var makeRandomId_1 = __importDefault(require("./makeRandomId")); | ||
var runInterval_1 = __importDefault(require("./runInterval")); | ||
var makeReliable = function (options, cb) { | ||
var _a = options.interval, interval = _a === void 0 ? 150 : _a, _b = options.runs, runs = _b === void 0 ? 10 : _b; | ||
var id = makeRandomId_1.default(24); | ||
runInterval_1.default(interval, runs, function () { | ||
import makeRandomId from './makeRandomId.js'; | ||
import runInterval from './runInterval.js'; | ||
const makeReliable = (options, cb) => { | ||
const { interval = 150, runs = 10 } = options; | ||
const id = makeRandomId(24); | ||
runInterval(interval, runs, () => { | ||
cb(id); | ||
}); | ||
}; | ||
exports.makeReliable = makeReliable; | ||
export { makeReliable }; | ||
//# sourceMappingURL=reliableMessage.js.map |
@@ -1,7 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var runInterval = function (interval, runs, cb) { | ||
if (interval === void 0) { interval = 200; } | ||
if (runs === void 0) { runs = 1; } | ||
var counter = 0; | ||
const runInterval = (interval = 200, runs = 1, cb) => { | ||
let counter = 0; | ||
if (typeof cb !== 'function') { | ||
@@ -11,3 +7,3 @@ console.error('You have to define your callback function!'); | ||
} | ||
var i = setInterval(function () { | ||
const i = setInterval(() => { | ||
cb(); | ||
@@ -21,3 +17,3 @@ counter++; | ||
}; | ||
exports.default = runInterval; | ||
export default runInterval; | ||
//# sourceMappingURL=runInterval.js.map |
@@ -1,4 +0,4 @@ | ||
import { Data, EventName, RawMessage } from './types'; | ||
import { Data, EventName, RawMessage } from './types.js'; | ||
declare const SendMessage: (dataChannel: any | RTCDataChannel, maxMessageSize: number | undefined, eventName: EventName, data?: Data | RawMessage | null) => any; | ||
export default SendMessage; | ||
//# sourceMappingURL=sendMessage.d.ts.map |
@@ -1,18 +0,14 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var helpers_1 = require("./helpers"); | ||
var constants_1 = require("./constants"); | ||
var SendMessage = function (dataChannel, maxMessageSize, eventName, data) { | ||
import { isBufferMessage, isStringMessage } from './helpers.js'; | ||
import { EVENTS } from './constants.js'; | ||
const SendMessage = (dataChannel, maxMessageSize, eventName, data = null) => { | ||
var _a; | ||
var _b; | ||
if (data === void 0) { data = null; } | ||
var send = function (data, isBuffer) { | ||
const send = (data, isBuffer) => { | ||
var _a; | ||
var bytes = (_a = data.byteLength) !== null && _a !== void 0 ? _a : data.length * 2; // (times 2 for characters that uses 2 bytes per char) | ||
const bytes = (_a = data.byteLength) !== null && _a !== void 0 ? _a : data.length * 2; // (times 2 for characters that uses 2 bytes per char) | ||
if (typeof maxMessageSize === 'number' && bytes > maxMessageSize) { | ||
throw new Error("maxMessageSize of " + maxMessageSize + " exceeded"); | ||
throw new Error(`maxMessageSize of ${maxMessageSize} exceeded`); | ||
} | ||
else { | ||
Promise.resolve() | ||
.then(function () { | ||
.then(() => { | ||
// server-side (send() does not exist on the server side) | ||
@@ -28,3 +24,3 @@ if (dataChannel.send) | ||
}) | ||
.catch(function (error) { | ||
.catch(error => { | ||
console.log('error', error); | ||
@@ -36,9 +32,9 @@ }); | ||
return; | ||
if (dataChannel.readyState === 'open' || ((_b = dataChannel.isOpen) === null || _b === void 0 ? void 0 : _b.call(dataChannel))) { | ||
if (dataChannel.readyState === 'open' || ((_a = dataChannel.isOpen) === null || _a === void 0 ? void 0 : _a.call(dataChannel))) { | ||
try { | ||
if (eventName === constants_1.EVENTS.RAW_MESSAGE && data !== null && (helpers_1.isStringMessage(data) || helpers_1.isBufferMessage(data))) { | ||
send(data, helpers_1.isBufferMessage(data)); | ||
if (eventName === EVENTS.RAW_MESSAGE && data !== null && (isStringMessage(data) || isBufferMessage(data))) { | ||
send(data, isBufferMessage(data)); | ||
} | ||
else { | ||
send(JSON.stringify((_a = {}, _a[eventName] = data, _a)), false); | ||
send(JSON.stringify({ [eventName]: data }), false); | ||
} | ||
@@ -52,3 +48,3 @@ } | ||
}; | ||
exports.default = SendMessage; | ||
export default SendMessage; | ||
//# sourceMappingURL=sendMessage.js.map |
@@ -25,5 +25,8 @@ /// <reference types="node" /> | ||
iceServers?: RTCIceServer[]; | ||
/** @deprecated since version 2.0 (not available in node-datachannel) */ | ||
iceTransportPolicy?: RTCIceTransportPolicy; | ||
label?: string; | ||
/** @deprecated since version 2.0 (not available in node-datachannel) */ | ||
maxPacketLifeTime?: number; | ||
/** @deprecated since version 2.0 (not available in node-datachannel) */ | ||
maxRetransmits?: number; | ||
@@ -30,0 +33,0 @@ ordered?: boolean; |
@@ -1,6 +0,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ArrayBufferView = void 0; | ||
var ArrayBufferView = Object.getPrototypeOf(Object.getPrototypeOf(new Uint8Array())).constructor; | ||
exports.ArrayBufferView = ArrayBufferView; | ||
const ArrayBufferView = Object.getPrototypeOf(Object.getPrototypeOf(new Uint8Array())).constructor; | ||
export { ArrayBufferView }; | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "@geckos.io/common", | ||
"version": "2.0.0-dev.4", | ||
"version": "2.0.0", | ||
"description": "The common module for @geckos.io/server and @geckos.io/client.", | ||
"main": "lib", | ||
"type": "module", | ||
"author": "Yannick Deubel (https://github.com/yandeu)", | ||
@@ -7,0 +8,0 @@ "license": "BSD-3-Clause", |
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
Yes
25384
341