Socket
Socket
Sign inDemoInstall

@geckos.io/client

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@geckos.io/client - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

lib/bundle.d.ts

37

lib/client.d.ts

@@ -6,19 +6,50 @@ import { RawMessage, Data, EventName, EventCallbackClient, ConnectionEventCallbackClient, EventCallbackRawMessage } from '@geckos.io/common/lib/typings';

private url;
constructor(url: string, port: number);
constructor(url: string, port: number, label: string);
private onconnectionstatechange;
readonly id: string | undefined;
/** Get the channel's id. */
readonly id: import("@geckos.io/common/lib/typings").ChannelId;
/** Emit a message to the server. */
emit(eventName: EventName, data?: Data | null): void;
/** Emit a raw message to the server */
readonly raw: {
/**
* Emit a raw message.
* @param rawMessage The raw message. Can be of type 'USVString | ArrayBuffer | ArrayBufferView'
*/
emit: (rawMessage: RawMessage) => void;
};
/**
* Listen for a raw message from the server.
* @param callback The event callback.
*/
onRaw(callback: EventCallbackRawMessage): void;
/**
* Listen for the connect event.
* @param callback The event callback.
*/
onConnect(callback: ConnectionEventCallbackClient): Promise<void>;
/**
* Listen for the disconnect event.
* @param callback The event callback.
*/
onDisconnect(callback: ConnectionEventCallbackClient): void;
/**
* Listen for a message from the server.
* @param eventName The event name.
* @param callback The event callback.
*/
on(eventName: EventName, callback: EventCallbackClient): void;
}
/**
* The geckos.io client library.
* @param options.url The url of the server. Default: \`${location.protocol}//${location.hostname}\`.
* @param options.port The port of the server. Default: 9208.
* @param options.label The label of the DataChannel. Default: 'geckos.io'.
*/
declare const geckosClient: (options?: {
url?: string | undefined;
url?: import("@geckos.io/common/lib/typings").ChannelId;
port?: number | undefined;
label?: import("@geckos.io/common/lib/typings").ChannelId;
}) => ClientChannel;
export default geckosClient;
//# sourceMappingURL=client.d.ts.map

@@ -45,6 +45,6 @@ "use strict";

var connectionsManager_1 = __importDefault(require("./wrtc/connectionsManager"));
var ClientChannel = (function () {
function ClientChannel(url, port) {
var ClientChannel = /** @class */ (function () {
function ClientChannel(url, port, label) {
this.url = url + ":" + port;
this.connectionsManager = new connectionsManager_1.default(this.url);
this.connectionsManager = new connectionsManager_1.default(this.url, label);
}

@@ -59,2 +59,3 @@ ClientChannel.prototype.onconnectionstatechange = function () {

Object.defineProperty(ClientChannel.prototype, "id", {
/** Get the channel's id. */
get: function () {

@@ -66,2 +67,3 @@ return this.peerConnection.id;

});
/** Emit a message to the server. */
ClientChannel.prototype.emit = function (eventName, data) {

@@ -72,5 +74,10 @@ if (data === void 0) { data = null; }

Object.defineProperty(ClientChannel.prototype, "raw", {
/** Emit a raw message to the server */
get: function () {
var _this = this;
return {
/**
* Emit a raw message.
* @param rawMessage The raw message. Can be of type 'USVString | ArrayBuffer | ArrayBufferView'
*/
emit: function (rawMessage) { return _this.emit(constants_1.EVENTS.RAW_MESSAGE, rawMessage); }

@@ -82,2 +89,6 @@ };

});
/**
* Listen for a raw message from the server.
* @param callback The event callback.
*/
ClientChannel.prototype.onRaw = function (callback) {

@@ -89,2 +100,6 @@ bridge_1.default.on(constants_1.EVENTS.RAW_MESSAGE, function (rawMessage) {

};
/**
* Listen for the connect event.
* @param callback The event callback.
*/
ClientChannel.prototype.onConnect = function (callback) {

@@ -96,2 +111,3 @@ return __awaiter(this, void 0, void 0, function () {

case 0:
// TODO(yandeu) add a connection timeout (or something like this)
bridge_1.default.on(constants_1.EVENTS.DATA_CHANNEL_IS_OPEN, function () {

@@ -101,3 +117,3 @@ callback();

this.peerConnection = new peerConnection_1.default();
return [4, this.peerConnection.connect(this.connectionsManager)];
return [4 /*yield*/, this.peerConnection.connect(this.connectionsManager)];
case 1:

@@ -109,3 +125,3 @@ error = _a.sent();

this.onconnectionstatechange();
return [2];
return [2 /*return*/];
}

@@ -115,5 +131,14 @@ });

};
/**
* Listen for the disconnect event.
* @param callback The event callback.
*/
ClientChannel.prototype.onDisconnect = function (callback) {
bridge_1.default.on(constants_1.EVENTS.DISCONNECTED, callback);
};
/**
* Listen for a message from the server.
* @param eventName The event name.
* @param callback The event callback.
*/
ClientChannel.prototype.on = function (eventName, callback) {

@@ -127,8 +152,14 @@ bridge_1.default.on(eventName, function (data) {

exports.ClientChannel = ClientChannel;
/**
* The geckos.io client library.
* @param options.url The url of the server. Default: \`${location.protocol}//${location.hostname}\`.
* @param options.port The port of the server. Default: 9208.
* @param options.label The label of the DataChannel. Default: 'geckos.io'.
*/
var geckosClient = function (options) {
if (options === void 0) { options = {}; }
var _a = options.url, url = _a === void 0 ? location.protocol + "//" + location.hostname : _a, _b = options.port, port = _b === void 0 ? 9208 : _b;
return new ClientChannel(url, port);
var _a = options.url, url = _a === void 0 ? location.protocol + "//" + location.hostname : _a, _b = options.port, port = _b === void 0 ? 9208 : _b, _c = options.label, label = _c === void 0 ? 'geckos.io' : _c;
return new ClientChannel(url, port, label);
};
exports.default = geckosClient;
//# sourceMappingURL=client.js.map

5

lib/wrtc/connectionsManager.d.ts

@@ -8,2 +8,3 @@ import { RawMessage, Data, ChannelId, EventName } from '@geckos.io/common/lib/typings';

url: string;
label: string;
localPeerConnection: RTCPeerConnection;

@@ -14,3 +15,3 @@ remotePeerConnection: RTCRemotePeerConnection;

emit(eventName: EventName, data?: Data | RawMessage | null): void;
constructor(url: string);
constructor(url: string, label: string);
onDataChannel: (ev: RTCDataChannelEvent) => void;

@@ -20,3 +21,3 @@ connect(): Promise<{

dataChannel: RTCDataChannel;
id: string | undefined;
id: ChannelId;
}>;

@@ -23,0 +24,0 @@ }

@@ -45,9 +45,10 @@ "use strict";

var sendMessage_1 = __importDefault(require("@geckos.io/common/lib/sendMessage"));
var ConnectionsManagerClient = (function () {
function ConnectionsManagerClient(url) {
var ConnectionsManagerClient = /** @class */ (function () {
function ConnectionsManagerClient(url, label) {
var _this = this;
this.url = url;
this.label = label;
this.onDataChannel = function (ev) {
var channel = ev.channel;
if (channel.label !== 'geckos.io')
if (channel.label !== _this.label)
return;

@@ -76,3 +77,3 @@ _this.dataChannel = channel;

_c.trys.push([1, 4, , 5]);
return [4, fetch(host + "/connections", {
return [4 /*yield*/, fetch(host + "/connections", {
method: 'POST',

@@ -86,10 +87,10 @@ headers: {

_a = this;
return [4, res.json()];
return [4 /*yield*/, res.json()];
case 3:
_a.remotePeerConnection = _c.sent();
return [3, 5];
return [3 /*break*/, 5];
case 4:
error_1 = _c.sent();
console.error(error_1.message);
return [3, 5];
return [3 /*break*/, 5];
case 5:

@@ -100,2 +101,3 @@ _b = this.remotePeerConnection, id = _b.id, localDescription = _b.localDescription;

webkitRTCPeerConnection ||
// @ts-ignore
mozRTCPeerConnection;

@@ -106,7 +108,7 @@ this.localPeerConnection = new RTCPc(configuration);

_c.trys.push([6, 14, , 15]);
return [4, this.localPeerConnection.setRemoteDescription(localDescription)];
return [4 /*yield*/, this.localPeerConnection.setRemoteDescription(localDescription)];
case 7:
_c.sent();
this.localPeerConnection.addEventListener('datachannel', this.onDataChannel);
return [4, this.localPeerConnection.createAnswer()];
return [4 /*yield*/, this.localPeerConnection.createAnswer()];
case 8:

@@ -118,3 +120,3 @@ originalAnswer = _c.sent();

});
return [4, this.localPeerConnection.setLocalDescription(updatedAnswer)];
return [4 /*yield*/, this.localPeerConnection.setLocalDescription(updatedAnswer)];
case 9:

@@ -125,3 +127,3 @@ _c.sent();

_c.trys.push([10, 12, , 13]);
return [4, fetch(host + "/connections/" + id + "/remote-description", {
return [4 /*yield*/, fetch(host + "/connections/" + id + "/remote-description", {
method: 'POST',

@@ -135,8 +137,8 @@ body: JSON.stringify(this.localPeerConnection.localDescription),

_c.sent();
return [3, 13];
return [3 /*break*/, 13];
case 12:
error_2 = _c.sent();
console.error(error_2.message);
return [3, 13];
case 13: return [2, {
return [3 /*break*/, 13];
case 13: return [2 /*return*/, {
localPeerConnection: this.localPeerConnection,

@@ -151,3 +153,3 @@ dataChannel: this.dataChannel,

throw error_3;
case 15: return [2];
case 15: return [2 /*return*/];
}

@@ -154,0 +156,0 @@ });

@@ -39,3 +39,3 @@ "use strict";

var constants_1 = require("@geckos.io/common/lib/constants");
var PeerConnection = (function () {
var PeerConnection = /** @class */ (function () {
function PeerConnection() {

@@ -51,5 +51,6 @@ }

webkitRTCPeerConnection ||
// @ts-ignore
mozRTCPeerConnection;
if (!webRTCPcSupported) return [3, 2];
return [4, connectionsManager.connect()];
if (!webRTCPcSupported) return [3 /*break*/, 2];
return [4 /*yield*/, connectionsManager.connect()];
case 1:

@@ -60,7 +61,7 @@ _a = _b.sent(), localPeerConnection = _a.localPeerConnection, dataChannel = _a.dataChannel, id = _a.id;

this.id = id;
return [2, null];
return [2 /*return*/, null];
case 2:
error = new Error(constants_1.ERRORS.BROWSER_NOT_SUPPORTED);
console.error(error.message);
return [2, error];
return [2 /*return*/, error];
}

@@ -67,0 +68,0 @@ });

{
"name": "@geckos.io/client",
"version": "0.0.2",
"version": "0.0.3",
"description": "Real-time client/server communication over UDP using WebRTC and Node.js",

@@ -34,12 +34,15 @@ "main": "lib/index.js",

"engines": {
"node": ">=10.0.0"
"node": "8.x || 10.x || 11.x"
},
"scripts": {
"bundle:latest": "../../node_modules/.bin/webpack --config webpack/webpack.prod.js --packageVersion=latest",
"bundle:version": "../../node_modules/.bin/webpack --config webpack/webpack.prod.js --packageVersion=${npm_package_version}",
"install:dev": "npm link @geckos.io/common && npm i",
"build": "tsc --build tsconfig.json",
"prepublish": "npm run build"
"prepublish": "npm run build",
"postpublish": "npm run bundle:version && npm run bundle:latest"
},
"dependencies": {
"@geckos.io/common": "0.0.2"
"@geckos.io/common": "0.0.3"
}
}

@@ -7,6 +7,7 @@ <a href="http://geckos.io">

[![Dependency Status](https://david-dm.org/geckosio/geckos.io/status.svg?path=packages/client)](https://david-dm.org/geckosio/geckos.io?path=packages%2Fclient)
[![devDependency Status](https://david-dm.org/geckosio/geckos.io/dev-status.svg?path=packages/client)](https://david-dm.org/geckosio/geckos.io?path=packages%2Fclient&type=dev)
[![NPM version](https://img.shields.io/npm/v/@geckos.io/client.svg?color=%230fc625)](https://www.npmjs.com/package/@geckos.io/client)
[![Downloads](https://img.shields.io/npm/dm/@geckos.io/client.svg?style=flat)](https://www.npmjs.com/package/@geckos.io/client)
[![Dependency Status](https://david-dm.org/geckosio/geckos.io/status.svg?path=packages/client&style=flat-square)](https://david-dm.org/geckosio/geckos.io?path=packages%2Fclient)
[![NPM version](https://img.shields.io/npm/v/@geckos.io/client.svg?style=flat-square)](https://www.npmjs.com/package/@geckos.io/client)
[![Downloads](https://img.shields.io/npm/dm/@geckos.io/client.svg?style=flat-square)](https://www.npmjs.com/package/@geckos.io/client)
![Node version](https://img.shields.io/node/v/@geckos.io/client.svg?style=flat-square)
[![Minified bundle](https://img.shields.io/github/size/geckosio/geckos.io/bundles/latest/geckos.io-client.latest.min.js.svg?label=minified%20bundle&style=flat-square)](https://github.com/geckosio/geckos.io/tree/master/bundles/versions)

@@ -13,0 +14,0 @@ Real-time client/server communication over UDP using WebRTC and Node.js.

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