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

end

end

getProxiedRemoteAddress

Hierarchy

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));