diff --git a/src/WebSocketWrapper.h b/src/WebSocketWrapper.h index b42c929..993b1e1 100644 --- a/src/WebSocketWrapper.h +++ b/src/WebSocketWrapper.h @@ -163,6 +163,57 @@ struct WebSocketWrapper { } } + /* Takes message, isBinary, compressed. Returns true on success, false otherwise */ + template + static void uWS_WebSocket_sendFirstFragment(const FunctionCallbackInfo &args) { + Isolate *isolate = args.GetIsolate(); + auto *ws = getWebSocket(args); + if (ws) { + NativeString message(args.GetIsolate(), args[0]); + if (message.isInvalid(args)) { + return; + } + + bool ok = ws->sendFirstFragment(message.getString(), args[1]->BooleanValue(isolate) ? uWS::OpCode::BINARY : uWS::OpCode::TEXT, args[2]->BooleanValue(isolate)); + + args.GetReturnValue().Set(Boolean::New(isolate, ok)); + } + } + + /* Takes message, compressed. Returns true on success, false otherwise */ + template + static void uWS_WebSocket_sendFragment(const FunctionCallbackInfo &args) { + Isolate *isolate = args.GetIsolate(); + auto *ws = getWebSocket(args); + if (ws) { + NativeString message(args.GetIsolate(), args[0]); + if (message.isInvalid(args)) { + return; + } + + bool ok = ws->sendFragment(message.getString(), args[1]->BooleanValue(isolate)); + + args.GetReturnValue().Set(Boolean::New(isolate, ok)); + } + } + + /* Takes message, compressed. Returns true on success, false otherwise */ + template + static void uWS_WebSocket_sendLastFragment(const FunctionCallbackInfo &args) { + Isolate *isolate = args.GetIsolate(); + auto *ws = getWebSocket(args); + if (ws) { + NativeString message(args.GetIsolate(), args[0]); + if (message.isInvalid(args)) { + return; + } + + bool ok = ws->sendLastFragment(message.getString(), args[1]->BooleanValue(isolate)); + + args.GetReturnValue().Set(Boolean::New(isolate, ok)); + } + } + /* Takes message, isBinary, compressed. Returns true on success, false otherwise */ template static void uWS_WebSocket_send(const FunctionCallbackInfo &args) { @@ -261,6 +312,10 @@ struct WebSocketWrapper { wsTemplateLocal->InstanceTemplate()->SetInternalFieldCount(1); /* Register our functions */ + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "sendFirstFragment", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_sendFirstFragment)); + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "sendFragment", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_sendFragment)); + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "sendLastFragment", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_sendLastFragment)); + wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "send", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_send)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "end", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_end)); wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "close", NewStringType::kNormal).ToLocalChecked(), FunctionTemplate::New(isolate, uWS_WebSocket_close)); diff --git a/uWebSockets b/uWebSockets index 80cd187..1dd372d 160000 --- a/uWebSockets +++ b/uWebSockets @@ -1 +1 @@ -Subproject commit 80cd18781b34cb7012ae52640d9ccbf0e8e8bb6c +Subproject commit 1dd372d6ace4a709e76cc27096a08c8da09858aa