-
Notifications
You must be signed in to change notification settings - Fork 31
/
comms.go
55 lines (47 loc) · 1.97 KB
/
comms.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package dispatcher
import (
"github.com/janpfeifer/gonb/internal/goexec"
"github.com/janpfeifer/gonb/internal/kernel"
"k8s.io/klog/v2"
)
// This file handles Comm messages (custom messages) incoming in the Shell channel
// for the Kernel (and IOPub channel in the Javascript/Wasm front-end).
//
// See details in:
// 1. Router (sent in the Shell socket):
// https://jupyter-client.readthedocs.io/en/latest/messaging.html#comm-info
// 2. Custom Messages:
// https://jupyter-client.readthedocs.io/en/latest/messaging.html#custom-messages
//
// Javascript front-end:
//
// - Session id: part of the filename of the json file passed to the kernel execution as an argument (--kernel=<file.json>).
// It can be separated from the file name with a regexp like `^.*/kernel-([a-f0-9-]+).json$`.
// - Websocket connection: /api/kernels/cb142eeb-450a-47ed-9e9c-5c31aa8dba27/channels
// - JupyterServer Websocket Protocol: https://jupyter-server.readthedocs.io/en/latest/developers/websocket-protocols.html
// This file handles Comm messages (custom messages), coming from the Shell socket.
// Notice that in the front-end they are sent/received in the IOPub channel.
//
// See details in:
// 1. Router (sent in the Shell socket):
// https://jupyter-client.readthedocs.io/en/latest/messaging.html#comm-info
// 2. Custom Messages:
// https://jupyter-client.readthedocs.io/en/latest/messaging.html#custom-messages
func handleComms(msg kernel.Message, goExec *goexec.State) error {
msgType := msg.ComposedMsg().Header.MsgType
if klog.V(2).Enabled() {
klog.Infof("Comms message %q: %+v", msgType, msg.ComposedMsg())
}
switch msgType {
case "comm_info_request":
// https://jupyter-client.readthedocs.io/en/latest/messaging.html#comm-info
case "comm_open":
return goExec.Comms.HandleOpen(msg)
case "comm_close":
klog.Warningf("\"comm_close\" received, but not implemented -- likely there is no impact.")
return nil
case "comm_msg":
return goExec.Comms.HandleMsg(msg)
}
return nil
}