jupyter-js-services
Advanced tools
Comparing version 0.4.5 to 0.5.0
@@ -186,2 +186,14 @@ import { IDisposable } from 'phosphor-disposable'; | ||
/** | ||
* IOPub comm_open kernel message specification. | ||
* | ||
* See [Comm open](http://jupyter-client.readthedocs.org/en/latest/messaging.html#opening-a-comm). | ||
*/ | ||
export interface IKernelIOPubCommOpenMessage extends IKernelMessage { | ||
content: ICommOpen; | ||
} | ||
/** | ||
* Check if an IKernelMessage is an iopub comm_open message. | ||
*/ | ||
export declare function isCommOpenMessage(msg: IKernelMessage): msg is IKernelIOPubCommOpenMessage; | ||
/** | ||
* Kernel information specification. | ||
@@ -426,6 +438,2 @@ * | ||
/** | ||
* A signal emitted for unhandled comm open message. | ||
*/ | ||
commOpened: ISignal<IKernel, IKernelMessage>; | ||
/** | ||
* The id of the server-side kernel. | ||
@@ -608,2 +616,17 @@ * | ||
/** | ||
* Register a comm target handler. | ||
* | ||
* @param targetName - The name of the comm target. | ||
* | ||
* @param callback - The callback invoked for a comm open message. | ||
* | ||
* @returns A disposable used to unregister the comm target. | ||
* | ||
* #### Notes | ||
* Only one comm target can be registered at a time, an existing | ||
* callback will be overidden. A registered comm target handler will take | ||
* precedence over a comm which specifies a `target_module`. | ||
*/ | ||
registerCommTarget(targetName: string, callback: (comm: IComm, msg: IKernelIOPubCommOpenMessage) => void): IDisposable; | ||
/** | ||
* Optional default settings for ajax requests, if applicable. | ||
@@ -610,0 +633,0 @@ */ |
@@ -54,2 +54,9 @@ // Copyright (c) Jupyter Development Team. | ||
/** | ||
* Check if an IKernelMessage is an iopub comm_open message. | ||
*/ | ||
function isCommOpenMessage(msg) { | ||
return msg.header.msg_type === "comm_open"; | ||
} | ||
exports.isCommOpenMessage = isCommOpenMessage; | ||
/** | ||
* Enumeration of valid Kernel status states. | ||
@@ -56,0 +63,0 @@ */ |
@@ -289,2 +289,3 @@ // Copyright (c) Jupyter Development Team. | ||
this._isWebSocketClosing = false; | ||
this._targetRegistry = Object.create(null); | ||
this.ajaxSettings = options.ajaxSettings || {}; | ||
@@ -322,12 +323,2 @@ this._name = options.name; | ||
}); | ||
Object.defineProperty(Kernel.prototype, "commOpened", { | ||
/** | ||
* A signal emitted for unhandled comm open message. | ||
*/ | ||
get: function () { | ||
return KernelPrivate.commOpenedSignal.bind(this); | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
Object.defineProperty(Kernel.prototype, "id", { | ||
@@ -441,3 +432,4 @@ /** | ||
this._ws = null; | ||
this._status === ikernel_1.KernelStatus.Dead; | ||
this._status = ikernel_1.KernelStatus.Dead; | ||
this._targetRegistry = null; | ||
phosphor_signaling_1.clearSignalData(this); | ||
@@ -711,2 +703,23 @@ runningKernels.delete(this._id); | ||
/** | ||
* Register a comm target handler. | ||
* | ||
* @param targetName - The name of the comm target. | ||
* | ||
* @param callback - The callback invoked for a comm open message. | ||
* | ||
* @returns A disposable used to unregister the comm target. | ||
* | ||
* #### Notes | ||
* Only one comm target can be registered at a time, an existing | ||
* callback will be overidden. A registered comm target handler will take | ||
* precedence over a comm which specifies a `target_module`. | ||
*/ | ||
Kernel.prototype.registerCommTarget = function (targetName, callback) { | ||
var _this = this; | ||
this._targetRegistry[targetName] = callback; | ||
return new phosphor_disposable_1.DisposableDelegate(function () { | ||
delete _this._targetRegistry[targetName]; | ||
}); | ||
}; | ||
/** | ||
* Connect to a comm, or create a new one. | ||
@@ -880,29 +893,16 @@ * | ||
var content = msg.content; | ||
if (!content.target_module) { | ||
this.commOpened.emit(msg); | ||
return; | ||
} | ||
var targetName = content.target_name; | ||
var moduleName = content.target_module; | ||
var promise = new Promise(function (resolve, reject) { | ||
// Try loading the module using require.js | ||
requirejs([moduleName], function (mod) { | ||
if (mod[targetName] === undefined) { | ||
reject(new Error('Target ' + targetName + ' not found in module ' + moduleName)); | ||
} | ||
var target = mod[targetName]; | ||
var comm = new Comm(content.target_name, content.comm_id, _this._sendCommMessage, function () { _this._unregisterComm(content.comm_id); }); | ||
try { | ||
var response = target(comm, msg); | ||
} | ||
catch (e) { | ||
comm.close(); | ||
_this._unregisterComm(comm.commId); | ||
console.error("Exception opening new comm"); | ||
reject(e); | ||
} | ||
_this._commPromises.delete(comm.commId); | ||
_this._comms.set(comm.commId, comm); | ||
resolve(comm); | ||
}); | ||
var promise = utils.loadClass(content.target_name, content.target_module, this._targetRegistry).then(function (target) { | ||
var comm = new Comm(content.target_name, content.comm_id, _this._sendCommMessage.bind(_this), function () { _this._unregisterComm(content.comm_id); }); | ||
try { | ||
var response = target(comm, msg); | ||
} | ||
catch (e) { | ||
comm.close(); | ||
console.error("Exception opening new comm"); | ||
throw (e); | ||
} | ||
_this._commPromises.delete(comm.commId); | ||
_this._comms.set(comm.commId, comm); | ||
return comm; | ||
}); | ||
@@ -1019,8 +1019,2 @@ this._commPromises.set(content.comm_id, promise); | ||
KernelPrivate.unhandledMessageSignal = new phosphor_signaling_1.Signal(); | ||
/** | ||
* A signal emitted for unhandled comm open message. | ||
* | ||
* **See also:** [[commOpened]] | ||
*/ | ||
KernelPrivate.commOpenedSignal = new phosphor_signaling_1.Signal(); | ||
})(KernelPrivate || (KernelPrivate = {})); | ||
@@ -1027,0 +1021,0 @@ /** |
{ | ||
"name": "jupyter-js-services", | ||
"version": "0.4.5", | ||
"version": "0.5.0", | ||
"description": "Client APIs for the Jupyter services REST APIs", | ||
@@ -8,3 +8,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"jupyter-js-utils": "^0.2.7", | ||
"jupyter-js-utils": "^0.2.12", | ||
"phosphor-disposable": "^1.0.5", | ||
@@ -34,2 +34,3 @@ "phosphor-signaling": "^1.2.0" | ||
"test:integration": "cd test && python integration_test.py", | ||
"test:debug": "mocha test/build/index.js --debug-brk", | ||
"test": "mocha test/build/index.js" | ||
@@ -36,0 +37,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
167700
4794
Updatedjupyter-js-utils@^0.2.12