Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for jupyter widgets #350

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/iruby/comm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ def initialize(target_name, comm_id = SecureRandom.uuid)
@target_name, @comm_id = target_name, comm_id
end

def open(**data)
Kernel.instance.session.send(:publish, :comm_open, comm_id: @comm_id, data: data, target_name: @target_name)
def open(metadata = nil, **data)
Kernel.instance.session.send(:publish, :comm_open, metadata, comm_id: @comm_id, data: data, target_name: @target_name)
Comm.comm[@comm_id] = self
end

def send(**data)
Kernel.instance.session.send(:publish, :comm_msg, comm_id: @comm_id, data: data)
def send(metadata = nil, **data)
Kernel.instance.session.send(:publish, :comm_msg, metadata, comm_id: @comm_id, data: data)
end

def close(**data)
Kernel.instance.session.send(:publish, :comm_close, comm_id: @comm_id, data: data)
def close(metadata = nil, **data)
Kernel.instance.session.send(:publish, :comm_close, metadata, comm_id: @comm_id, data: data)
Comm.comm.delete(@comm_id)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/iruby/session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def setup_security
end
end

def send(socket_type, message_type, content)
def send(socket_type, message_type, metadata = nil, content)
sock = check_socket_type(socket_type)
idents = if socket_type == :reply && @last_recvd_msg
@last_recvd_msg[:idents]
Expand All @@ -85,7 +85,7 @@ def send(socket_type, message_type, content)
session: @session_id,
version: '5.0'
}
@adapter.send(sock, serialize(idents, header, content))
@adapter.send(sock, serialize(idents, header, metadata, content))
end

def recv(socket_type)
Expand Down
4 changes: 2 additions & 2 deletions lib/iruby/session/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module SessionSerialize

private

def serialize(idents, header, content)
def serialize(idents, header, metadata = nil, content)
msg = [MultiJson.dump(header),
MultiJson.dump(@last_recvd_msg ? @last_recvd_msg[:header] : {}),
'{}',
MultiJson.dump(metadata || {}),
MultiJson.dump(content || {})]
frames = ([*idents].compact.map(&:to_s) << DELIM << sign(msg)) + msg
IRuby.logger.debug "Sent #{frames.inspect}"
Expand Down
Loading