Flutter - Ably - java.util.HashMap cannot be cast to io.ably.lib.types.Param

138 Views Asked by At

This plugin ...

https://pub.dev/packages/ably_flutter

... asked me to do this ...

ably.ClientOptions options = ably.ClientOptions(
  clientId : '...',
  authUrl : '...',
  authHeaders : {'Authorization' : '...'},
);
ably.Realtime realtime = await ably.Realtime(options : options);

... before gave me this ...

E/DartMessenger(12893): Uncaught exception in binary message listener

E/DartMessenger(12893): java.lang.ClassCastException: java.util.HashMap cannot be cast to io.ably.lib.types.Param[]

... and I don't know what else to do.

I thought it's because the backend responded wrong format data to Ably, so it was failed to convert it to ably.tokenParams type at app end. But backend guys told me there's nothing wrong at their end.

Greatly appreciate your help thank you.

1

There are 1 best solutions below

0
stackunderflow On BEST ANSWER

It's working either way using authCallback instead of authUrl and clientId, where TokenRequest or TokenDetais generated from data returned by back-end.

Authenticate with signed TokenRequest

ably.ClientOptions(
  key : token //Authentication token
  authCallback : (ably.TokenParams params) => ably.TokenRequest.fromMap(...)
);

Authenticate with Ably JWT

ably.ClientOptions(
  authCallback : (ably.TokenParams params) => ably.TokenDetails.fromMap(...)
);