##// END OF EJS Templates
pass whole message to Comm handlers
MinRK -
Show More
@@ -70,7 +70,7 b' var IPython = (function (IPython) {'
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 callback(comm);
72 callback(comm);
73 comm.handle_open(content.data);
73 comm.handle_open(msg);
74 };
74 };
75
75
76 CommManager.prototype.comm_close = function (msg) {
76 CommManager.prototype.comm_close = function (msg) {
@@ -80,7 +80,7 b' var IPython = (function (IPython) {'
80 return;
80 return;
81 }
81 }
82 delete this.comms[content.comm_id];
82 delete this.comms[content.comm_id];
83 comm.handle_close(content.data);
83 comm.handle_close(msg);
84 };
84 };
85
85
86 CommManager.prototype.comm_msg = function (msg) {
86 CommManager.prototype.comm_msg = function (msg) {
@@ -89,16 +89,16 b' var IPython = (function (IPython) {'
89 if (comm === undefined) {
89 if (comm === undefined) {
90 return;
90 return;
91 }
91 }
92 comm.handle_msg(content.data);
92 comm.handle_msg(msg);
93 };
93 };
94
94
95 //-----------------------------------------------------------------------
95 //-----------------------------------------------------------------------
96 // Comm base class
96 // Comm base class
97 //-----------------------------------------------------------------------
97 //-----------------------------------------------------------------------
98
98
99 var Comm = function (comm_id) {
99 var Comm = function (comm_id, target) {
100 this.comm_id = comm_id;
100 this.comm_id = comm_id;
101 this.target = 'comm';
101 this.target = target || 'comm';
102 };
102 };
103
103
104 // methods for sending messages
104 // methods for sending messages
@@ -129,16 +129,16 b' var IPython = (function (IPython) {'
129
129
130 // methods for handling incoming messages
130 // methods for handling incoming messages
131
131
132 Comm.prototype.handle_open = function (data) {
132 Comm.prototype.handle_open = function (msg) {
133 $([this]).trigger("comm_open", data);
133 $([this]).trigger("comm_open", msg);
134 };
134 };
135
135
136 Comm.prototype.handle_msg = function (data) {
136 Comm.prototype.handle_msg = function (msg) {
137 $([this]).trigger("comm_msg", data);
137 $([this]).trigger("comm_msg", msg);
138 };
138 };
139
139
140 Comm.prototype.handle_close = function (data) {
140 Comm.prototype.handle_close = function (msg) {
141 $([this]).trigger("comm_close", data);
141 $([this]).trigger("comm_close", msg);
142 };
142 };
143
143
144 IPython.CommManager = CommManager;
144 IPython.CommManager = CommManager;
@@ -56,15 +56,12 b' class Comm(LoggingConfigurable):'
56
56
57 primary = Bool(True, help="Am I the primary or secondary Comm?")
57 primary = Bool(True, help="Am I the primary or secondary Comm?")
58
58
59 def __init__(self, **kwargs):
59 def __init__(self, data=None, **kwargs):
60 super(Comm, self).__init__(**kwargs)
60 super(Comm, self).__init__(**kwargs)
61 get_ipython().comm_manager.register_comm(self)
61 get_ipython().comm_manager.register_comm(self)
62 if self.primary:
62 if self.primary:
63 # I am primary, open my peer
63 # I am primary, open my peer
64 self.open()
64 self.open(data)
65 else:
66 # I am secondary, handle creation
67 self.handle_open(self._open_data)
68
65
69 def _publish_msg(self, msg_type, data=None, **keys):
66 def _publish_msg(self, msg_type, data=None, **keys):
70 """Helper for sending a comm message on IOPub"""
67 """Helper for sending a comm message on IOPub"""
@@ -97,7 +94,7 b' class Comm(LoggingConfigurable):'
97 self._closed = True
94 self._closed = True
98
95
99 def send(self, data=None):
96 def send(self, data=None):
100 """Update the frontend-side version of this comm"""
97 """Send a message to the frontend-side version of this comm"""
101 self._publish_msg('comm_msg', data)
98 self._publish_msg('comm_msg', data)
102
99
103 # registering callbacks
100 # registering callbacks
@@ -130,23 +127,23 b' class Comm(LoggingConfigurable):'
130
127
131 # handling of incoming messages
128 # handling of incoming messages
132
129
133 def handle_open(self, data):
130 def handle_open(self, msg):
134 """Handle a comm_open message"""
131 """Handle a comm_open message"""
135 self.log.debug("handle_open[%s](%s)", self.comm_id, data)
132 self.log.debug("handle_open[%s](%s)", self.comm_id, msg)
136 if self._open_callback:
133 if self._open_callback:
137 self._open_callback(data)
134 self._open_callback(msg)
138
135
139 def handle_close(self, data):
136 def handle_close(self, msg):
140 """Handle a comm_close message"""
137 """Handle a comm_close message"""
141 self.log.debug("handle_close[%s](%s)", self.comm_id, data)
138 self.log.debug("handle_close[%s](%s)", self.comm_id, msg)
142 if self._close_callback:
139 if self._close_callback:
143 self._close_callback(data)
140 self._close_callback(msg)
144
141
145 def handle_msg(self, data):
142 def handle_msg(self, msg):
146 """Handle a comm_msg message"""
143 """Handle a comm_msg message"""
147 self.log.debug("handle_msg[%s](%s)", self.comm_id, data)
144 self.log.debug("handle_msg[%s](%s)", self.comm_id, msg)
148 if self._msg_callback:
145 if self._msg_callback:
149 self._msg_callback(data)
146 self._msg_callback(msg)
150
147
151
148
152 __all__ = ['Comm']
149 __all__ = ['Comm']
@@ -107,7 +107,6 b' class CommManager(LoggingConfigurable):'
107 comm = Comm(comm_id=comm_id,
107 comm = Comm(comm_id=comm_id,
108 shell=self.shell,
108 shell=self.shell,
109 iopub_socket=self.iopub_socket,
109 iopub_socket=self.iopub_socket,
110 _open_data=content['data'],
111 primary=False,
110 primary=False,
112 )
111 )
113 if callback is None:
112 if callback is None:
@@ -115,6 +114,7 b' class CommManager(LoggingConfigurable):'
115 comm.close()
114 comm.close()
116 return
115 return
117 callback(comm)
116 callback(comm)
117 comm.handle_open(msg)
118 self.register_comm(comm)
118 self.register_comm(comm)
119
119
120 def comm_msg(self, stream, ident, msg):
120 def comm_msg(self, stream, ident, msg):
@@ -125,7 +125,7 b' class CommManager(LoggingConfigurable):'
125 if comm is None:
125 if comm is None:
126 # no such comm
126 # no such comm
127 return
127 return
128 comm.handle_msg(content['data'])
128 comm.handle_msg(msg)
129
129
130 def comm_close(self, stream, ident, msg):
130 def comm_close(self, stream, ident, msg):
131 """Handler for comm_close messages"""
131 """Handler for comm_close messages"""
@@ -135,8 +135,8 b' class CommManager(LoggingConfigurable):'
135 if comm is None:
135 if comm is None:
136 # no such comm
136 # no such comm
137 return
137 return
138 comm.handle_close(content['data'])
139 del self.comms[comm_id]
138 del self.comms[comm_id]
139 comm.handle_close(msg)
140
140
141
141
142 __all__ = ['CommManager']
142 __all__ = ['CommManager']
General Comments 0
You need to be logged in to leave comments. Login now