Update uWS, wrap ping/pong handlers
This commit is contained in:
parent
3860b922c7
commit
9840bb0fef
@ -24,6 +24,8 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
||||
UniquePersistent<Function> messagePf;
|
||||
UniquePersistent<Function> drainPf;
|
||||
UniquePersistent<Function> closePf;
|
||||
UniquePersistent<Function> pingPf;
|
||||
UniquePersistent<Function> pongPf;
|
||||
|
||||
struct PerSocketData {
|
||||
UniquePersistent<Object> *socketPf;
|
||||
@ -65,6 +67,11 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
||||
drainPf.Reset(args.GetIsolate(), Local<Function>::Cast(behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "drain", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked()));
|
||||
/* Close */
|
||||
closePf.Reset(args.GetIsolate(), Local<Function>::Cast(behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "close", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked()));
|
||||
/* Ping */
|
||||
pingPf.Reset(args.GetIsolate(), Local<Function>::Cast(behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "ping", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked()));
|
||||
/* Pong */
|
||||
pongPf.Reset(args.GetIsolate(), Local<Function>::Cast(behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "pong", NewStringType::kNormal).ToLocalChecked()).ToLocalChecked()));
|
||||
|
||||
}
|
||||
|
||||
/* Open handler is NOT optional for the wrapper */
|
||||
@ -123,14 +130,27 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
||||
};
|
||||
}
|
||||
|
||||
/* These are not hooked in */
|
||||
behavior.ping = [](auto *ws) {
|
||||
/* Ping handler is always optional */
|
||||
if (pingPf != Undefined(isolate)) {
|
||||
behavior.ping = [pingPf = std::move(pingPf), isolate](auto *ws) {
|
||||
HandleScope hs(isolate);
|
||||
|
||||
};
|
||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||
Local<Value> argv[1] = {Local<Object>::New(isolate, *(perSocketData->socketPf))};
|
||||
CallJS(isolate, Local<Function>::New(isolate, pingPf), 1, argv);
|
||||
};
|
||||
}
|
||||
|
||||
behavior.pong = [](auto *ws) {
|
||||
/* Pong handler is always optional */
|
||||
if (pongPf != Undefined(isolate)) {
|
||||
behavior.pong = [pongPf = std::move(pongPf), isolate](auto *ws) {
|
||||
HandleScope hs(isolate);
|
||||
|
||||
};
|
||||
PerSocketData *perSocketData = (PerSocketData *) ws->getUserData();
|
||||
Local<Value> argv[1] = {Local<Object>::New(isolate, *(perSocketData->socketPf))};
|
||||
CallJS(isolate, Local<Function>::New(isolate, pongPf), 1, argv);
|
||||
};
|
||||
}
|
||||
|
||||
/* Close handler is NOT optional for the wrapper */
|
||||
behavior.close = [closePf = std::move(closePf), isolate](auto *ws, int code, std::string_view message) {
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 588d234d45064fc70c0b6871383cbed2b6ff9d20
|
||||
Subproject commit 591518b2d0749165e6c5a3aca55ee1d1c0454bdc
|
Loading…
Reference in New Issue
Block a user