Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST - Channels & publishing messages #45

Merged
merged 52 commits into from May 27, 2021
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
84bf2c3
move mock handler to utils and re-use [test]
tiholic Mar 1, 2021
cdc156a
add rest#channels unit tests
tiholic Mar 1, 2021
eda41f8
add rest#channels unit tests
tiholic Mar 1, 2021
d8953e5
move timeouts to constants.dart
tiholic Mar 1, 2021
d173fac
improve message model and add unit tests
tiholic Mar 2, 2021
8d09886
remove channels.all API and use channels itself as an iterator
tiholic Mar 2, 2021
9880437
throw error while creating a channel with null name
tiholic Mar 2, 2021
c8bd0e7
add MessageExtras to validate extras passed to Message & PresenceMessage
tiholic Mar 2, 2021
80f1e69
run flutter create in example to migrate after flutter SDK upgrade
tiholic Mar 2, 2021
4c3426f
implement rest and realtime channel#release on Android
tiholic Mar 2, 2021
5a73b75
implement rest and realtime channel#release on iOS
tiholic Mar 2, 2021
e7065fd
fix lint hints
tiholic Mar 2, 2021
a154537
fix formatting
tiholic Mar 2, 2021
c1a09a9
support Rest ChannelOptions and RealtimeChannelOptions on iOS & Android
tiholic Mar 8, 2021
b3db58b
formatting issue
tiholic Mar 9, 2021
2c70824
fix unit tests after refactoring transport keys
tiholic Mar 9, 2021
fc60457
add unit tests for RSN4a and RSN4b of channels#release
tiholic Mar 9, 2021
de1ace0
refactor tests
tiholic Mar 12, 2021
a47368c
add test publish tests
tiholic Mar 12, 2021
099bc0d
feedback - making few properties on realtime connection private
tiholic Mar 12, 2021
4b4990d
fix test on android
tiholic Mar 12, 2021
80e83cb
refactor part of integration_tests that run on the ground
tiholic Mar 13, 2021
6faea42
convert PlatformException to AblyException
tiholic Mar 14, 2021
5f80574
enhance provisioning to support custom appSpec
tiholic Mar 14, 2021
b2e9ebb
[integration-test] rest channel max message size, rest capability spec
tiholic Mar 14, 2021
8db6b37
improvise platform-AblyException error messages and fix unit tests
tiholic Mar 14, 2021
b96cd85
[integration tests] move config/data to utils/data
tiholic Mar 14, 2021
2693e06
[integration tests] move all delays to a constant
tiholic Mar 14, 2021
a85ea1a
remove test loggers
tiholic Mar 14, 2021
f060470
disable `RSL1m1` as it is not supported in iOS yet.
tiholic Mar 22, 2021
ba548bb
flutter format
tiholic Mar 22, 2021
b057c4b
decode RealtimeChannelOptions#modes on iOS side
tiholic Mar 25, 2021
b248970
remove options from channels#get
tiholic May 4, 2021
54a4a5e
remove options from channels#get on android side
tiholic May 4, 2021
17571a1
remove options from channels#get on iOS side
tiholic May 4, 2021
781b712
upgrade cocoapods
tiholic May 4, 2021
4ab3360
fir for RSL1m1 spec from cocoa (upgrade Ably pod to 1.2.4)
tiholic May 4, 2021
3dfc61b
Merge branch 'main' into feature/rest-channels-and-messages
QuintinWillison May 7, 2021
589b7c4
Merge branch 'main' into feature/rest-channels-and-messages
QuintinWillison May 11, 2021
53d71a0
Update lock files.
QuintinWillison May 11, 2021
8351bb8
fix docstring on Codec#_encodeRestChannelOptions
tiholic May 20, 2021
a1fd1ea
fix docstring on Codec#_encodeRealtimeChannelOptions
tiholic May 20, 2021
bd62984
update doc commentary in codec.dart
tiholic May 20, 2021
dedcd27
fix typo
tiholic May 20, 2021
823c785
fix dependencies after flutter upgrade to 2.2
tiholic May 20, 2021
3166620
add @protected annotation to Channels#createChannel
tiholic May 20, 2021
7179b2d
remove unwated interface declaration in objC files
tiholic May 20, 2021
5dc16a3
rename cbk to callback
tiholic May 20, 2021
246e6b6
remove unsupported List type for MessageExtras
tiholic May 22, 2021
fa34b43
Merge branch 'main' into feature/rest-channels-and-messages
QuintinWillison May 27, 2021
9745e6d
fix message extras model test
tiholic May 27, 2021
8998afc
fix presence message model tests
tiholic May 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -141,53 +141,42 @@ public void onListen(Object object, EventChannel.EventSink uiThreadEventSink) {
final String eventName = eventMessage.eventName;
final Map<String, Object> eventPayload = (eventMessage.message == null) ? null : (Map<String, Object>) eventMessage.message;
try {
ChannelOptions channelOptions;
switch (eventName) {
case PlatformConstants.PlatformMethod.onRealtimeConnectionStateChanged:
connectionStateListener = new PluginConnectionStateListener(eventSink);
ablyLibrary.getRealtime(ablyMessage.handle).connection.on(connectionStateListener);
break;
case PlatformConstants.PlatformMethod.onRealtimeChannelStateChanged:
assert eventPayload != null : "event message is missing";
try {
final Channel channel = ablyLibrary
channelStateListener = new PluginChannelStateListener(eventSink);
ablyLibrary
.getRealtime(ablyMessage.handle)
.channels
.get(
(String) eventPayload.get("channel"),
(ChannelOptions) eventPayload.get("options")
);
channelStateListener = new PluginChannelStateListener(eventSink);
channel.on(channelStateListener);
} catch (AblyException ablyException) {
handleAblyException(eventSink, ablyException);
}
.get((String) eventPayload.get(PlatformConstants.TxTransportKeys.channelName))
.on(channelStateListener);
break;
case PlatformConstants.PlatformMethod.onRealtimeChannelMessage:
assert eventPayload != null : "event message is missing";
try {
final Channel channel = ablyLibrary
.getRealtime(ablyMessage.handle)
.channels
.get(
(String) eventPayload.get("channel"),
(ChannelOptions) eventPayload.get("options")
);
channelMessageListener = new PluginChannelMessageListener(eventSink);
channel.subscribe(channelMessageListener);
ablyLibrary
.getRealtime(ablyMessage.handle)
.channels
.get((String) eventPayload.get(PlatformConstants.TxTransportKeys.channelName))
.subscribe(channelMessageListener);
} catch (AblyException ablyException) {
handleAblyException(eventSink, ablyException);
}
break;
case PlatformConstants.PlatformMethod.onRealtimePresenceMessage:
assert eventPayload != null : "event message is missing";
try {
final Channel channel = ablyLibrary
.getRealtime(ablyMessage.handle)
.channels
.get((String) eventPayload.get(PlatformConstants.TxTransportKeys.channelName));
channelPresenceMessageListener = new PluginChannelPresenceMessageListener(eventSink);
channel.presence.subscribe(channelPresenceMessageListener);
ablyLibrary
.getRealtime(ablyMessage.handle)
.channels
.get((String) eventPayload.get(PlatformConstants.TxTransportKeys.channelName))
.presence.subscribe(channelPresenceMessageListener);
} catch (AblyException ablyException) {
handleAblyException(eventSink, ablyException);
}
Expand Down Expand Up @@ -219,27 +208,27 @@ public void onCancel(Object object) {
// left as is as there is no way of propagating this error to flutter side
assert eventPayload != null : "event message is missing";
ablyLibrary
.getRealtime(ablyMessage.handle)
.channels
.get((String) eventPayload.get("channel"))
.off(channelStateListener);
.getRealtime(ablyMessage.handle)
.channels
.get((String) eventPayload.get(PlatformConstants.TxTransportKeys.channelName))
.off(channelStateListener);
break;
case PlatformConstants.PlatformMethod.onRealtimeChannelMessage:
assert eventPayload != null : "event message is missing";
ablyLibrary
.getRealtime(ablyMessage.handle)
.channels
.get((String) eventPayload.get("channel"))
.unsubscribe(channelMessageListener);
.getRealtime(ablyMessage.handle)
.channels
.get((String) eventPayload.get(PlatformConstants.TxTransportKeys.channelName))
.unsubscribe(channelMessageListener);
break;
case PlatformConstants.PlatformMethod.onRealtimePresenceMessage:
assert eventPayload != null : "event message is missing";
ablyLibrary
.getRealtime(ablyMessage.handle)
.channels
.get((String) eventPayload.get(PlatformConstants.TxTransportKeys.channelName))
.presence
.unsubscribe(channelPresenceMessageListener);
.getRealtime(ablyMessage.handle)
.channels
.get((String) eventPayload.get(PlatformConstants.TxTransportKeys.channelName))
.presence
.unsubscribe(channelPresenceMessageListener);
break;
}
}
Expand Down
72 changes: 52 additions & 20 deletions android/src/main/java/io/ably/flutter/plugin/AblyMessageCodec.java
Expand Up @@ -22,7 +22,9 @@
import io.ably.lib.realtime.ConnectionStateListener;
import io.ably.lib.rest.Auth;
import io.ably.lib.rest.Auth.TokenDetails;
import io.ably.lib.types.AblyException;
import io.ably.lib.types.AsyncPaginatedResult;
import io.ably.lib.types.ChannelOptions;
import io.ably.lib.types.ClientOptions;
import io.ably.lib.types.ErrorInfo;
import io.ably.lib.types.Message;
Expand Down Expand Up @@ -74,39 +76,43 @@ T decode(Map<String, Object> jsonMap) {
codecMap = new HashMap<Byte, CodecPair>() {
{
put(PlatformConstants.CodecTypes.ablyMessage,
new CodecPair<>(self::encodeAblyFlutterMessage, self::decodeAblyFlutterMessage));
new CodecPair<>(self::encodeAblyFlutterMessage, self::decodeAblyFlutterMessage));
QuintinWillison marked this conversation as resolved.
Show resolved Hide resolved
put(PlatformConstants.CodecTypes.ablyEventMessage,
new CodecPair<>(null, self::decodeAblyFlutterEventMessage));
new CodecPair<>(null, self::decodeAblyFlutterEventMessage));
put(PlatformConstants.CodecTypes.clientOptions,
new CodecPair<>(null, self::decodeClientOptions));
new CodecPair<>(null, self::decodeClientOptions));
put(PlatformConstants.CodecTypes.tokenParams,
new CodecPair<>(self::encodeTokenParams, null));
new CodecPair<>(self::encodeTokenParams, null));
put(PlatformConstants.CodecTypes.tokenDetails,
new CodecPair<>(null, self::decodeTokenDetails));
new CodecPair<>(null, self::decodeTokenDetails));
put(PlatformConstants.CodecTypes.tokenRequest,
new CodecPair<>(null, self::decodeTokenRequest));
new CodecPair<>(null, self::decodeTokenRequest));
put(PlatformConstants.CodecTypes.restChannelOptions,
new CodecPair<>(null, self::decodeRestChannelOptions));
put(PlatformConstants.CodecTypes.realtimeChannelOptions,
new CodecPair<>(null, self::decodeRealtimeChannelOptions));
put(PlatformConstants.CodecTypes.paginatedResult,
new CodecPair<>(self::encodePaginatedResult, null));
new CodecPair<>(self::encodePaginatedResult, null));
put(PlatformConstants.CodecTypes.restHistoryParams,
new CodecPair<>(null, self::decodeRestHistoryParams));
new CodecPair<>(null, self::decodeRestHistoryParams));
put(PlatformConstants.CodecTypes.realtimeHistoryParams,
new CodecPair<>(null, self::decodeRealtimeHistoryParams));
new CodecPair<>(null, self::decodeRealtimeHistoryParams));
put(PlatformConstants.CodecTypes.restPresenceParams,
new CodecPair<>(null, self::decodeRestPresenceParams));
new CodecPair<>(null, self::decodeRestPresenceParams));
put(PlatformConstants.CodecTypes.realtimePresenceParams,
new CodecPair<>(null, self::decodeRealtimePresenceParams));
new CodecPair<>(null, self::decodeRealtimePresenceParams));
put(PlatformConstants.CodecTypes.errorInfo,
new CodecPair<>(self::encodeErrorInfo, null));
new CodecPair<>(self::encodeErrorInfo, null));
put(PlatformConstants.CodecTypes.messageData,
new CodecPair<>(null, self::decodeChannelMessageData));
new CodecPair<>(null, self::decodeChannelMessageData));
put(PlatformConstants.CodecTypes.message,
new CodecPair<>(self::encodeChannelMessage, self::decodeChannelMessage));
new CodecPair<>(self::encodeChannelMessage, self::decodeChannelMessage));
put(PlatformConstants.CodecTypes.presenceMessage,
new CodecPair<>(self::encodePresenceMessage, null));
new CodecPair<>(self::encodePresenceMessage, null));
put(PlatformConstants.CodecTypes.connectionStateChange,
new CodecPair<>(self::encodeConnectionStateChange, null));
new CodecPair<>(self::encodeConnectionStateChange, null));
put(PlatformConstants.CodecTypes.channelStateChange,
new CodecPair<>(self::encodeChannelStateChange, null));
new CodecPair<>(self::encodeChannelStateChange, null));
}
};
}
Expand Down Expand Up @@ -314,6 +320,32 @@ private Auth.TokenRequest decodeTokenRequest(Map<String, Object> jsonMap) {
return o;
}

private ChannelOptions decodeRestChannelOptions(Map<String, Object> jsonMap) {
if (jsonMap == null) return null;
final Object cipher = jsonMap.get(PlatformConstants.TxRealtimeChannelOptions.cipher);
try {
return ChannelOptions.withCipherKey((String) cipher);
} catch (AblyException ae) {
System.out.println("Exception while decoding RestChannelOptions : " + ae);
return null;
}
}

private ChannelOptions decodeRealtimeChannelOptions(Map<String, Object> jsonMap) {
if (jsonMap == null) return null;
final Object cipher = jsonMap.get(PlatformConstants.TxRealtimeChannelOptions.cipher);
try {
final ChannelOptions o = ChannelOptions.withCipherKey((String) cipher);
readValueFromJson(jsonMap, PlatformConstants.TxRealtimeChannelOptions.params, v -> o.cipherParams = (Map<String, String>) v);
// modes is not supported in ably-java
// Track @ https://github.com/ably/ably-flutter/issues/14
return o;
} catch (AblyException ae) {
System.out.println("Exception while decoding RealtimeChannelOptions: " + ae);
return null;
}
}

private Param[] decodeRestHistoryParams(Map<String, Object> jsonMap) {
if (jsonMap == null) return null;
Param[] params = new Param[jsonMap.size()];
Expand Down Expand Up @@ -573,9 +605,9 @@ private Map<String, Object> encodePaginatedResult(AsyncPaginatedResult<Object> c
list.add((Map<String, Object>) pair.encode(item));
}
writeValueToJson(
jsonMap,
PlatformConstants.TxPaginatedResult.items,
list
jsonMap,
PlatformConstants.TxPaginatedResult.items,
list
);
writeValueToJson(jsonMap, PlatformConstants.TxPaginatedResult.type, type & 0xff);
}
Expand Down