@@ -22,6 +22,7 @@ namespace HiveMQtt.Client;
22
22
using HiveMQtt . Client . Options ;
23
23
using HiveMQtt . Client . Results ;
24
24
using HiveMQtt . MQTT5 . Types ;
25
+ using HiveMQtt . Client . Events ;
25
26
26
27
/// <summary>
27
28
/// The HiveMQClient interface.
@@ -35,45 +36,45 @@ public interface IHiveMQClient : IDisposable
35
36
/// to store data that is specific to this HiveMQClient.
36
37
/// </para>
37
38
/// </summary>
38
- Dictionary < string , string > LocalStore { get ; }
39
+ public Dictionary < string , string > LocalStore { get ; }
39
40
40
41
/// <summary>
41
42
/// Gets or sets the options for this client.
42
43
/// </summary>
43
- HiveMQClientOptions Options { get ; set ; }
44
+ public HiveMQClientOptions Options { get ; set ; }
44
45
45
46
/// <summary>
46
47
/// Gets the list of subscriptions for this client.
47
48
/// </summary>
48
- List < Subscription > Subscriptions { get ; }
49
+ public List < Subscription > Subscriptions { get ; }
49
50
50
51
/// <summary>
51
52
/// Indicates if the client is currently connected to the MQTT broker.
52
53
/// </summary>
53
54
/// <returns>True if connected, false otherwise.</returns>
54
- bool IsConnected ( ) ;
55
+ public bool IsConnected ( ) ;
55
56
56
57
/// <summary>
57
58
/// Asynchronously makes a TCP connection to the remote specified in HiveMQClientOptions and then
58
59
/// proceeds to make an MQTT Connect request.
59
60
/// </summary>
60
61
/// <returns>A ConnectResult class representing the result of the MQTT connect call.</returns>
61
- Task < ConnectResult > ConnectAsync ( ) ;
62
+ public Task < ConnectResult > ConnectAsync ( ) ;
62
63
63
64
/// <summary>
64
65
/// Asynchronous disconnect from the previously connected MQTT broker.
65
66
/// </summary>
66
67
/// <param name="options">The options for the MQTT Disconnect call.</param>
67
68
/// <returns>A boolean indicating on success or failure.</returns>
68
- Task < bool > DisconnectAsync ( DisconnectOptions options ) ;
69
+ public Task < bool > DisconnectAsync ( DisconnectOptions options ) ;
69
70
70
71
/// <summary>
71
72
/// Publish a message to an MQTT topic.
72
73
/// </summary>
73
74
/// <param name="message">The <seealso cref="MQTT5PublishMessage"/> for the Publish.</param>
74
75
/// <param name="cancellationToken">A <seealso cref="CancellationToken"/> to cancel the operation.</param>
75
76
/// <returns>A <seealso cref="PublishResult"/> representing the result of the publish operation.</returns>
76
- Task < PublishResult > PublishAsync ( MQTT5PublishMessage message , CancellationToken cancellationToken = default ) ;
77
+ public Task < PublishResult > PublishAsync ( MQTT5PublishMessage message , CancellationToken cancellationToken = default ) ;
77
78
78
79
/// <summary>
79
80
/// Publish a message to an MQTT topic.
@@ -85,7 +86,7 @@ public interface IHiveMQClient : IDisposable
85
86
/// <param name="payload">The string message to publish.</param>
86
87
/// <param name="qos">The <seealso cref="QualityOfService"/> to use for the publish.</param>
87
88
/// <returns>A <seealso cref="PublishResult"/> representing the result of the publish operation.</returns>
88
- Task < PublishResult > PublishAsync ( string topic , string payload , QualityOfService qos = QualityOfService . AtMostOnceDelivery ) ;
89
+ public Task < PublishResult > PublishAsync ( string topic , string payload , QualityOfService qos = QualityOfService . AtMostOnceDelivery ) ;
89
90
90
91
/// <summary>
91
92
/// Publish a message to an MQTT topic.
@@ -97,7 +98,7 @@ public interface IHiveMQClient : IDisposable
97
98
/// <param name="payload">The UTF-8 encoded array of bytes to publish.</param>
98
99
/// <param name="qos">The <seealso cref="QualityOfService"/> to use for the publish.</param>
99
100
/// <returns>A <seealso cref="PublishResult"/> representing the result of the publish operation.</returns>
100
- Task < PublishResult > PublishAsync ( string topic , byte [ ] payload , QualityOfService qos = QualityOfService . AtMostOnceDelivery ) ;
101
+ public Task < PublishResult > PublishAsync ( string topic , byte [ ] payload , QualityOfService qos = QualityOfService . AtMostOnceDelivery ) ;
101
102
102
103
/// <summary>
103
104
/// Subscribe with a single topic filter on the MQTT broker.
@@ -114,7 +115,7 @@ public interface IHiveMQClient : IDisposable
114
115
/// <param name="retainAsPublished">A boolean indicating whether Application Messages forwarded using this subscription keep the RETAIN flag they were published with.</param>
115
116
/// <param name="retainHandling">A RetainHandling value indicating whether retained messages are sent when the subscription is established.</param>
116
117
/// <returns>SubscribeResult reflecting the result of the operation.</returns>
117
- Task < SubscribeResult > SubscribeAsync ( string topic , QualityOfService qos = QualityOfService . AtMostOnceDelivery , bool noLocal = false , bool retainAsPublished = false , RetainHandling retainHandling = RetainHandling . SendAtSubscribe ) ;
118
+ public Task < SubscribeResult > SubscribeAsync ( string topic , QualityOfService qos = QualityOfService . AtMostOnceDelivery , bool noLocal = false , bool retainAsPublished = false , RetainHandling retainHandling = RetainHandling . SendAtSubscribe ) ;
118
119
119
120
/// <summary>
120
121
/// Subscribe with SubscribeOptions on the MQTT broker.
@@ -130,29 +131,219 @@ public interface IHiveMQClient : IDisposable
130
131
/// </example>
131
132
/// <param name="options">The options for the subscribe request.</param>
132
133
/// <returns>SubscribeResult reflecting the result of the operation.</returns>
133
- Task < SubscribeResult > SubscribeAsync ( SubscribeOptions options ) ;
134
+ public Task < SubscribeResult > SubscribeAsync ( SubscribeOptions options ) ;
134
135
135
136
/// <summary>
136
137
/// Unsubscribe from a single topic filter on the MQTT broker.
137
138
/// </summary>
138
139
/// <exception cref="HiveMQttClientException">Thrown if no subscription is found for the topic.</exception>
139
140
/// <param name="topic">The topic filter to unsubscribe from.</param>
140
141
/// <returns>UnsubscribeResult reflecting the result of the operation.</returns>
141
- Task < UnsubscribeResult > UnsubscribeAsync ( string topic ) ;
142
+ public Task < UnsubscribeResult > UnsubscribeAsync ( string topic ) ;
142
143
143
144
/// <summary>
144
145
/// Unsubscribe from a single topic filter on the MQTT broker.
145
146
/// </summary>
146
147
/// <exception cref="HiveMQttClientException">Thrown if no subscription is found for the topic.</exception>
147
148
/// <param name="subscription">The subscription from client.Subscriptions to unsubscribe from.</param>
148
149
/// <returns>UnsubscribeResult reflecting the result of the operation.</returns>
149
- Task < UnsubscribeResult > UnsubscribeAsync ( Subscription subscription ) ;
150
+ public Task < UnsubscribeResult > UnsubscribeAsync ( Subscription subscription ) ;
150
151
151
152
/// <summary>
152
153
/// Unsubscribe from a single topic filter on the MQTT broker.
153
154
/// </summary>
154
155
/// <exception cref="HiveMQttClientException">Thrown if no subscription is found for the topic.</exception>
155
156
/// <param name="subscriptions">The subscriptions from client.Subscriptions to unsubscribe from.</param>
156
157
/// <returns>UnsubscribeResult reflecting the result of the operation.</returns>
157
- Task < UnsubscribeResult > UnsubscribeAsync ( List < Subscription > subscriptions ) ;
158
+ public Task < UnsubscribeResult > UnsubscribeAsync ( List < Subscription > subscriptions ) ;
159
+
160
+ /// <summary>
161
+ /// Event that is fired before the client connects to the broker.
162
+ /// </summary>
163
+ /// <remarks>
164
+ /// This event allows you to modify connection options before the connection attempt is made.
165
+ /// </remarks>
166
+ public event EventHandler < BeforeConnectEventArgs > ? BeforeConnect ;
167
+
168
+ /// <summary>
169
+ /// Event that is fired after the client successfully connects to the broker.
170
+ /// </summary>
171
+ /// <remarks>
172
+ /// The event arguments contain the results of the connection attempt.
173
+ /// </remarks>
174
+ public event EventHandler < AfterConnectEventArgs > ? AfterConnect ;
175
+
176
+ /// <summary>
177
+ /// Event that is fired before the client disconnects from the broker.
178
+ /// </summary>
179
+ public event EventHandler < BeforeDisconnectEventArgs > ? BeforeDisconnect ;
180
+
181
+ /// <summary>
182
+ /// Event that is fired after the client is disconnected from the broker.
183
+ /// </summary>
184
+ /// <remarks>
185
+ /// The event arguments indicate whether the disconnect was clean or not.
186
+ /// </remarks>
187
+ public event EventHandler < AfterDisconnectEventArgs > ? AfterDisconnect ;
188
+
189
+ /// <summary>
190
+ /// Event that is fired before the client sends a subscribe request.
191
+ /// </summary>
192
+ /// <remarks>
193
+ /// This event allows you to modify subscription options before the request is sent.
194
+ /// </remarks>
195
+ public event EventHandler < BeforeSubscribeEventArgs > ? BeforeSubscribe ;
196
+
197
+ /// <summary>
198
+ /// Event that is fired after the client completes a subscribe request.
199
+ /// </summary>
200
+ /// <remarks>
201
+ /// The event arguments contain the results of the subscription attempt.
202
+ /// </remarks>
203
+ public event EventHandler < AfterSubscribeEventArgs > ? AfterSubscribe ;
204
+
205
+ /// <summary>
206
+ /// Event that is fired before the client sends an unsubscribe request.
207
+ /// </summary>
208
+ public event EventHandler < BeforeUnsubscribeEventArgs > ? BeforeUnsubscribe ;
209
+
210
+ /// <summary>
211
+ /// Event that is fired after the client completes an unsubscribe request.
212
+ /// </summary>
213
+ /// <remarks>
214
+ /// The event arguments contain the results of the unsubscribe operation.
215
+ /// </remarks>
216
+ public event EventHandler < AfterUnsubscribeEventArgs > ? AfterUnsubscribe ;
217
+
218
+ /// <summary>
219
+ /// Event that is fired when a message is received from the broker.
220
+ /// </summary>
221
+ /// <remarks>
222
+ /// This is the main event for receiving published messages from subscribed topics.
223
+ /// </remarks>
224
+ public event EventHandler < OnMessageReceivedEventArgs > ? OnMessageReceived ;
225
+
226
+ /// <summary>
227
+ /// Event that is fired after the client sends a CONNECT packet to the broker.
228
+ /// </summary>
229
+ public event EventHandler < OnConnectSentEventArgs > ? OnConnectSent ;
230
+
231
+ /// <summary>
232
+ /// Event that is fired after the client receives a CONNACK packet from the broker.
233
+ /// </summary>
234
+ public event EventHandler < OnConnAckReceivedEventArgs > ? OnConnAckReceived ;
235
+
236
+ /// <summary>
237
+ /// Event that is fired after the client sends a DISCONNECT packet to the broker.
238
+ /// </summary>
239
+ public event EventHandler < OnDisconnectSentEventArgs > ? OnDisconnectSent ;
240
+
241
+ /// <summary>
242
+ /// Event that is fired after the client receives a DISCONNECT packet from the broker.
243
+ /// </summary>
244
+ public event EventHandler < OnDisconnectReceivedEventArgs > ? OnDisconnectReceived ;
245
+
246
+ /// <summary>
247
+ /// Event that is fired after the client sends a PINGREQ packet to the broker.
248
+ /// </summary>
249
+ public event EventHandler < OnPingReqSentEventArgs > ? OnPingReqSent ;
250
+
251
+ /// <summary>
252
+ /// Event that is fired after the client receives a PINGRESP packet from the broker.
253
+ /// </summary>
254
+ public event EventHandler < OnPingRespReceivedEventArgs > ? OnPingRespReceived ;
255
+
256
+ /// <summary>
257
+ /// Event that is fired after the client sends a SUBSCRIBE packet to the broker.
258
+ /// </summary>
259
+ public event EventHandler < OnSubscribeSentEventArgs > ? OnSubscribeSent ;
260
+
261
+ /// <summary>
262
+ /// Event that is fired after the client receives a SUBACK packet from the broker.
263
+ /// </summary>
264
+ public event EventHandler < OnSubAckReceivedEventArgs > ? OnSubAckReceived ;
265
+
266
+ /// <summary>
267
+ /// Event that is fired after the client sends an UNSUBSCRIBE packet to the broker.
268
+ /// </summary>
269
+ public event EventHandler < OnUnsubscribeSentEventArgs > ? OnUnsubscribeSent ;
270
+
271
+ /// <summary>
272
+ /// Event that is fired after the client receives an UNSUBACK packet from the broker.
273
+ /// </summary>
274
+ public event EventHandler < OnUnsubAckReceivedEventArgs > ? OnUnsubAckReceived ;
275
+
276
+ /// <summary>
277
+ /// Event that is fired after the client receives a PUBLISH packet from the broker.
278
+ /// </summary>
279
+ public event EventHandler < OnPublishReceivedEventArgs > ? OnPublishReceived ;
280
+
281
+ /// <summary>
282
+ /// Event that is fired after the client sends a PUBLISH packet to the broker.
283
+ /// </summary>
284
+ public event EventHandler < OnPublishSentEventArgs > ? OnPublishSent ;
285
+
286
+ /// <summary>
287
+ /// Event that is fired after the client receives a PUBACK packet from the broker.
288
+ /// </summary>
289
+ /// <remarks>
290
+ /// This event is part of QoS 1 message delivery protocol.
291
+ /// </remarks>
292
+ public event EventHandler < OnPubAckReceivedEventArgs > ? OnPubAckReceived ;
293
+
294
+ /// <summary>
295
+ /// Event that is fired after the client sends a PUBACK packet to the broker.
296
+ /// </summary>
297
+ /// <remarks>
298
+ /// This event is part of QoS 1 message delivery protocol.
299
+ /// </remarks>
300
+ public event EventHandler < OnPubAckSentEventArgs > ? OnPubAckSent ;
301
+
302
+ /// <summary>
303
+ /// Event that is fired after the client receives a PUBREC packet from the broker.
304
+ /// </summary>
305
+ /// <remarks>
306
+ /// This event is part of QoS 2 message delivery protocol.
307
+ /// </remarks>
308
+ public event EventHandler < OnPubRecReceivedEventArgs > ? OnPubRecReceived ;
309
+
310
+ /// <summary>
311
+ /// Event that is fired after the client sends a PUBREC packet to the broker.
312
+ /// </summary>
313
+ /// <remarks>
314
+ /// This event is part of QoS 2 message delivery protocol.
315
+ /// </remarks>
316
+ public event EventHandler < OnPubRecSentEventArgs > ? OnPubRecSent ;
317
+
318
+ /// <summary>
319
+ /// Event that is fired after the client receives a PUBREL packet from the broker.
320
+ /// </summary>
321
+ /// <remarks>
322
+ /// This event is part of QoS 2 message delivery protocol.
323
+ /// </remarks>
324
+ public event EventHandler < OnPubRelReceivedEventArgs > ? OnPubRelReceived ;
325
+
326
+ /// <summary>
327
+ /// Event that is fired after the client sends a PUBREL packet to the broker.
328
+ /// </summary>
329
+ /// <remarks>
330
+ /// This event is part of QoS 2 message delivery protocol.
331
+ /// </remarks>
332
+ public event EventHandler < OnPubRelSentEventArgs > ? OnPubRelSent ;
333
+
334
+ /// <summary>
335
+ /// Event that is fired after the client receives a PUBCOMP packet from the broker.
336
+ /// </summary>
337
+ /// <remarks>
338
+ /// This event is part of QoS 2 message delivery protocol.
339
+ /// </remarks>
340
+ public event EventHandler < OnPubCompReceivedEventArgs > ? OnPubCompReceived ;
341
+
342
+ /// <summary>
343
+ /// Event that is fired after the client sends a PUBCOMP packet to the broker.
344
+ /// </summary>
345
+ /// <remarks>
346
+ /// This event is part of QoS 2 message delivery protocol.
347
+ /// </remarks>
348
+ public event EventHandler < OnPubCompSentEventArgs > ? OnPubCompSent ;
158
349
}
0 commit comments