|
1 | 1 | package io.ably.lib.objects |
2 | 2 |
|
3 | | -import io.ably.lib.plugins.PluginConnectionAdapter |
4 | | -import io.ably.lib.realtime.CompletionListener |
5 | | -import io.ably.lib.types.ErrorInfo |
6 | 3 | import io.ably.lib.types.ProtocolMessage |
7 | | -import kotlinx.coroutines.CompletableDeferred |
8 | 4 | import java.util.concurrent.ConcurrentHashMap |
9 | 5 |
|
10 | | -public class DefaultLiveObjectsPlugin(private val pluginConnectionAdapter: PluginConnectionAdapter) : LiveObjectsPlugin { |
| 6 | +public class DefaultLiveObjectsPlugin(private val adapter: LiveObjectsAdapter) : LiveObjectsPlugin { |
11 | 7 |
|
12 | 8 | private val liveObjects = ConcurrentHashMap<String, DefaultLiveObjects>() |
13 | 9 |
|
14 | 10 | override fun getInstance(channelName: String): LiveObjects { |
15 | | - return liveObjects.getOrPut(channelName) { DefaultLiveObjects(channelName) } |
| 11 | + return liveObjects.getOrPut(channelName) { DefaultLiveObjects(channelName, adapter) } |
16 | 12 | } |
17 | 13 |
|
18 | | - public suspend fun send(message: ProtocolMessage) { |
19 | | - val deferred = CompletableDeferred<Unit>() |
20 | | - pluginConnectionAdapter.send(message, object : CompletionListener { |
21 | | - override fun onSuccess() { |
22 | | - deferred.complete(Unit) |
23 | | - } |
24 | | - |
25 | | - override fun onError(reason: ErrorInfo) { |
26 | | - deferred.completeExceptionally(Exception(reason.message)) |
27 | | - } |
28 | | - }) |
29 | | - deferred.await() |
30 | | - } |
31 | | - |
32 | | - override fun handle(message: ProtocolMessage) { |
33 | | - TODO("Not yet implemented") |
| 14 | + override fun handle(msg: ProtocolMessage) { |
| 15 | + val channelName = msg.channel |
| 16 | + liveObjects[channelName]?.handle(msg) |
34 | 17 | } |
35 | 18 |
|
36 | 19 | override fun dispose(channelName: String) { |
|
0 commit comments