@@ -15,7 +15,7 @@ import kotlin.coroutines.resumeWithException
1515 */
1616internal suspend fun LiveObjectsAdapter.sendAsync (message : ProtocolMessage ) = suspendCancellableCoroutine { continuation ->
1717 try {
18- this .send(message, object : CompletionListener {
18+ connectionManager .send(message, clientOptions.queueMessages , object : CompletionListener {
1919 override fun onSuccess () {
2020 continuation.resume(Unit )
2121 }
@@ -31,7 +31,7 @@ internal suspend fun LiveObjectsAdapter.sendAsync(message: ProtocolMessage) = su
3131
3232internal suspend fun LiveObjectsAdapter.attachAsync (channelName : String ) = suspendCancellableCoroutine { continuation ->
3333 try {
34- this . getChannel(channelName).attach(object : CompletionListener {
34+ getChannel(channelName).attach(object : CompletionListener {
3535 override fun onSuccess () {
3636 continuation.resume(Unit )
3737 }
@@ -45,11 +45,38 @@ internal suspend fun LiveObjectsAdapter.attachAsync(channelName: String) = suspe
4545 }
4646}
4747
48+ /* *
49+ * Retrieves the channel modes for a specific channel.
50+ * This method returns the modes that are set for the specified channel.
51+ *
52+ * @param channelName the name of the channel for which to retrieve the modes
53+ * @return the array of channel modes for the specified channel, or null if the channel is not found
54+ * Spec: RTO2a, RTO2b
55+ */
56+ internal fun LiveObjectsAdapter.getChannelModes (channelName : String ): Array <ChannelMode >? {
57+ val channel = getChannel(channelName)
58+
59+ // RTO2a - channel.modes is only populated on channel attachment, so use it only if it is set
60+ channel.modes?.let { modes ->
61+ if (modes.isNotEmpty()) {
62+ return modes
63+ }
64+ }
65+
66+ // RTO2b - otherwise as a best effort use user provided channel options
67+ channel.options?.let { options ->
68+ if (options.hasModes()) {
69+ return options.modes
70+ }
71+ }
72+ return null
73+ }
74+
4875/* *
4976 * Spec: RTO15d
5077 */
5178internal fun LiveObjectsAdapter.ensureMessageSizeWithinLimit (objectMessages : Array <ObjectMessage >) {
52- val maximumAllowedSize = maxMessageSizeLimit()
79+ val maximumAllowedSize = connectionManager.maxMessageSize
5380 val objectsTotalMessageSize = objectMessages.sumOf { it.size() }
5481 if (objectsTotalMessageSize > maximumAllowedSize) {
5582 throw ablyException(" ObjectMessages size $objectsTotalMessageSize exceeds maximum allowed size of $maximumAllowedSize bytes" ,
@@ -61,11 +88,12 @@ internal fun LiveObjectsAdapter.setChannelSerial(channelName: String, protocolMe
6188 if (protocolMessage.action != ProtocolMessage .Action .`object `) return
6289 val channelSerial = protocolMessage.channelSerial
6390 if (channelSerial.isNullOrEmpty()) return
64- setChannelSerial (channelName, channelSerial)
91+ getChannel (channelName).properties.channelSerial = channelSerial
6592}
6693
6794internal suspend fun LiveObjectsAdapter.ensureAttached (channelName : String ) {
68- when (val currentChannelStatus = this .getChannelState(channelName)) {
95+ val channel = getChannel(channelName)
96+ when (val currentChannelStatus = channel.state) {
6997 ChannelState .initialized -> attachAsync(channelName)
7098 ChannelState .attached -> return
7199 ChannelState .attaching -> {
@@ -80,7 +108,7 @@ internal suspend fun LiveObjectsAdapter.ensureAttached(channelName: String) {
80108 }
81109 }
82110 }
83- if (this .getChannelState(channelName) == ChannelState .attached) {
111+ if (channel.state == ChannelState .attached) {
84112 attachDeferred.complete(Unit )
85113 }
86114 attachDeferred.await()
@@ -119,7 +147,7 @@ internal fun LiveObjectsAdapter.throwIfMissingChannelMode(channelName: String, c
119147}
120148
121149internal fun LiveObjectsAdapter.throwIfInChannelState (channelName : String , channelStates : Array <ChannelState >) {
122- val currentState = getChannelState (channelName)
150+ val currentState = getChannel (channelName).state
123151 if (currentState == null || channelStates.contains(currentState)) {
124152 throw ablyException(" Channel is in invalid state: $currentState " , ErrorCode .ChannelStateError )
125153 }
0 commit comments