@mercuryworkshop/wisp-client-js
Advanced tools
Comparing version 1.0.3 to 1.1.0
{ | ||
"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. |
16
wisp.js
@@ -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
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
51205
328
0