Class: Clacky::Channel::Adapters::DingTalk::StreamClient
- Inherits:
-
Object
- Object
- Clacky::Channel::Adapters::DingTalk::StreamClient
- Defined in:
- lib/clacky/server/channel/adapters/dingtalk/stream_client.rb
Overview
WebSocket Stream Mode client for DingTalk. DingTalk Stream Mode uses JSON frames (unlike Feishu’s protobuf). Frame shape:
{ "specVersion": "1.0", "type": "SYSTEM"|"EVENT"|"CALLBACK",
"headers": { "messageId": "...", "time": "...", "topic": "...", ... },
"data": "..." }
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(client_id:, client_secret:) ⇒ StreamClient
constructor
A new instance of StreamClient.
- #start(&on_event) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(client_id:, client_secret:) ⇒ StreamClient
Returns a new instance of StreamClient.
22 23 24 25 26 |
# File 'lib/clacky/server/channel/adapters/dingtalk/stream_client.rb', line 22 def initialize(client_id:, client_secret:) @client_id = client_id @client_secret = client_secret @running = false end |
Class Method Details
.client_identifier ⇒ Object
140 141 142 143 144 |
# File 'lib/clacky/server/channel/adapters/dingtalk/stream_client.rb', line 140 def self.client_identifier name = Clacky::BrandConfig.load.product_name name = "OpenClacky" if name.nil? || name.strip.empty? "#{name.strip}/#{Clacky::VERSION}" end |
Instance Method Details
#start(&on_event) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/clacky/server/channel/adapters/dingtalk/stream_client.rb', line 28 def start(&on_event) @running = true @on_event = on_event Clacky::Logger.info("[dingtalk-ws] Starting stream client (client_id=#{@client_id})") while @running begin connect_and_listen rescue => e Clacky::Logger.warn("[dingtalk-ws] Connection error: #{e.class}: #{e.}") sleep RECONNECT_DELAY if @running end end end |
#stop ⇒ Object
43 44 45 46 |
# File 'lib/clacky/server/channel/adapters/dingtalk/stream_client.rb', line 43 def stop @running = false @ws_socket&.close rescue nil end |