Show More
@@ -61,16 +61,15 b' var IPython = (function (IPython) {' | |||||
61 |
|
61 | |||
62 | CommManager.prototype.comm_open = function (msg) { |
|
62 | CommManager.prototype.comm_open = function (msg) { | |
63 | var content = msg.content; |
|
63 | var content = msg.content; | |
64 |
var |
|
64 | var f = this.targets[content.target_name]; | |
65 |
if ( |
|
65 | if (f === undefined) { | |
66 | console.log("No such target registered: ", content.target_name); |
|
66 | console.log("No such target registered: ", content.target_name); | |
67 | console.log("Available targets are: ", this.targets); |
|
67 | console.log("Available targets are: ", this.targets); | |
68 | return; |
|
68 | return; | |
69 | } |
|
69 | } | |
70 | var comm = new Comm(content.comm_id); |
|
70 | var comm = new Comm(content.comm_id); | |
71 | this.register_comm(comm); |
|
71 | this.register_comm(comm); | |
72 |
|
|
72 | f(comm, msg); | |
73 | comm.handle_open(msg); |
|
|||
74 | }; |
|
73 | }; | |
75 |
|
74 | |||
76 | CommManager.prototype.comm_close = function (msg) { |
|
75 | CommManager.prototype.comm_close = function (msg) { | |
@@ -99,7 +98,7 b' var IPython = (function (IPython) {' | |||||
99 | var Comm = function (comm_id, target_name) { |
|
98 | var Comm = function (comm_id, target_name) { | |
100 | this.comm_id = comm_id || new IPython.utils.uuid(); |
|
99 | this.comm_id = comm_id || new IPython.utils.uuid(); | |
101 | this.target_name = target_name; |
|
100 | this.target_name = target_name; | |
102 |
this._msg_callback |
|
101 | this._msg_callback = this._close_callback = null; | |
103 | }; |
|
102 | }; | |
104 |
|
103 | |||
105 | // methods for sending messages |
|
104 | // methods for sending messages | |
@@ -133,10 +132,6 b' var IPython = (function (IPython) {' | |||||
133 | this['_' + key + '_callback'] = callback; |
|
132 | this['_' + key + '_callback'] = callback; | |
134 | }; |
|
133 | }; | |
135 |
|
134 | |||
136 | Comm.prototype.on_open = function (callback) { |
|
|||
137 | this._register_callback('open', callback); |
|
|||
138 | }; |
|
|||
139 |
|
||||
140 | Comm.prototype.on_msg = function (callback) { |
|
135 | Comm.prototype.on_msg = function (callback) { | |
141 | this._register_callback('msg', callback); |
|
136 | this._register_callback('msg', callback); | |
142 | }; |
|
137 | }; | |
@@ -152,10 +147,6 b' var IPython = (function (IPython) {' | |||||
152 | if (callback) callback(msg); |
|
147 | if (callback) callback(msg); | |
153 | }; |
|
148 | }; | |
154 |
|
149 | |||
155 | Comm.prototype.handle_open = function (msg) { |
|
|||
156 | this._maybe_callback('open', msg); |
|
|||
157 | }; |
|
|||
158 |
|
||||
159 | Comm.prototype.handle_msg = function (msg) { |
|
150 | Comm.prototype.handle_msg = function (msg) { | |
160 | this._maybe_callback('msg', msg); |
|
151 | this._maybe_callback('msg', msg); | |
161 | }; |
|
152 | }; |
@@ -43,10 +43,9 b' class Comm(LoggingConfigurable):' | |||||
43 | def _topic_default(self): |
|
43 | def _topic_default(self): | |
44 | return ('comm-%s' % self.comm_id).encode('ascii') |
|
44 | return ('comm-%s' % self.comm_id).encode('ascii') | |
45 |
|
45 | |||
46 |
_open_data = Dict(help="data dict, if any, to be included in comm_ |
|
46 | _open_data = Dict(help="data dict, if any, to be included in comm_open") | |
47 | _close_data = Dict(help="data dict, if any, to be included in comm_close") |
|
47 | _close_data = Dict(help="data dict, if any, to be included in comm_close") | |
48 |
|
48 | |||
49 | _open_callback = Any() |
|
|||
50 | _msg_callback = Any() |
|
49 | _msg_callback = Any() | |
51 | _close_callback = Any() |
|
50 | _close_callback = Any() | |
52 |
|
51 | |||
@@ -61,7 +60,7 b' class Comm(LoggingConfigurable):' | |||||
61 | super(Comm, self).__init__(**kwargs) |
|
60 | super(Comm, self).__init__(**kwargs) | |
62 | get_ipython().comm_manager.register_comm(self) |
|
61 | get_ipython().comm_manager.register_comm(self) | |
63 | if self.primary: |
|
62 | if self.primary: | |
64 | # I am primary, open my peer |
|
63 | # I am primary, open my peer. | |
65 | self.open(data) |
|
64 | self.open(data) | |
66 |
|
65 | |||
67 | def _publish_msg(self, msg_type, data=None, **keys): |
|
66 | def _publish_msg(self, msg_type, data=None, **keys): | |
@@ -99,14 +98,6 b' class Comm(LoggingConfigurable):' | |||||
99 | self._publish_msg('comm_msg', data) |
|
98 | self._publish_msg('comm_msg', data) | |
100 |
|
99 | |||
101 | # registering callbacks |
|
100 | # registering callbacks | |
102 | def on_open(self, callback): |
|
|||
103 | """Register a callback for comm_open |
|
|||
104 |
|
||||
105 | Will be called with the `data` of the open message. |
|
|||
106 |
|
||||
107 | Call `on_open(None)` to disable an existing callback. |
|
|||
108 | """ |
|
|||
109 | self._open_callback = callback |
|
|||
110 |
|
101 | |||
111 | def on_close(self, callback): |
|
102 | def on_close(self, callback): | |
112 | """Register a callback for comm_close |
|
103 | """Register a callback for comm_close | |
@@ -128,12 +119,6 b' class Comm(LoggingConfigurable):' | |||||
128 |
|
119 | |||
129 | # handling of incoming messages |
|
120 | # handling of incoming messages | |
130 |
|
121 | |||
131 | def handle_open(self, msg): |
|
|||
132 | """Handle a comm_open message""" |
|
|||
133 | self.log.debug("handle_open[%s](%s)", self.comm_id, msg) |
|
|||
134 | if self._open_callback: |
|
|||
135 | self._open_callback(msg) |
|
|||
136 |
|
||||
137 | def handle_close(self, msg): |
|
122 | def handle_close(self, msg): | |
138 | """Handle a comm_close message""" |
|
123 | """Handle a comm_close message""" | |
139 | self.log.debug("handle_close[%s](%s)", self.comm_id, msg) |
|
124 | self.log.debug("handle_close[%s](%s)", self.comm_id, msg) |
@@ -136,9 +136,8 b' class CommManager(LoggingConfigurable):' | |||||
136 | self.log.error("No such comm target registered: %s", target_name) |
|
136 | self.log.error("No such comm target registered: %s", target_name) | |
137 | comm.close() |
|
137 | comm.close() | |
138 | return |
|
138 | return | |
139 | f(comm) |
|
|||
140 | comm.handle_open(msg) |
|
|||
141 | self.register_comm(comm) |
|
139 | self.register_comm(comm) | |
|
140 | f(comm, msg) | |||
142 |
|
141 | |||
143 | @with_output |
|
142 | @with_output | |
144 | def comm_msg(self, stream, ident, msg): |
|
143 | def comm_msg(self, stream, ident, msg): |
General Comments 0
You need to be logged in to leave comments.
Login now