From bce99d8884136b1ca54eee12961da6ed39a6f34b Mon Sep 17 00:00:00 2001 From: snowbldr Date: Tue, 7 Dec 2021 06:46:30 -0700 Subject: [PATCH] change websocket publish to return boolean as the uws method publish returns boolean (#641) * Update docs to match implementation * change websocket publish to return boolean as the uws method publish returns boolean * re-generate typedoc since publish changed to return boolean --- docs/generated/interfaces/HttpResponse.html | 4 ++-- docs/generated/interfaces/WebSocket.html | 8 ++++---- docs/index.d.ts | 8 ++++---- src/WebSocketWrapper.h | 7 ++++--- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/docs/generated/interfaces/HttpResponse.html b/docs/generated/interfaces/HttpResponse.html index becc39c..8d251fd 100644 --- a/docs/generated/interfaces/HttpResponse.html +++ b/docs/generated/interfaces/HttpResponse.html @@ -4,7 +4,7 @@

Arbitrary user data may be attached to this object

Index

Methods

close

cork

  • cork(cb: () => void): void

cork

  • Corking a response is a performance improvement in both CPU and network, as you ready the IO system for writing multiple chunks at once. By default, you're corked in the immediately executing top portion of the route handler. In all other cases, such as when returning from await, or when being called back from an async database request or anything that isn't directly executing in the route handler, you'll want @@ -15,7 +15,7 @@ in one TLS block being sent off, each with one send syscall.

    res.cork(() => { res.writeStatus("200 OK").writeHeader("Some", "Value").write("Hello world!"); });

    -

    Parameters

    • cb: () => void
        • (): void
        • Returns void

    Returns void

end

end

getProxiedRemoteAddress

  • getProxiedRemoteAddress(): ArrayBuffer
  • Returns the remote IP address in binary format (4 or 16 bytes), as reported by the PROXY Protocol v2 compatible proxy.

    diff --git a/docs/generated/interfaces/WebSocket.html b/docs/generated/interfaces/WebSocket.html index 961afec..063946f 100644 --- a/docs/generated/interfaces/WebSocket.html +++ b/docs/generated/interfaces/WebSocket.html @@ -3,15 +3,15 @@ Read more about this in the user manual.

Hierarchy

  • WebSocket

Indexable

[key: string]: any

Arbitrary user data may be attached to this object. In C++ this is done by using getUserData().

-

Index

Methods

close

Index

Methods

close

  • close(): void
  • Forcefully closes this WebSocket. Immediately calls the close handler. No WebSocket close message is sent.

    -

    Returns WebSocket

cork

  • cork(cb: () => void): void

cork

  • See HttpResponse.cork. Takes a function in which the socket is corked (packing many sends into one single syscall/SSL block)

    -

    Parameters

    • cb: () => void
        • (): void
        • Returns void

    Returns void

end

end

  • Gracefully closes this WebSocket. Immediately calls the close handler. A WebSocket close message is sent with code and shortMessage.

    -

    Parameters

    Returns WebSocket

getBufferedAmount

  • getBufferedAmount(): number

getBufferedAmount

  • getBufferedAmount(): number
  • Returns the bytes buffered in backpressure. This is similar to the bufferedAmount property in the browser counterpart. Check backpressure example.

    Returns number

getRemoteAddress

  • getRemoteAddress(): ArrayBuffer
  • diff --git a/docs/index.d.ts b/docs/index.d.ts index 4723ec2..b8d1afd 100644 --- a/docs/index.d.ts +++ b/docs/index.d.ts @@ -63,12 +63,12 @@ export interface WebSocket { /** Gracefully closes this WebSocket. Immediately calls the close handler. * A WebSocket close message is sent with code and shortMessage. */ - end(code?: number, shortMessage?: RecognizedString) : WebSocket; + end(code?: number, shortMessage?: RecognizedString) : void; /** Forcefully closes this WebSocket. Immediately calls the close handler. * No WebSocket close message is sent. */ - close() : 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; @@ -91,7 +91,7 @@ export interface WebSocket { publish(topic: RecognizedString, message: RecognizedString, isBinary?: boolean, compress?: boolean) : boolean; /** See HttpResponse.cork. Takes a function in which the socket is corked (packing many sends into one single syscall/SSL block) */ - cork(cb: () => void) : void; + cork(cb: () => void) : WebSocket; /** Returns the remote IP address. Note that the returned IP is binary, not text. * @@ -183,7 +183,7 @@ export interface HttpResponse { * res.writeStatus("200 OK").writeHeader("Some", "Value").write("Hello world!"); * }); */ - cork(cb: () => void) : void; + cork(cb: () => void) : HttpResponse; /** Upgrades a HttpResponse to a WebSocket. See UpgradeAsync, UpgradeSync example files. */ upgrade(userData : T, secWebSocketKey: RecognizedString, secWebSocketProtocol: RecognizedString, secWebSocketExtensions: RecognizedString, context: us_socket_context_t) : void; diff --git a/src/WebSocketWrapper.h b/src/WebSocketWrapper.h index 993b1e1..90cff21 100644 --- a/src/WebSocketWrapper.h +++ b/src/WebSocketWrapper.h @@ -71,7 +71,7 @@ struct WebSocketWrapper { } } - /* Takes string topic, message */ + /* Takes string topic, message, returns boolean success */ template static void uWS_WebSocket_publish(const FunctionCallbackInfo &args) { Isolate *isolate = args.GetIsolate(); @@ -90,7 +90,8 @@ struct WebSocketWrapper { return; } - ws->publish(topic.getString(), message.getString(), args[2]->BooleanValue(isolate) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[3]->BooleanValue(isolate)); + bool success = ws->publish(topic.getString(), message.getString(), args[2]->BooleanValue(isolate) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[3]->BooleanValue(isolate)); + args.GetReturnValue().Set(Boolean::New(isolate, success)); } } @@ -315,7 +316,7 @@ struct WebSocketWrapper { wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "sendFirstFragment", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_sendFirstFragment)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "sendFragment", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_sendFragment)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "sendLastFragment", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_sendLastFragment)); - + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "send", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_send)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "end", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_end)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "close", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_close));