forPresenceChannel static method

EndpointAuthorizableChannelTokenAuthorizationDelegate<PresenceChannelAuthorizationData> forPresenceChannel({
  1. required Uri authorizationEndpoint,
  2. required Map<String, String> headers,
  3. bool overrideContentTypeHeader = true,
  4. EndpointAuthorizableChannelTokenAuthorizationParser<PresenceChannelAuthorizationData> parser = _defaultParserForPresenceChannel,
  5. EndpointAuthFailedCallback? onAuthFailed,
})

Providing an instance of this class to authorize to PresenceChannels with PresenceChannelAuthorizationData.

Set overrideContentTypeHeader to false in order to prevent 'content-type': 'application/x-www-form-urlencoded' from being added into provided headers.

If the custom parser is not provided the default one will be used:

static PresenceChannelAuthorizationData _defaultParserForPresenceChannel(
  http.Response response,
) {
  final decoded = jsonDecode(response.body) as Map;
  final auth = decoded['auth'] as String;
  final channelData = decoded['channel_data'] as String;
  return PresenceChannelAuthorizationData(
    authKey: auth,
    channelDataEncoded: channelData,
  );
}

Implementation

///   return PresenceChannelAuthorizationData(
///     authKey: auth,
///     channelDataEncoded: channelData,
///   );
/// }

/// ```
static EndpointAuthorizableChannelTokenAuthorizationDelegate<
    PresenceChannelAuthorizationData> forPresenceChannel({
  required Uri authorizationEndpoint,
  required Map<String, String> headers,
  bool overrideContentTypeHeader = true,
  EndpointAuthorizableChannelTokenAuthorizationParser<
          PresenceChannelAuthorizationData>
      parser = _defaultParserForPresenceChannel,
  EndpointAuthFailedCallback? onAuthFailed,
}) =>
    EndpointAuthorizableChannelTokenAuthorizationDelegate._(
      authorizationEndpoint: authorizationEndpoint,
      overrideContentTypeHeader: overrideContentTypeHeader,
      headers: headers,
      parser: parser,
      onAuthFailed: onAuthFailed,
    );