Wrap WebSocket.cork, update docs

This commit is contained in:
Alex Hultman 2020-01-10 19:02:51 +01:00
parent 6691236309
commit 68fde105e6
13 changed files with 157 additions and 82 deletions

View file

@ -232,7 +232,7 @@ struct HttpResponseWrapper {
}
}
/* Takes function, returns this (EXPERIMENTAL) */
/* Takes function, returns this */
template <bool SSL>
static void res_cork(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();

View file

@ -138,6 +138,32 @@ struct WebSocketWrapper {
}
}
/* Takes nothing, returns this */
/*template <bool SSL>
static void uWS_WebSocket_unsubscribeAll(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
auto *ws = getWebSocket<SSL>(args);
if (ws) {
ws->unsubscribeAll();
args.GetReturnValue().Set(args.Holder());
}
}*/
/* Takes function, returns this */
template <bool SSL>
static void uWS_WebSocket_cork(const FunctionCallbackInfo<Value> &args) {
Isolate *isolate = args.GetIsolate();
auto *ws = getWebSocket<SSL>(args);
if (ws) {
ws->cork([cb = Local<Function>::Cast(args[0]), isolate]() {
cb->Call(isolate->GetCurrentContext(), isolate->GetCurrentContext()->Global(), 0, nullptr).IsEmpty();
});
args.GetReturnValue().Set(args.Holder());
}
}
template <bool SSL>
static Local<Object> init(Isolate *isolate) {
Local<FunctionTemplate> wsTemplateLocal = FunctionTemplate::New(isolate);
@ -157,6 +183,8 @@ struct WebSocketWrapper {
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "subscribe", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_subscribe<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "unsubscribe", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_unsubscribe<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "publish", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_publish<SSL>));
//wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "unsubscribeAll", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_unsubscribeAll<SSL>));
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "cork", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_cork<SSL>));
/* Create the template */
Local<Object> wsObjectLocal = wsTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();