Add getRemoteAddress to res and ws objects
This commit is contained in:
parent
a43675c197
commit
b4ca0a487b
@ -78,6 +78,18 @@ struct HttpResponseWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Takes nothing, returns arraybuffer */
|
||||||
|
template <bool SSL>
|
||||||
|
static void res_getRemoteAddress(const FunctionCallbackInfo<Value> &args) {
|
||||||
|
auto *res = getHttpResponse<SSL>(args);
|
||||||
|
if (res) {
|
||||||
|
std::string_view ip = res->getRemoteAddress();
|
||||||
|
|
||||||
|
/* Todo: we need to pass a copy here */
|
||||||
|
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns the current write offset */
|
/* Returns the current write offset */
|
||||||
template <bool SSL>
|
template <bool SSL>
|
||||||
static void res_getWriteOffset(const FunctionCallbackInfo<Value> &args) {
|
static void res_getWriteOffset(const FunctionCallbackInfo<Value> &args) {
|
||||||
@ -224,6 +236,7 @@ struct HttpResponseWrapper {
|
|||||||
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onWritable"), FunctionTemplate::New(isolate, res_onWritable<SSL>));
|
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onWritable"), FunctionTemplate::New(isolate, res_onWritable<SSL>));
|
||||||
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onAborted"), FunctionTemplate::New(isolate, res_onAborted<SSL>));
|
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onAborted"), FunctionTemplate::New(isolate, res_onAborted<SSL>));
|
||||||
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onData"), FunctionTemplate::New(isolate, res_onData<SSL>));
|
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "onData"), FunctionTemplate::New(isolate, res_onData<SSL>));
|
||||||
|
resTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddress"), FunctionTemplate::New(isolate, res_getRemoteAddress<SSL>));
|
||||||
|
|
||||||
/* Create our template */
|
/* Create our template */
|
||||||
Local<Object> resObjectLocal = resTemplateLocal->GetFunction()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
Local<Object> resObjectLocal = resTemplateLocal->GetFunction()->NewInstance(isolate->GetCurrentContext()).ToLocalChecked();
|
||||||
|
@ -75,6 +75,18 @@ struct WebSocketWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Takes nothing returns arraybuffer */
|
||||||
|
template <bool SSL>
|
||||||
|
static void uWS_WebSocket_getRemoteAddress(const FunctionCallbackInfo<Value> &args) {
|
||||||
|
auto *ws = getWebSocket<SSL>(args);
|
||||||
|
if (ws) {
|
||||||
|
std::string_view ip = ws->getRemoteAddress();
|
||||||
|
|
||||||
|
/* Todo: we need to pass a copy here */
|
||||||
|
args.GetReturnValue().Set(ArrayBuffer::New(isolate, (void *) ip.data(), ip.length()/*, ArrayBufferCreationMode::kInternalized*/));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Takes nothing, returns integer */
|
/* Takes nothing, returns integer */
|
||||||
template <bool SSL>
|
template <bool SSL>
|
||||||
static void uWS_WebSocket_getBufferedAmount(const FunctionCallbackInfo<Value> &args) {
|
static void uWS_WebSocket_getBufferedAmount(const FunctionCallbackInfo<Value> &args) {
|
||||||
@ -116,6 +128,7 @@ struct WebSocketWrapper {
|
|||||||
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "end"), FunctionTemplate::New(isolate, uWS_WebSocket_end<SSL>));
|
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "end"), FunctionTemplate::New(isolate, uWS_WebSocket_end<SSL>));
|
||||||
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "close"), FunctionTemplate::New(isolate, uWS_WebSocket_close<SSL>));
|
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "close"), FunctionTemplate::New(isolate, uWS_WebSocket_close<SSL>));
|
||||||
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getBufferedAmount"), FunctionTemplate::New(isolate, uWS_WebSocket_getBufferedAmount<SSL>));
|
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getBufferedAmount"), FunctionTemplate::New(isolate, uWS_WebSocket_getBufferedAmount<SSL>));
|
||||||
|
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "getRemoteAddress"), FunctionTemplate::New(isolate, uWS_WebSocket_getRemoteAddress<SSL>));
|
||||||
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "subscribe"), FunctionTemplate::New(isolate, uWS_WebSocket_subscribe<SSL>));
|
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "subscribe"), FunctionTemplate::New(isolate, uWS_WebSocket_subscribe<SSL>));
|
||||||
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "publish"), FunctionTemplate::New(isolate, uWS_WebSocket_publish<SSL>));
|
wsTemplateLocal->PrototypeTemplate()->Set(String::NewFromUtf8(isolate, "publish"), FunctionTemplate::New(isolate, uWS_WebSocket_publish<SSL>));
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 35e6bad33b20c3e630e53b16c16546d2572bccfa
|
Subproject commit 495ccfc07602385c039a9edc9978167d9fb122ae
|
Loading…
x
Reference in New Issue
Block a user