Wrap isSubscribed, numSubscribers
This commit is contained in:
parent
797286515a
commit
08a54d4ba6
|
@ -358,6 +358,25 @@ void uWS_App_publish(const FunctionCallbackInfo<Value> &args) {
|
|||
app->publish(topic.getString(), message.getString(), args[2]->BooleanValue(isolate) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[3]->BooleanValue(isolate));
|
||||
}
|
||||
|
||||
template <typename APP>
|
||||
void uWS_App_numSubscribers(const FunctionCallbackInfo<Value> &args) {
|
||||
APP *app = (APP *) args.Holder()->GetAlignedPointerFromInternalField(0);
|
||||
|
||||
Isolate *isolate = args.GetIsolate();
|
||||
|
||||
/* topic */
|
||||
if (missingArguments(1, args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
NativeString topic(isolate, args[0]);
|
||||
if (topic.isInvalid(args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
args.GetReturnValue().Set(Integer::New(isolate, app->numSubscribers(topic.getString())));
|
||||
}
|
||||
|
||||
/* This one modified per-thread static strings temporarily */
|
||||
std::pair<uWS::SocketContextOptions, bool> readOptionsObject(const FunctionCallbackInfo<Value> &args, int index) {
|
||||
Isolate *isolate = args.GetIsolate();
|
||||
|
@ -557,6 +576,7 @@ void uWS_App(const FunctionCallbackInfo<Value> &args) {
|
|||
appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "ws", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App_ws<APP>, args.Data()));
|
||||
appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "listen", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App_listen<APP>, args.Data()));
|
||||
appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "publish", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App_publish<APP>, args.Data()));
|
||||
appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "numSubscribers", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App_numSubscribers<APP>, args.Data()));
|
||||
|
||||
/* SNI */
|
||||
appTemplate->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "addServerName", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_App_addServerName<APP>, args.Data()));
|
||||
|
|
|
@ -181,6 +181,23 @@ struct WebSocketWrapper {
|
|||
}
|
||||
}
|
||||
|
||||
/* Takes topic string, returns bool */
|
||||
template <bool SSL>
|
||||
static void uWS_WebSocket_isSubscribed(const FunctionCallbackInfo<Value> &args) {
|
||||
Isolate *isolate = args.GetIsolate();
|
||||
auto *ws = getWebSocket<SSL>(args);
|
||||
if (ws) {
|
||||
NativeString topic(args.GetIsolate(), args[0]);
|
||||
if (topic.isInvalid(args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool subscribed = ws->isSubscribed(topic.getString());
|
||||
|
||||
args.GetReturnValue().Set(Boolean::New(isolate, subscribed));
|
||||
}
|
||||
}
|
||||
|
||||
/* Takes message. Returns true on success, false otherwise */
|
||||
template <bool SSL>
|
||||
static void uWS_WebSocket_ping(const FunctionCallbackInfo<Value> &args) {
|
||||
|
@ -237,6 +254,7 @@ struct WebSocketWrapper {
|
|||
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "cork", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_cork<SSL>));
|
||||
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "ping", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_ping<SSL>));
|
||||
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddressAsText", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_getRemoteAddressAsText<SSL>));
|
||||
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "isSubscribed", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_isSubscribed<SSL>));
|
||||
|
||||
/* Create the template */
|
||||
Local<Object> wsObjectLocal = wsTemplateLocal->GetFunction(isolate->GetCurrentContext()).ToLocalChecked()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 65d1498774af82b201ad15e42a43554a583de147
|
||||
Subproject commit 5df25ffa59b83e2f37b00f4dbb14ca8abdb9bad1
|
Loading…
Reference in New Issue