add ws.send sendStatus (#707)

This commit is contained in:
e3dio
2022-05-04 10:55:46 -07:00
committed by GitHub
parent 0c6615488d
commit e23d6eda45
3 changed files with 20 additions and 22 deletions

View File

@@ -25,16 +25,15 @@ IPv6 is 16 byte long and can be converted to text in similar ways, but you typic
<p>Returns a list of topics this websocket is subscribed to.</p>
</div></div><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol">[]</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="isSubscribed" class="tsd-anchor"></a><h3>is<wbr/>Subscribed</h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface"><li class="tsd-signature tsd-kind-icon">is<wbr/>Subscribed<span class="tsd-signature-symbol">(</span>topic<span class="tsd-signature-symbol">: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/uNetworking/uWebSockets.js/blob/master/docs/index.d.ts#L83">index.d.ts:83</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Returns whether this websocket is subscribed to topic.</p>
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>topic: <a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="ping" class="tsd-anchor"></a><h3>ping</h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface"><li class="tsd-signature tsd-kind-icon">ping<span class="tsd-signature-symbol">(</span>message<span class="tsd-signature-symbol">?: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/uNetworking/uWebSockets.js/blob/master/docs/index.d.ts#L74">index.d.ts:74</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Sends a ping control message. Returns true on success in similar ways as WebSocket.send does (regarding backpressure). This helper function correlates to WebSocket::send(message, uWS::OpCode::PING, ...) in C++.</p>
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> message: <a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="publish" class="tsd-anchor"></a><h3>publish</h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface"><li class="tsd-signature tsd-kind-icon">publish<span class="tsd-signature-symbol">(</span>topic<span class="tsd-signature-symbol">: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a>, message<span class="tsd-signature-symbol">: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a>, isBinary<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span>, compress<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/uNetworking/uWebSockets.js/blob/master/docs/index.d.ts#L91">index.d.ts:91</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>topic: <a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="ping" class="tsd-anchor"></a><h3>ping</h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface"><li class="tsd-signature tsd-kind-icon">ping<span class="tsd-signature-symbol">(</span>message<span class="tsd-signature-symbol">?: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/uNetworking/uWebSockets.js/blob/master/docs/index.d.ts#L74">index.d.ts:74</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Sends a ping control message. Returns sendStatus similar to WebSocket.send (regarding backpressure). This helper function correlates to WebSocket::send(message, uWS::OpCode::PING, ...) in C++.</p>
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> message: <a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="publish" class="tsd-anchor"></a><h3>publish</h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface"><li class="tsd-signature tsd-kind-icon">publish<span class="tsd-signature-symbol">(</span>topic<span class="tsd-signature-symbol">: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a>, message<span class="tsd-signature-symbol">: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a>, isBinary<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span>, compress<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/uNetworking/uWebSockets.js/blob/master/docs/index.d.ts#L91">index.d.ts:91</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Publish a message under topic. Backpressure is managed according to maxBackpressure, closeOnBackpressureLimit settings.
Order is guaranteed since v20.</p>
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>topic: <a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a></h5></li><li><h5>message: <a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a></h5></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> isBinary: <span class="tsd-signature-type">boolean</span></h5></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> compress: <span class="tsd-signature-type">boolean</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="send" class="tsd-anchor"></a><h3>send</h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface"><li class="tsd-signature tsd-kind-icon">send<span class="tsd-signature-symbol">(</span>message<span class="tsd-signature-symbol">: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a>, isBinary<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span>, compress<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/uNetworking/uWebSockets.js/blob/master/docs/index.d.ts#L56">index.d.ts:56</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Sends a message. Make sure to check getBufferedAmount() before sending. Returns true for success, false for built up backpressure that will drain when time is given.
Returning false does not mean nothing was sent, it only means backpressure was built up. This you can check by calling getBufferedAmount() afterwards.</p>
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>topic: <a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a></h5></li><li><h5>message: <a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a></h5></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> isBinary: <span class="tsd-signature-type">boolean</span></h5></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> compress: <span class="tsd-signature-type">boolean</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="send" class="tsd-anchor"></a><h3>send</h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface"><li class="tsd-signature tsd-kind-icon">send<span class="tsd-signature-symbol">(</span>message<span class="tsd-signature-symbol">: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a>, isBinary<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span>, compress<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/uNetworking/uWebSockets.js/blob/master/docs/index.d.ts#L56">index.d.ts:56</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Sends a message. Returns 1 for success, 2 for dropped due to backpressure limit, and 0 for built up backpressure that will drain over time. You can check backpressure before or after sending by calling getBufferedAmount().</p>
</div><div><p>Make sure you properly understand the concept of backpressure. Check the backpressure example file.</p>
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>message: <a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a></h5></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> isBinary: <span class="tsd-signature-type">boolean</span></h5></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> compress: <span class="tsd-signature-type">boolean</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="subscribe" class="tsd-anchor"></a><h3>subscribe</h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface"><li class="tsd-signature tsd-kind-icon">subscribe<span class="tsd-signature-symbol">(</span>topic<span class="tsd-signature-symbol">: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/uNetworking/uWebSockets.js/blob/master/docs/index.d.ts#L77">index.d.ts:77</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>message: <a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a></h5></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> isBinary: <span class="tsd-signature-type">boolean</span></h5></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> compress: <span class="tsd-signature-type">boolean</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="subscribe" class="tsd-anchor"></a><h3>subscribe</h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface"><li class="tsd-signature tsd-kind-icon">subscribe<span class="tsd-signature-symbol">(</span>topic<span class="tsd-signature-symbol">: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/uNetworking/uWebSockets.js/blob/master/docs/index.d.ts#L77">index.d.ts:77</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Subscribe to a topic.</p>
</div></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>topic: <a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">boolean</span></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface"><a id="unsubscribe" class="tsd-anchor"></a><h3>unsubscribe</h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface"><li class="tsd-signature tsd-kind-icon">unsubscribe<span class="tsd-signature-symbol">(</span>topic<span class="tsd-signature-symbol">: </span><a href="../index.html#RecognizedString" class="tsd-signature-type" data-tsd-kind="Type alias">RecognizedString</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">boolean</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/uNetworking/uWebSockets.js/blob/master/docs/index.d.ts#L80">index.d.ts:80</a></li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead">
<p>Unsubscribe from a topic. Returns true on success, if the WebSocket was subscribed.</p>

9
docs/index.d.ts vendored
View File

@@ -48,12 +48,11 @@ export type RecognizedString = string | ArrayBuffer | Uint8Array | Int8Array | U
* Read more about this in the user manual.
*/
export interface WebSocket {
/** Sends a message. Make sure to check getBufferedAmount() before sending. Returns true for success, false for built up backpressure that will drain when time is given.
* Returning false does not mean nothing was sent, it only means backpressure was built up. This you can check by calling getBufferedAmount() afterwards.
/** Sends a message. Returns 1 for success, 2 for dropped due to backpressure limit, and 0 for built up backpressure that will drain over time. You can check backpressure before or after sending by calling getBufferedAmount().
*
* Make sure you properly understand the concept of backpressure. Check the backpressure example file.
*/
send(message: RecognizedString, isBinary?: boolean, compress?: boolean) : boolean;
send(message: RecognizedString, isBinary?: boolean, compress?: boolean) : number;
/** Returns the bytes buffered in backpressure. This is similar to the bufferedAmount property in the browser counterpart.
* Check backpressure example.
@@ -70,8 +69,8 @@ export interface WebSocket {
*/
close() : void;
/** Sends a ping control message. Returns true on success in similar ways as WebSocket.send does (regarding backpressure). This helper function correlates to WebSocket::send(message, uWS::OpCode::PING, ...) in C++. */
ping(message?: RecognizedString) : boolean;
/** Sends a ping control message. Returns sendStatus similar to WebSocket.send (regarding backpressure). This helper function correlates to WebSocket::send(message, uWS::OpCode::PING, ...) in C++. */
ping(message?: RecognizedString) : number;
/** Subscribe to a topic. */
subscribe(topic: RecognizedString) : boolean;

View File

@@ -175,9 +175,9 @@ struct WebSocketWrapper {
return;
}
bool ok = ws->sendFirstFragment(message.getString(), args[1]->BooleanValue(isolate) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[2]->BooleanValue(isolate));
unsigned int sendStatus = ws->sendFirstFragment(message.getString(), args[1]->BooleanValue(isolate) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[2]->BooleanValue(isolate));
args.GetReturnValue().Set(Boolean::New(isolate, ok));
args.GetReturnValue().Set(Integer::NewFromUnsigned(isolate, sendStatus));
}
}
@@ -192,9 +192,9 @@ struct WebSocketWrapper {
return;
}
bool ok = ws->sendFragment(message.getString(), args[1]->BooleanValue(isolate));
unsigned int sendStatus = ws->sendFragment(message.getString(), args[1]->BooleanValue(isolate));
args.GetReturnValue().Set(Boolean::New(isolate, ok));
args.GetReturnValue().Set(Integer::NewFromUnsigned(isolate, sendStatus));
}
}
@@ -209,9 +209,9 @@ struct WebSocketWrapper {
return;
}
bool ok = ws->sendLastFragment(message.getString(), args[1]->BooleanValue(isolate));
unsigned int sendStatus = ws->sendLastFragment(message.getString(), args[1]->BooleanValue(isolate));
args.GetReturnValue().Set(Boolean::New(isolate, ok));
args.GetReturnValue().Set(Integer::NewFromUnsigned(isolate, sendStatus));
}
}
@@ -226,9 +226,9 @@ struct WebSocketWrapper {
return;
}
bool ok = ws->send(message.getString(), args[1]->BooleanValue(isolate) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[2]->BooleanValue(isolate));
unsigned int sendStatus = ws->send(message.getString(), args[1]->BooleanValue(isolate) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[2]->BooleanValue(isolate));
args.GetReturnValue().Set(Boolean::New(isolate, ok));
args.GetReturnValue().Set(Integer::NewFromUnsigned(isolate, sendStatus));
}
}
@@ -261,9 +261,9 @@ struct WebSocketWrapper {
}
/* This is a wrapper that does not exist in the C++ project */
bool ok = ws->send(message.getString(), uWS::OpCode::PING);
unsigned int sendStatus = ws->send(message.getString(), uWS::OpCode::PING);
args.GetReturnValue().Set(Boolean::New(isolate, ok));
args.GetReturnValue().Set(Integer::NewFromUnsigned(isolate, sendStatus));
}
}