subscribe method
StompUnsubscribe
subscribe({
- required String destination,
- required StompFrameCallback callback,
- Map<
String, String> ? headers,
Implementation
StompUnsubscribe subscribe({
required String destination,
required StompFrameCallback callback,
Map<String, String>? headers,
}) {
final subscriptionHeaders = {
...?headers,
'destination': destination,
};
if (!subscriptionHeaders.containsKey('id')) {
subscriptionHeaders['id'] = 'sub-${_currentSubscriptionIndex++}';
}
_subscriptionWatcher[subscriptionHeaders['id']!] = callback;
_transmit(command: 'SUBSCRIBE', headers: subscriptionHeaders);
return ({Map<String, String>? unsubscribeHeaders}) {
if (!connected) return;
final headers = {...?unsubscribeHeaders};
if (!headers.containsKey('id')) {
headers['id'] = subscriptionHeaders['id']!;
}
_subscriptionWatcher.remove(headers['id']);
_transmit(command: 'UNSUBSCRIBE', headers: headers);
};
}