diff --git a/lib/iruby/comm.rb b/lib/iruby/comm.rb index f72505f..3a712a2 100644 --- a/lib/iruby/comm.rb +++ b/lib/iruby/comm.rb @@ -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 diff --git a/lib/iruby/session.rb b/lib/iruby/session.rb index 584de9a..3a4c66d 100644 --- a/lib/iruby/session.rb +++ b/lib/iruby/session.rb @@ -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] @@ -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) diff --git a/lib/iruby/session/mixin.rb b/lib/iruby/session/mixin.rb index 5aed699..3ddd06c 100644 --- a/lib/iruby/session/mixin.rb +++ b/lib/iruby/session/mixin.rb @@ -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}"