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

@push-rpc/websocket

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@push-rpc/websocket - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

3

dist/client.d.ts
import { Socket } from "@push-rpc/core";
export declare function wrapWebsocket(ws: any): Socket;
export declare function createWebsocket(url: any, protocol?: any): Socket;
export declare function wrapWebsocket(ws: WebSocket): Socket;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function createWebsocket(url, protocol) {
return wrapWebsocket(new WebSocket(url, protocol));
}
exports.createWebsocket = createWebsocket;
function wrapWebsocket(ws) {
return {
onMessage: function (h) {
return ws.on("message", function (e) {
h(e.toString("utf-8"));
return (ws.onmessage = function (e) {
h(e.data.toString());
});
},
onOpen: function (h) { return ws.on("open", h); },
onOpen: function (h) { return (ws.onopen = h); },
onClose: function (h) {
return ws.on("close", function (code, reason) {
return (ws.onclose = function (_a) {
var code = _a.code, reason = _a.reason;
h(code, reason);
});
},
onError: function (h) { return ws.on("error", h); },
onPong: function (h) { return ws.on("pong", h); },
terminate: function () { return ws.terminate(); },
onError: function (h) { return (ws.onerror = h); },
onPong: function (h) {
// not implemented
},
terminate: function () { return ws.close(); },
send: function (data) { return ws.send(data); },
ping: function (data) { return ws.ping(data); },
ping: function () {
// not implemented
},
};
}
exports.wrapWebsocket = wrapWebsocket;

@@ -1,2 +0,2 @@

export { wrapWebsocket } from "./client";
export { createWebsocketServer, createWebsocket } from "./server";
export { createWebsocket } from "./client";
export { createWebsocketServer } from "./server";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var client_1 = require("./client");
exports.wrapWebsocket = client_1.wrapWebsocket;
exports.createWebsocket = client_1.createWebsocket;
var server_1 = require("./server");
exports.createWebsocketServer = server_1.createWebsocketServer;
exports.createWebsocket = server_1.createWebsocket;

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

import { SocketServer } from "@push-rpc/core";
import * as WebSocket from "ws";
import { Socket, SocketServer } from "@push-rpc/core";
export declare function createWebsocketServer(options?: WebSocket.ServerOptions): SocketServer & {
wss: WebSocket.Server;
};
export declare function createWebsocket(url: any): import("@push-rpc/core").Socket;
export declare function createWebsocket(url: any, protocol?: any): Socket;
export declare function wrapWebsocket(ws: any): Socket;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var WebSocket = require("ws");
var client_1 = require("./client");
function createWebsocketServer(options) {
if (options === void 0) { options = { noServer: true }; }
var wss = new WebSocket.Server(options);
function onError(handler) {
wss.on("error", handler);
}
function onConnection(handler) {
wss.on("connection", function (ws, req) {
handler(client_1.wrapWebsocket(ws), req);
});
}
function close(cb) {
wss.close(cb);
}
return {
onError: onError,
onConnection: onConnection,
close: close,
onError: function (h) {
wss.on("error", h);
},
onConnection: function (h) {
wss.on("connection", function (ws, req) { return h(wrapWebsocket(ws), req); });
},
close: function (h) { return wss.close(h); },
wss: wss,

@@ -27,5 +19,26 @@ };

exports.createWebsocketServer = createWebsocketServer;
function createWebsocket(url) {
return client_1.wrapWebsocket(new WebSocket(url));
function createWebsocket(url, protocol) {
return wrapWebsocket(new WebSocket(url, protocol));
}
exports.createWebsocket = createWebsocket;
function wrapWebsocket(ws) {
return {
onMessage: function (h) {
return ws.on("message", function (e) {
h(e.toString("utf-8"));
});
},
onOpen: function (h) { return ws.on("open", h); },
onClose: function (h) {
return ws.on("close", function (code, reason) {
h(code, reason);
});
},
onError: function (h) { return ws.on("error", h); },
onPong: function (h) { return ws.on("pong", h); },
terminate: function () { return ws.terminate(); },
send: function (data) { return ws.send(data); },
ping: function (data) { return ws.ping(data); },
};
}
exports.wrapWebsocket = wrapWebsocket;
{
"name": "@push-rpc/websocket",
"version": "1.0.1",
"version": "1.0.2",
"main": "dist/index.js",

@@ -20,2 +20,4 @@ "types": "dist/index.d.ts",

},
"repository": "https://github.com/vasyas/push-rpc.git",
"author": "Vasyl Stashuk <vasyl@stashuk.com>",
"publishConfig": {

@@ -22,0 +24,0 @@ "access": "public"

import {Socket} from "@push-rpc/core"
export function wrapWebsocket(ws): Socket {
export function createWebsocket(url, protocol?) {
return wrapWebsocket(new WebSocket(url, protocol))
}
export function wrapWebsocket(ws: WebSocket): Socket {
return {
onMessage: h =>
ws.on("message", e => {
h(e.toString("utf-8"))
(ws.onmessage = e => {
h(e.data.toString())
}),
onOpen: h => ws.on("open", h),
onOpen: h => (ws.onopen = h),
onClose: h =>
ws.on("close", (code, reason) => {
(ws.onclose = ({code, reason}) => {
h(code, reason)
}),
onError: h => ws.on("error", h),
onPong: h => ws.on("pong", h),
onError: h => (ws.onerror = h),
onPong: h => {
// not implemented
},
terminate: () => ws.terminate(),
terminate: () => ws.close(),
send: data => ws.send(data),
ping: data => ws.ping(data),
ping: () => {
// not implemented
},
}
}

@@ -1,2 +0,2 @@

export {wrapWebsocket} from "./client"
export {createWebsocketServer, createWebsocket} from "./server"
export {createWebsocket} from "./client"
export {createWebsocketServer} from "./server"

@@ -1,5 +0,3 @@

import {SocketServer} from "@push-rpc/core"
import * as WebSocket from "ws"
import {wrapWebsocket} from "./client"
import {Socket, SocketServer} from "@push-rpc/core"

@@ -11,26 +9,36 @@ export function createWebsocketServer(

function onError(handler) {
wss.on("error", handler)
return {
onError: h => {
wss.on("error", h)
},
onConnection: h => {
wss.on("connection", (ws, req) => h(wrapWebsocket(ws), req))
},
close: h => wss.close(h),
wss,
}
}
function onConnection(handler) {
wss.on("connection", (ws, req) => {
handler(wrapWebsocket(ws), req)
})
}
export function createWebsocket(url, protocol?) {
return wrapWebsocket(new WebSocket(url, protocol))
}
function close(cb) {
wss.close(cb)
}
export function wrapWebsocket(ws): Socket {
return {
onMessage: h =>
ws.on("message", e => {
h(e.toString("utf-8"))
}),
onOpen: h => ws.on("open", h),
onClose: h =>
ws.on("close", (code, reason) => {
h(code, reason)
}),
onError: h => ws.on("error", h),
onPong: h => ws.on("pong", h),
return {
onError,
onConnection,
close,
wss,
terminate: () => ws.terminate(),
send: data => ws.send(data),
ping: data => ws.ping(data),
}
}
export function createWebsocket(url) {
return wrapWebsocket(new WebSocket(url))
}

@@ -6,3 +6,4 @@ {

"lib": [
"es6"
"es6",
"dom"
],

@@ -9,0 +10,0 @@ "declaration": true

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