-
Notifications
You must be signed in to change notification settings - Fork 104
Description
Hi,
I am creating a native module in nodejs (uses libuv event loop)
I am using live555helper live555helper.
The initial intention is to get the buffer from nodejs, however the program stays in the event loop of live555 and not run the callback that I pass to it from nodejs and the api of v8 (not return to javascript).
The program in nodejs is.
'use strict'
const addon = require('./build/Release/eas-rtsp')
addon.getBuffer((err, buffer) => {
if (err) {
console.log(err)
} else {
console.log(buffer.toString('hex'))
}
})
// Code not reached
console.log('continue...')The c ++ addon is:
#include <rtspconnectionclient.h>
using namespace v8;
NAN_METHOD(getBuffer) {
Nan:: HandleScope scope;
Nan::Callback *node_callback = new Nan::Callback(info[0].As<Function>());
class RTSPCallback : public RTSPConnection::Callback
{
public:
virtual bool onData(const char* id, unsigned char* buffer, ssize_t size, struct timeval presentationTime, Nan::Callback* node_callback) {
// std::cout << id << " " << size << " ts:" << presentationTime.tv_sec << "." << presentationTime.tv_usec << std::endl;
v8::Local<v8::Object> node_buffer = Nan::NewBuffer((char *)buffer, size).ToLocalChecked();
v8::Local<v8::Value> argv[] = { node_buffer };
node_callback->Call(1, argv);
return true;
}
};
Environment env;
RTSPCallback cb;
RTSPConnection rtspClient(env, &cb, "rtsp://admin:@192.168.1.38:554/live1.sdp", node_callback);
env.mainloop();
}
NAN_MODULE_INIT(Initialize) {
NAN_EXPORT(target, getBuffer);
}
NODE_MODULE(addon, Initialize);- get Callback from node.
Nan::Callback *node_callback = new Nan::Callback(info[0].As<Function>());-
overwrite onData of live555helper.
-
The live555 event loop starts.
env.mainloop();
The code eas-rtsp commit bb08a5e
The node program does not continue.
-
Should I add the live555 event loop in another thread?
-
How do I add an event type to the live555 event loop so that from the event loop of nodejs
I will be able to read the buffer. -
Maybe use EventEmitter but I don't know.
What do you think?. It is posible?
Your opinion is very important to me.
Thank you!!!
Regards,