-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement RtcEngine plugin feature (#470)
* feat: Implement RtcEngine plugin feature * Remove unnecessary comments * Remove unnecessary comments * Resolve PR comment
- Loading branch information
1 parent
1800a85
commit 9230a55
Showing
29 changed files
with
1,876 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
android/src/main/java/io/agora/rtc/base/RtcEnginePlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.agora.rtc.base | ||
|
||
import io.agora.rtc.RtcEngine | ||
|
||
/** | ||
* A [RtcEnginePlugin] allows developers to interact with the [RtcEngine] which created from flutter | ||
* side. | ||
*/ | ||
interface RtcEnginePlugin { | ||
|
||
/** | ||
* This callback will be called when the [RtcEngine] is created by | ||
* [RtcEngine.createWithContext](https://docs.agora.io/cn/Video/API%20Reference/flutter/agora_rtc_engine/RtcEngine/createWithContext.html) | ||
* function from flutter. | ||
* | ||
* @param rtcEngine The same [RtcEngine] used by flutter side | ||
*/ | ||
fun onRtcEngineCreated(rtcEngine: RtcEngine?) | ||
|
||
/** | ||
* This callback will be called when the [RtcEngine.destroy](https://docs.agora.io/cn/Video/API%20Reference/flutter/v4.0.7/rtc_channel/RtcChannel/destroy.html) | ||
* function is called from flutter. | ||
*/ | ||
fun onRtcEngineDestroyed() | ||
|
||
companion object Registrant { | ||
/** | ||
* Register a [RtcEnginePlugin]. The [plugin] will be called when the [RtcEngine] is created from | ||
* flutter side. | ||
*/ | ||
fun register(plugin: RtcEnginePlugin) { | ||
RtcEngineRegistry.instance.add(plugin = plugin) | ||
} | ||
|
||
/** | ||
* Unregister a previously registered [RtcEnginePlugin]. | ||
*/ | ||
fun unregister(plugin: RtcEnginePlugin) { | ||
RtcEngineRegistry.instance.remove(pluginClass = plugin.javaClass) | ||
} | ||
} | ||
} | ||
|
||
|
43 changes: 43 additions & 0 deletions
43
android/src/main/java/io/agora/rtc/base/RtcEngineRegistry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package io.agora.rtc.base | ||
|
||
import io.agora.rtc.RtcEngine | ||
import java.util.HashMap | ||
|
||
/** | ||
* The [RtcEngineRegistry] is response to add, remove and notify the callback when [RtcEngine] is created | ||
* from flutter side. | ||
*/ | ||
internal class RtcEngineRegistry private constructor() : RtcEnginePlugin { | ||
companion object { | ||
val instance: RtcEngineRegistry by lazy { RtcEngineRegistry() } | ||
} | ||
|
||
private val plugins: MutableMap<Class<out RtcEnginePlugin>, RtcEnginePlugin> = HashMap() | ||
|
||
/** | ||
* Add a [RtcEnginePlugin]. | ||
*/ | ||
fun add(plugin: RtcEnginePlugin) { | ||
if (plugins.containsKey(plugin.javaClass)) return | ||
plugins[plugin.javaClass] = plugin | ||
} | ||
|
||
/** | ||
* Remove the previously added [RtcEnginePlugin]. | ||
*/ | ||
fun remove(pluginClass: Class<out RtcEnginePlugin>) { | ||
plugins.remove(pluginClass) | ||
} | ||
|
||
override fun onRtcEngineCreated(rtcEngine: RtcEngine?) { | ||
for (plugin in plugins.values) { | ||
plugin.onRtcEngineCreated(rtcEngine) | ||
} | ||
} | ||
|
||
override fun onRtcEngineDestroyed() { | ||
for (plugin in plugins.values) { | ||
plugin.onRtcEngineDestroyed() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.