// ws.getBufferedAmount() // ws.close(lalala) // ws.? /* Helping QtCreator */ #include "App.h" #include #include "Utilities.h" using namespace v8; // also wrap all of this in some common struct Persistent wsTemplate[2]; /* WebSocket send */ template void uWS_WebSocket_send(const FunctionCallbackInfo &args) { NativeString nativeString(args.GetIsolate(), args[0]); bool isBinary = args[1]->Int32Value(); bool ok = ((uWS::WebSocket *) args.Holder()->GetAlignedPointerFromInternalField(0))->send( std::string_view(nativeString.getData(), nativeString.getLength()), isBinary ? uWS::OpCode::BINARY : uWS::OpCode::TEXT ); args.GetReturnValue().Set(Boolean::New(isolate, ok)); } template void initWsTemplate() { Local wsTemplateLocal = FunctionTemplate::New(isolate); if (SSL) { wsTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.SSLWebSocket")); } else { wsTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.WebSocket")); } wsTemplateLocal->InstanceTemplate()->SetInternalFieldCount(1); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "send"), FunctionTemplate::New(isolate, uWS_WebSocket_send)); Local wsObjectLocal = wsTemplateLocal->GetFunction()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked(); wsTemplate[SSL].Reset(isolate, wsObjectLocal); } template Local getWsInstance() { return Local::New(isolate, wsTemplate[std::is_same::value])->Clone(); }