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