##// END OF EJS Templates
Support specifying requirejs modules for comm targets
Thomas Kluyver -
Show More
@@ -65,20 +65,40 b' define(['
65 65
66 66 CommManager.prototype.comm_open = function (msg) {
67 67 var content = msg.content;
68 var that = this;
69
70 var instantiate_comm = function(target) {
71 var comm = new Comm(content.target_name, content.comm_id);
72 that.register_comm(comm);
73 try {
74 target(comm, msg);
75 } catch (e) {
76 console.log("Exception opening new comm:", e, e.stack, msg);
77 comm.close();
78 that.unregister_comm(comm);
79 }
80 };
81
82 if (content.target_module) {
83 // Load requirejs module for comm target
84 require([content.target_module], function(mod) {
85 var target = mod[content.target_name];
86 if (target !== undefined) {
87 instantiate_comm(target)
88 } else {
89 console.log("Comm target " + content.target_name +
90 " not found in module " + content.target_module);
91 }
92 }, function(err) { console.log(err); });
93 } else {
94 // No requirejs module specified: look for target in registry
68 95 var f = this.targets[content.target_name];
69 96 if (f === undefined) {
70 97 console.log("No such target registered: ", content.target_name);
71 98 console.log("Available targets are: ", this.targets);
72 99 return;
73 100 }
74 var comm = new Comm(content.target_name, content.comm_id);
75 this.register_comm(comm);
76 try {
77 f(comm, msg);
78 } catch (e) {
79 console.log("Exception opening new comm:", e, e.stack, msg);
80 comm.close();
81 this.unregister_comm(comm);
101 instantiate_comm(f)
82 102 }
83 103 };
84 104
@@ -31,6 +31,8 b' class Comm(LoggingConfigurable):'
31 31 return self.kernel.session
32 32
33 33 target_name = Unicode('comm')
34 target_module = Unicode(None, allow_none=True, help="""requirejs module from
35 which to load comm target.""")
34 36
35 37 topic = Bytes()
36 38 def _topic_default(self):
@@ -91,7 +93,9 b' class Comm(LoggingConfigurable):'
91 93 try:
92 94 self._publish_msg('comm_open',
93 95 data=data, metadata=metadata, buffers=buffers,
94 target_name=self.target_name)
96 target_name=self.target_name,
97 target_module=self.target_module,
98 )
95 99 self._closed = False
96 100 except:
97 101 comm_manager.unregister_comm(self)
General Comments 0
You need to be logged in to leave comments. Login now