diff --git a/api/zyre_event.xml b/api/zyre_event.xml
index 1781148e3..aa9accef9 100644
--- a/api/zyre_event.xml
+++ b/api/zyre_event.xml
@@ -38,17 +38,17 @@
-
- Return the sending peer's id as a string
+
+ Return the sending peer's uuid as a string
-
+
Return the sending peer's public name as a string
-
+
Return the sending peer's ipaddress as a string
@@ -71,7 +71,7 @@
- Returns the incoming message payload (currently one frame)
+ Returns the incoming message payload
diff --git a/bindings/nodejs/binding.cc b/bindings/nodejs/binding.cc
index 53cfb6afe..9f855b6ad 100644
--- a/bindings/nodejs/binding.cc
+++ b/bindings/nodejs/binding.cc
@@ -2,6 +2,7 @@
#include "nan.h"
using namespace v8;
+using namespace Nan;
class Zyre: public Nan::ObjectWrap {
public:
@@ -15,6 +16,7 @@ class Zyre: public Nan::ObjectWrap {
// Prototypes
Nan::SetPrototypeMethod (tpl, "destroy", destroy);
+ Nan::SetPrototypeMethod (tpl, "defined", defined);
Nan::SetPrototypeMethod (tpl, "uuid", uuid);
Nan::SetPrototypeMethod (tpl, "name", name);
Nan::SetPrototypeMethod (tpl, "start", start);
@@ -24,8 +26,8 @@ class Zyre: public Nan::ObjectWrap {
Nan::SetPrototypeMethod (tpl, "join", join);
Nan::SetPrototypeMethod (tpl, "leave", leave);
Nan::SetPrototypeMethod (tpl, "print", print);
- Nan::SetPrototypeMethod (tpl, "whispers", whispers);
- Nan::SetPrototypeMethod (tpl, "shouts", shouts);
+ Nan::SetPrototypeMethod (tpl, "whisper", whisper);
+ Nan::SetPrototypeMethod (tpl, "shout", shout);
Nan::SetPrototypeMethod (tpl, "recv", recv);
constructor ().Reset (Nan::GetFunction (tpl).ToLocalChecked ());
@@ -35,61 +37,68 @@ class Zyre: public Nan::ObjectWrap {
private:
explicit Zyre (char *name = NULL) {
self = zyre_new (name);
- assert (self);
}
~Zyre () {
}
static NAN_METHOD (New) {
assert (info.IsConstructCall ());
- Zyre *obj;
+ Zyre *zyre;
if (info [0]->IsString ()) {
Nan::Utf8String name (info [0].As());
- obj = new Zyre (*name);
+ zyre = new Zyre (*name);
}
else
- obj = new Zyre ();
- obj->Wrap (info.This ());
- info.GetReturnValue ().Set (info.This ());
+ zyre = new Zyre ();
+
+ if (zyre) {
+ zyre->Wrap (info.This ());
+ info.GetReturnValue ().Set (info.This ());
+ }
}
static NAN_METHOD (destroy) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
- zyre_destroy (&obj->self);
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
+ zyre_destroy (&zyre->self);
+ }
+
+ static NAN_METHOD (defined) {
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
+ info.GetReturnValue ().Set (Nan::New (zyre->self != NULL));
}
static NAN_METHOD (uuid) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
- info.GetReturnValue ().Set (Nan::New (zyre_uuid (obj->self)).ToLocalChecked ());
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
+ info.GetReturnValue ().Set (Nan::New (zyre_uuid (zyre->self)).ToLocalChecked ());
}
static NAN_METHOD (name) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
- info.GetReturnValue ().Set (Nan::New (zyre_name (obj->self)).ToLocalChecked ());
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
+ info.GetReturnValue ().Set (Nan::New (zyre_name (zyre->self)).ToLocalChecked ());
}
static NAN_METHOD (start) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
- zyre_start (obj->self);
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
+ zyre_start (zyre->self);
}
static NAN_METHOD (stop) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
- zyre_stop (obj->self);
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
+ zyre_stop (zyre->self);
}
static NAN_METHOD (set_verbose) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
- zyre_set_verbose (obj->self);
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
+ zyre_set_verbose (zyre->self);
}
static NAN_METHOD (set_header) {
if (info [0]->IsString ()
&& info [1]->IsString ()) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
Nan::Utf8String name (info [0].As());
Nan::Utf8String value (info [0].As());
- zyre_set_header (obj->self, *name, "%s", *value);
+ zyre_set_header (zyre->self, *name, "%s", *value);
}
else
return Nan::ThrowTypeError (".set_header() expects name and value as strings");
@@ -97,9 +106,9 @@ class Zyre: public Nan::ObjectWrap {
static NAN_METHOD (join) {
if (info [0]->IsString ()) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
Nan::Utf8String group (info [0].As());
- zyre_join (obj->self, *group);
+ zyre_join (zyre->self, *group);
}
else
return Nan::ThrowTypeError (".join() expects group as string");
@@ -107,41 +116,45 @@ class Zyre: public Nan::ObjectWrap {
static NAN_METHOD (leave) {
if (info [0]->IsString ()) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
Nan::Utf8String group (info [0].As());
- zyre_leave (obj->self, *group);
+ zyre_leave (zyre->self, *group);
}
else
return Nan::ThrowTypeError (".leave() expects group as string");
}
- static NAN_METHOD (whispers) {
+ static NAN_METHOD (whisper) {
if (info [0]->IsString ()
&& info [1]->IsString ()) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
Nan::Utf8String peer (info [0].As());
- Nan::Utf8String message (info [0].As());
- zyre_shouts (obj->self, *peer, "%s", *message);
+ Nan::Utf8String string (info [0].As());
+ zmsg_t *msg = zmsg_new ();
+ zmsg_pushstr (msg, *string);
+ zyre_whisper (zyre->self, *peer, &msg);
}
else
- return Nan::ThrowTypeError (".set_header() expects peer and message as strings");
+ return Nan::ThrowTypeError (".whisper() expects peer and message as strings");
}
- static NAN_METHOD (shouts) {
+ static NAN_METHOD (shout) {
if (info [0]->IsString ()
&& info [1]->IsString ()) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
Nan::Utf8String group (info [0].As());
- Nan::Utf8String message (info [0].As());
- zyre_shouts (obj->self, *group, "%s", *message);
+ Nan::Utf8String string (info [0].As());
+ zmsg_t *msg = zmsg_new ();
+ zmsg_pushstr (msg, *string);
+ zyre_shout (zyre->self, *group, &msg);
}
else
- return Nan::ThrowTypeError (".set_header() expects group and message as strings");
+ return Nan::ThrowTypeError (".shout() expects group and message as strings");
}
static NAN_METHOD (recv) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
- zmsg_t *msg = zyre_recv (obj->self);
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
+ zmsg_t *msg = zyre_recv (zyre->self);
if (msg) {
char *string = zmsg_popstr (msg);
info.GetReturnValue ().Set (Nan::New (string).ToLocalChecked ());
@@ -150,8 +163,8 @@ class Zyre: public Nan::ObjectWrap {
}
static NAN_METHOD (print) {
- Zyre *obj = Nan::ObjectWrap::Unwrap (info.Holder ());
- zyre_print (obj->self);
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info.Holder ());
+ zyre_print (zyre->self);
}
static Nan::Persistent & constructor () {
@@ -160,6 +173,202 @@ class Zyre: public Nan::ObjectWrap {
}
zyre_t *self;
+ public:
+ zyre_t *get_self () {
+ return self;
+ }
};
-NODE_MODULE (zyre, Zyre::Init)
+class ZyreEvent: public Nan::ObjectWrap {
+ public:
+ static NAN_MODULE_INIT (Init) {
+ Nan::HandleScope scope;
+
+ // Prepare constructor template
+ Local tpl = Nan::New (New);
+ tpl->SetClassName (Nan::New ("ZyreEvent").ToLocalChecked ());
+ tpl->InstanceTemplate ()->SetInternalFieldCount (1);
+
+ // Prototypes
+ Nan::SetPrototypeMethod (tpl, "destroy", destroy);
+ Nan::SetPrototypeMethod (tpl, "defined", defined);
+ Nan::SetPrototypeMethod (tpl, "type", type);
+ Nan::SetPrototypeMethod (tpl, "type_name", type_name);
+ Nan::SetPrototypeMethod (tpl, "peer_id", peer_id);
+ Nan::SetPrototypeMethod (tpl, "peer_name", peer_name);
+ Nan::SetPrototypeMethod (tpl, "peer_addr", peer_addr);
+ Nan::SetPrototypeMethod (tpl, "header", header);
+ Nan::SetPrototypeMethod (tpl, "group", group);
+ Nan::SetPrototypeMethod (tpl, "msg", msg);
+ Nan::SetPrototypeMethod (tpl, "print", print);
+
+ constructor ().Reset (Nan::GetFunction (tpl).ToLocalChecked ());
+ Nan::Set (target, Nan::New ("ZyreEvent").ToLocalChecked (),
+ Nan::GetFunction (tpl).ToLocalChecked ());
+ }
+ private:
+ explicit ZyreEvent (Zyre *zyre) {
+ self = zyre_event_new (zyre->get_self ());
+ }
+ ~ZyreEvent () {
+ }
+
+ static NAN_METHOD (New) {
+ assert (info.IsConstructCall ());
+ if (info [0]->IsObject ()) {
+ Zyre *zyre = Nan::ObjectWrap::Unwrap (info [0].As