Wrap maxBackpressure, use sane defaults from uWS
This commit is contained in:
parent
b3f37ad896
commit
cfbcb55b03
|
@ -7,6 +7,7 @@ using namespace v8;
|
||||||
template <typename APP>
|
template <typename APP>
|
||||||
void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
||||||
APP *app = (APP *) args.Holder()->GetAlignedPointerFromInternalField(0);
|
APP *app = (APP *) args.Holder()->GetAlignedPointerFromInternalField(0);
|
||||||
|
/* This one is default constructed with defaults */
|
||||||
typename APP::WebSocketBehavior behavior = {};
|
typename APP::WebSocketBehavior behavior = {};
|
||||||
|
|
||||||
NativeString pattern(args.GetIsolate(), args[0]);
|
NativeString pattern(args.GetIsolate(), args[0]);
|
||||||
|
@ -27,14 +28,29 @@ void uWS_App_ws(const FunctionCallbackInfo<Value> &args) {
|
||||||
if (args.Length() == 2) {
|
if (args.Length() == 2) {
|
||||||
Local<Object> behaviorObject = Local<Object>::Cast(args[1]);
|
Local<Object> behaviorObject = Local<Object>::Cast(args[1]);
|
||||||
|
|
||||||
/* maxPayloadLength */
|
/* maxPayloadLength or default */
|
||||||
behavior.maxPayloadLength = behaviorObject->Get(String::NewFromUtf8(isolate, "maxPayloadLength"))->Int32Value(isolate->GetCurrentContext()).ToChecked();
|
MaybeLocal<Value> maybeMaxPayloadLength = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "maxPayloadLength"));
|
||||||
|
if (!maybeMaxPayloadLength.IsEmpty() && !maybeMaxPayloadLength.ToLocalChecked()->IsUndefined()) {
|
||||||
|
behavior.maxPayloadLength = maybeMaxPayloadLength.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked();
|
||||||
|
}
|
||||||
|
|
||||||
/* idleTimeout */
|
/* idleTimeout or default */
|
||||||
behavior.idleTimeout = behaviorObject->Get(String::NewFromUtf8(isolate, "idleTimeout"))->Int32Value(isolate->GetCurrentContext()).ToChecked();
|
MaybeLocal<Value> maybeIdleTimeout = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "idleTimeout"));
|
||||||
|
if (!maybeIdleTimeout.IsEmpty() && !maybeIdleTimeout.ToLocalChecked()->IsUndefined()) {
|
||||||
|
behavior.idleTimeout = maybeIdleTimeout.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked();
|
||||||
|
}
|
||||||
|
|
||||||
/* Compression, map from 0, 1, 2 to disabled, shared, dedicated. This is actually the enum */
|
/* Compression or default, map from 0, 1, 2 to disabled, shared, dedicated. This is actually the enum */
|
||||||
behavior.compression = (uWS::CompressOptions) behaviorObject->Get(String::NewFromUtf8(isolate, "compression"))->Int32Value(isolate->GetCurrentContext()).ToChecked();
|
MaybeLocal<Value> maybeCompression = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "compression"));
|
||||||
|
if (!maybeCompression.IsEmpty() && !maybeCompression.ToLocalChecked()->IsUndefined()) {
|
||||||
|
behavior.compression = (uWS::CompressOptions) maybeCompression.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* maxBackpressure or default */
|
||||||
|
MaybeLocal<Value> maybeMaxBackpressure = behaviorObject->Get(isolate->GetCurrentContext(), String::NewFromUtf8(isolate, "maxBackpressure"));
|
||||||
|
if (!maybeMaxBackpressure.IsEmpty() && !maybeMaxBackpressure.ToLocalChecked()->IsUndefined()) {
|
||||||
|
behavior.maxBackpressure = maybeMaxBackpressure.ToLocalChecked()->Int32Value(isolate->GetCurrentContext()).ToChecked();
|
||||||
|
}
|
||||||
|
|
||||||
/* Open */
|
/* Open */
|
||||||
openPf.Reset(args.GetIsolate(), Local<Function>::Cast(behaviorObject->Get(String::NewFromUtf8(isolate, "open"))));
|
openPf.Reset(args.GetIsolate(), Local<Function>::Cast(behaviorObject->Get(String::NewFromUtf8(isolate, "open"))));
|
||||||
|
|
Loading…
Reference in New Issue