Skip to content

Commit 7764a65

Browse files
committed
Add getUserData
1 parent 816e8d0 commit 7764a65

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/WebSocketWrapper.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ struct WebSocketWrapper {
3939
args.Holder()->SetAlignedPointerInInternalField(0, nullptr);
4040
}
4141

42+
/* Takes nothing returns holder (only used to fool TypeScript, as a conversion from WS to UserData) */
43+
template <bool SSL>
44+
static void uWS_WebSocket_getUserData(const FunctionCallbackInfo<Value> &args) {
45+
args.GetReturnValue().Set(args.Holder());
46+
}
47+
4248
/* Takes string topic */
4349
template <bool SSL>
4450
static void uWS_WebSocket_subscribe(const FunctionCallbackInfo<Value> &args) {
@@ -317,6 +323,7 @@ struct WebSocketWrapper {
317323
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "sendFragment", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_sendFragment<SSL>));
318324
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "sendLastFragment", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_sendLastFragment<SSL>));
319325

326+
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getUserData", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_getUserData<SSL>));
320327
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "send", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_send<SSL>));
321328
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "end", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_end<SSL>));
322329
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "close", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_close<SSL>));

0 commit comments

Comments
 (0)