Module: Funl::Stream
- Included in:
- Client, MessageSequencer
- Defined in:
- lib/funl/stream.rb
Overview
Mixin depends on stream_type, log, client_id, message_class.
Instance Method Summary collapse
- #client_stream_for(io, type: stream_type, **opts) ⇒ Object
- #message_server_stream_for(io, type: stream_type, **opts) ⇒ Object
- #server_stream_for(io, type: stream_type, **opts) ⇒ Object
Instance Method Details
#client_stream_for(io, type: stream_type, **opts) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/funl/stream.rb', line 11 def client_stream_for io, type: stream_type, **opts ObjectStreamWrapper.new(io, type: type, **opts).tap do |stream| stream.write_to_outbox {{"client_id" => client_id}} # client_id will be nil in the case of cseq, but that's ok. end end |
#message_server_stream_for(io, type: stream_type, **opts) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/funl/stream.rb', line 29 def io, type: stream_type, **opts ObjectStreamWrapper.new(io, type: type, **opts).tap do |stream| stream.consume do |h| raise StreamError, "bad handshake: #{h.class}" unless h.kind_of? Hash client_id = h["client_id"] stream.peer_name = "client #{client_id}" log.info "peer is #{stream.peer_name}" stream.expect end end end |
#server_stream_for(io, type: stream_type, **opts) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/funl/stream.rb', line 18 def server_stream_for io, type: stream_type, **opts ObjectStreamWrapper.new(io, type: type, **opts).tap do |stream| stream.consume do |h| raise StreamError, "bad handshake: #{h.class}" unless h.kind_of? Hash client_id = h["client_id"] stream.peer_name = "client #{client_id}" log.info "peer is #{stream.peer_name}" end end end |