Begin WebSocketWrapper nice struct
This commit is contained in:
parent
a6b897cdbc
commit
31e7463c9b
|
@ -66,7 +66,7 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
|||
HandleScope hs(isolate);
|
||||
|
||||
/* Create a new websocket object */
|
||||
Local<Object> wsObject = getWsInstance<APP>();
|
||||
Local<Object> wsObject = WebSocketWrapper::getWsInstance<APP>();
|
||||
wsObject->SetAlignedPointerInInternalField(0, ws);
|
||||
|
||||
/* Attach a new V8 object with pointer to us, to us */
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
// ws.getBufferedAmount()
|
||||
// ws.close(lalala)
|
||||
// ws.?
|
||||
|
||||
/* Helping QtCreator */
|
||||
#include "App.h"
|
||||
#include <v8.h>
|
||||
#include "Utilities.h"
|
||||
using namespace v8;
|
||||
|
||||
// also wrap all of this in some common struct
|
||||
Persistent<Object> wsTemplate[2];
|
||||
struct WebSocketWrapper {
|
||||
static Persistent<Object> wsTemplate[2];
|
||||
|
||||
/* WebSocket send */
|
||||
// ws.getBufferedAmount()
|
||||
// ws.close(lalala)
|
||||
// ws.?
|
||||
|
||||
template <bool SSL>
|
||||
void uWS_WebSocket_send(const FunctionCallbackInfo<Value> &args) {
|
||||
template <bool SSL>
|
||||
static void uWS_WebSocket_send(const FunctionCallbackInfo<Value> &args) {
|
||||
NativeString nativeString(args.GetIsolate(), args[0]);
|
||||
|
||||
bool isBinary = args[1]->Int32Value();
|
||||
|
@ -24,10 +21,10 @@ void uWS_WebSocket_send(const FunctionCallbackInfo<Value> &args) {
|
|||
);
|
||||
|
||||
args.GetReturnValue().Set(Boolean::New(isolate, ok));
|
||||
}
|
||||
}
|
||||
|
||||
template <bool SSL>
|
||||
void initWsTemplate() {
|
||||
template <bool SSL>
|
||||
static void initWsTemplate() {
|
||||
Local<FunctionTemplate> wsTemplateLocal = FunctionTemplate::New(isolate);
|
||||
if (SSL) {
|
||||
wsTemplateLocal->SetClassName(String::NewFromUtf8(isolate, "uWS.SSLWebSocket"));
|
||||
|
@ -39,9 +36,12 @@ void initWsTemplate() {
|
|||
|
||||
Local<Object> wsObjectLocal = wsTemplateLocal->GetFunction()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
||||
wsTemplate[SSL].Reset(isolate, wsObjectLocal);
|
||||
}
|
||||
}
|
||||
|
||||
template <class APP>
|
||||
Local<Object> getWsInstance() {
|
||||
template <class APP>
|
||||
static Local<Object> getWsInstance() {
|
||||
return Local<Object>::New(isolate, wsTemplate[std::is_same<APP, uWS::SSLApp>::value])->Clone();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Persistent<Object> WebSocketWrapper::wsTemplate[2];
|
||||
|
|
|
@ -76,8 +76,8 @@ void Main(Local<Object> exports) {
|
|||
// these inits should probably happen elsewhere (in their respective struct's constructor)?
|
||||
|
||||
/* The template for websockets */
|
||||
initWsTemplate<0>();
|
||||
initWsTemplate<1>();
|
||||
WebSocketWrapper::initWsTemplate<0>();
|
||||
WebSocketWrapper::initWsTemplate<1>();
|
||||
|
||||
/* Initialize SSL and non-SSL templates */
|
||||
initResTemplate<0>();
|
||||
|
|
Loading…
Reference in New Issue