@@ -59,7 +59,7 @@ module Cable
5959 @stream_identifier = stream_identifier.to_s
6060 end
6161
62- def self.broadcast_to (channel : String , message : JSON ::Any )
62+ def self.broadcast_to (channel : String , message : JSON ::Any | Hash ( String , String ) )
6363 Cable ::Logger .info { " [ActionCable] Broadcasting to #{ channel } : #{ message } " }
6464 Cable .server.publish(channel, message.to_json)
6565 end
@@ -70,60 +70,19 @@ module Cable
7070 Cable .server.publish(channel, message)
7171 end
7272
73- def self.broadcast_to (channel : String , message : Hash (String , String ))
74- Cable ::Logger .info { " [ActionCable] Broadcasting to #{ channel } : #{ message } " }
75- Cable .server.publish(channel, message.to_json)
76- end
77-
78- def broadcast (message : String )
79- if stream_id = stream_identifier.presence
80- Cable ::Logger .info { " [ActionCable] Broadcasting to #{ self .class} : #{ message } " }
81- Cable .server.send_to_channels(stream_id, message)
82- else
83- Cable ::Logger .error { " #{ self .class} .transmit(message : String) with #{ message } without already using stream_from(stream_identifier)" }
84- end
85- end
86-
87- def broadcast (message : JSON ::Any )
73+ def broadcast (message : String | JSON ::Any | Hash (String , String ))
8874 if stream_id = stream_identifier.presence
8975 Cable ::Logger .info { " [ActionCable] Broadcasting to #{ self .class} : #{ message } " }
9076 Cable .server.send_to_channels(stream_id, message)
9177 else
92- Cable ::Logger .error { " #{ self .class} .transmit(message : JSON::Any ) with #{ message } without already using stream_from(stream_identifier)" }
78+ Cable ::Logger .error { " #{ self .class} .transmit(message : #{ message.class } ) with #{ message } without already using stream_from(stream_identifier)" }
9379 end
9480 end
9581
96- def broadcast (message : Hash (String , String ))
97- if stream_id = stream_identifier.presence
98- Cable ::Logger .info { " [ActionCable] Broadcasting to #{ self .class} : #{ message } " }
99- Cable .server.send_to_channels(stream_id, message.to_json)
100- else
101- Cable ::Logger .error { " #{ self .class} .transmit(message : Hash(String, String)) with #{ message } without already using stream_from(stream_identifier)" }
102- end
103- end
104-
105- # broadcast single message to single connection for this channel
106- def transmit (message : String )
107- Cable ::Logger .info { " [ActionCable] transmitting to #{ self .class} : #{ message } " }
108- connection.socket.send({
109- identifier: identifier,
110- message: Cable .server.safe_decode_message(message),
111- }.to_json)
112- end
113-
114- # broadcast single message to single connection for this channel
115- def transmit (message : JSON ::Any )
116- Cable ::Logger .info { " [ActionCable] transmitting to #{ self .class} : #{ message } " }
117- connection.socket.send({
118- identifier: identifier,
119- message: Cable .server.safe_decode_message(message),
120- }.to_json)
121- end
122-
12382 # broadcast single message to single connection for this channel
124- def transmit (message : Hash (String , String ))
83+ def transmit (message : String | JSON :: Any | Hash (String , String ))
12584 Cable ::Logger .info { " [ActionCable] transmitting to #{ self .class} : #{ message } " }
126- connection.socket.send ({
85+ connection.send_message ({
12786 identifier: identifier,
12887 message: Cable .server.safe_decode_message(message),
12988 }.to_json)
0 commit comments