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

@mercuryworkshop/wisp-client-js

Package Overview
Dependencies
Maintainers
5
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mercuryworkshop/wisp-client-js - npm Package Compare versions

Comparing version 1.0.3 to 1.1.0

2

package.json
{
"name": "@mercuryworkshop/wisp-client-js",
"version": "1.0.3",
"version": "1.1.0",
"description": "A Wisp client implementation, written in Javascript for the use on the web. ",

@@ -5,0 +5,0 @@ "repository": {

@@ -20,3 +20,3 @@ # JavaScript Wisp Client

### Creating New Streams:
Once you have your `WispConnection` object, and you have waited for the connection to be established, you can use the `WispConnection.create_stream` method to create new streams. The two arguments to this function are the hostname and port of the new stream, and a `WispStream` object will be returned.
Once you have your `WispConnection` object, and you have waited for the connection to be established, you can use the `WispConnection.create_stream` method to create new streams. The two arguments to this function are the hostname and port of the new stream, and a `WispStream` object will be returned. You can also pass a third argument to `create_stream`, which is the type of the stream, and it can be either `"tcp"` (the default) or `"udp"`.

@@ -23,0 +23,0 @@ For receiving incoming messages, use the `message` event on the `WispStream` object. The returned data will always be a `Uint8Array`. The `close` and `error` events can be used to know when the stream is closed.

@@ -50,4 +50,4 @@ //mapping of packet names to packet types

export class WispStream extends EventTarget {
constructor(hostname, port, websocket, buffer_size, stream_id, connection) {
class WispStream extends EventTarget {
constructor(hostname, port, websocket, buffer_size, stream_id, connection, stream_type) {
super();

@@ -60,2 +60,3 @@ this.hostname = hostname;

this.connection = connection;
this.stream_type = stream_type;
this.send_buffer = [];

@@ -66,3 +67,4 @@ this.open = true;

send(data) {
if (this.buffer_size > 0 || !this.open) {
//note: udp shouldn't buffer anything
if (this.buffer_size > 0 || !this.open || this.stream_type === 0x02) {
//construct and send a DATA packet

@@ -156,10 +158,11 @@ let packet = create_packet(0x02, this.stream_id, data);

create_stream(hostname, port) {
create_stream(hostname, port, type="tcp") {
let stream_type = type === "udp" ? 0x02 : 0x01;
let stream_id = this.next_stream_id
this.next_stream_id++;
let stream = new WispStream(hostname, port, this.ws, this.max_buffer_size, stream_id, this);
let stream = new WispStream(hostname, port, this.ws, this.max_buffer_size, stream_id, this, stream_type);
stream.open = this.connected;
//construct CONNECT packet
let type_array = array_from_uint(0x01, 1);
let type_array = array_from_uint(stream_type, 1);
let port_array = array_from_uint(port, 2);

@@ -207,3 +210,2 @@ let host_array = new TextEncoder().encode(hostname);

else if (packet_type === packet_types.CLOSE) { //CLOSE packets
if (!stream) return;
this.close_stream(stream, payload[0]);

@@ -210,0 +212,0 @@ }

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