Add getRemoteAddress to res and ws objects
This commit is contained in:
parent
a43675c197
commit
b4ca0a487b
3 changed files with 27 additions and 1 deletions
|
@ -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 */
|
||||
template <bool SSL>
|
||||
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, "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, "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, "publish"), FunctionTemplate::New(isolate, uWS_WebSocket_publish<SSL>));
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue