Closed rgbkrk closed 9 years ago
That's great! Would it help if I move the jp
module into its own npm
package?
Here are my thoughts about the pull request.
lib/index.js
. Wouldn't it be enough to require ./lib/jp.js
directly from index.js
?jupyter
globally. I think the decision should be left to the importer:
var jupyter = require("ijavascript");
to import locallyjupyter = require("ijavascript");
to import globallyWhat I ended up doing last night was
var Message = require('ijavascript/lib/jp.js');
I'm extremely new to packaging node application, so I'm willing to change this to any way you like it.
Updated it to only export jp.js.
After some more thought, this is where I stand:
jp
in their codesm
to provide access to node.js sessions.sm
as its own npm
packagesm
and jp
may have different interests, it makes more sense that IJavascript, sm
and jp
are distributed independentlyFor those reasons, I've decided to move jp
into its own npm
package. I've renamed the module as jmp
(Jupyter Messaging Protocol), because the jp
is already taken. I've also changed the way to import class Message
(so that I can export other symbols in the future).
To use the new package, you can replace:
var Message = require('ijavascript/lib/jp.js');
with:
var Message = require('jmp').Message;
Please, let me know if this change wouldn't work for you.
Totally works for me!
I'm likely duplicating code that could be propagating converted messages, perhaps we can build up some other tooling that submits Message events?
/**
* @class Snupyter
* @classdesc Snoops on messages from a Jupyter kernel
* @param {Object} connectionJSON Connection information provided by Jupyter
*/
function Snupyter(connectionJSON) {
/**
* Connection information provided by Jupyter
* @member {Object}
*/
this.connectionJSON = connectionJSON;
/** IOPub socket
* @member {module:zmq~Socket}
*/
this.iopubSocket = zmq.socket("sub");
this.iopubURL = formConnectionString(this.connectionJSON, "iopub");
console.log('Connecting to ' + this.iopubURL);
this.iopubSocket.connect(this.iopubURL);
this.iopubSocket.subscribe('');
this.iopubSocket.on("message", onIOPubMessage.bind(this));
function onIOPubMessage() {
var msg = new Message(
arguments,
this.connectionJSON.signature_scheme.slice("hmac-".length),
this.connectionJSON.key
);
console.dir(msg);
}
}
var snupyter = new Snupyter(config);
I'm doing this to create an Electron app that can display outputs from Jupyter kernels, starting with an HTML side car to a console:
I'm likely duplicating code that could be propagating converted messages,
I don't understand
perhaps we can build up some other tooling that submits Message events?
sorry I don't understand this either (:() Could you give me an example?
I'm going offline now. It's likely I won't be able to come back to you until tomorrow.
Hey, that's ok. In particular, I'm thinking we could use a generic message handler to pass a message on to a callback or a stream:
function onMessage() {
var msg = new Message(
arguments,
this.connectionJSON.signature_scheme.slice("hmac-".length),
this.connectionJSON.key
);
// pass msg on somehow
}
This is what I came up over my tube journey:
Socket
that inherits from ZMQ's Socket (and thus, it can be used where a ZMQ socket is used). It wraps all the listeners of "message" events so that they receive an instance of Message
./**
* @class Snupyter
* @classdesc Snoops on messages from a Jupyter kernel
* @param {Object} connectionJSON Connection information provided by Jupyter
*/
function Snupyter(connectionJSON) {
/**
* Connection information provided by Jupyter
* @member {Object}
*/
this.connectionJSON = connectionJSON;
/** IOPub socket
* @member {module:jmp~Socket}
*/
this.iopubSocket = new jmp.Socket(
"sub",
this.connectionJSON.signature_scheme.slice("hmac-".length),
this.connectionJSON.key
);
this.iopubURL = formConnectionString(this.connectionJSON, "iopub");
console.log('Connecting to ' + this.iopubURL);
this.iopubSocket.connect(this.iopubURL);
this.iopubSocket.subscribe('');
this.iopubSocket.on("message", onIOPubMessage.bind(this));
function onIOPubMessage(msg) {
console.dir(msg);
}
}
var snupyter = new Snupyter(config);
Beautiful @n-riesco! That's just what I was hoping for. Thank you.
:) Thanks.
I've only tested that message listeners can be added, get the messages and can be removed. At some point in the nearish future, I will add some proper tests.
I'm hoping to use a common code base for the Jupyter messaging protocol, in my case for some alternative front end bits.
This sets up Message to be exported from jp.js (since that's all that comes out). I'm open to having more exposed but this is all I needed at the moment.