##// END OF EJS Templates
trigger `Kernel.status_started` after websockets open...
MinRK -
Show More
@@ -119,7 +119,6 b' var IPython = (function (IPython) {'
119 this.ws_url = ws_url;
119 this.ws_url = ws_url;
120 this.kernel_url = this.base_url + "/" + this.kernel_id;
120 this.kernel_url = this.base_url + "/" + this.kernel_id;
121 this.start_channels();
121 this.start_channels();
122 $([IPython.events]).trigger('status_started.Kernel', {kernel: this});
123 };
122 };
124
123
125
124
@@ -144,11 +143,7 b' var IPython = (function (IPython) {'
144 this.shell_channel = new this.WebSocket(ws_url + "/shell");
143 this.shell_channel = new this.WebSocket(ws_url + "/shell");
145 this.stdin_channel = new this.WebSocket(ws_url + "/stdin");
144 this.stdin_channel = new this.WebSocket(ws_url + "/stdin");
146 this.iopub_channel = new this.WebSocket(ws_url + "/iopub");
145 this.iopub_channel = new this.WebSocket(ws_url + "/iopub");
147 send_cookie = function(){
146
148 // send the session id so the Session object Python-side
149 // has the same identity
150 this.send(that.session_id + ':' + document.cookie);
151 };
152 var already_called_onclose = false; // only alert once
147 var already_called_onclose = false; // only alert once
153 var ws_closed_early = function(evt){
148 var ws_closed_early = function(evt){
154 if (already_called_onclose){
149 if (already_called_onclose){
@@ -170,7 +165,7 b' var IPython = (function (IPython) {'
170 };
165 };
171 var channels = [this.shell_channel, this.iopub_channel, this.stdin_channel];
166 var channels = [this.shell_channel, this.iopub_channel, this.stdin_channel];
172 for (var i=0; i < channels.length; i++) {
167 for (var i=0; i < channels.length; i++) {
173 channels[i].onopen = send_cookie;
168 channels[i].onopen = $.proxy(this._ws_opened, this);
174 channels[i].onclose = ws_closed_early;
169 channels[i].onclose = ws_closed_early;
175 }
170 }
176 // switch from early-close to late-close message after 1s
171 // switch from early-close to late-close message after 1s
@@ -187,7 +182,27 b' var IPython = (function (IPython) {'
187 };
182 };
188
183
189 /**
184 /**
190 * Stop the `shell`and `iopub` channels.
185 * Handle a websocket entering the open state
186 * sends session and cookie authentication info as first message.
187 * Once all sockets are open, signal the Kernel.status_started event.
188 * @method _ws_opened
189 */
190 Kernel.prototype._ws_opened = function (evt) {
191 // send the session id so the Session object Python-side
192 // has the same identity
193 evt.target.send(this.session_id + ':' + document.cookie);
194
195 var channels = [this.shell_channel, this.iopub_channel, this.stdin_channel];
196 for (var i=0; i < channels.length; i++) {
197 // if any channel is not ready, don't trigger event.
198 if ( !channels[i].readyState ) return;
199 }
200 // all events ready, trigger started event.
201 $([IPython.events]).trigger('status_started.Kernel', {kernel: this});
202 };
203
204 /**
205 * Stop the websocket channels.
191 * @method stop_channels
206 * @method stop_channels
192 */
207 */
193 Kernel.prototype.stop_channels = function () {
208 Kernel.prototype.stop_channels = function () {
General Comments 0
You need to be logged in to leave comments. Login now