Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
xuning
/
livekitAndroidXuningTest
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
davidliu
2024-01-11 17:42:56 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Committed by
GitHub
2024-01-11 17:42:56 +0900
Commit
2d924ee7438356d2d46721dfe92f79bdeb03e667
2d924ee7
1 parent
e58f9edd
Remove deprecated methods and unused classes (#356)
隐藏空白字符变更
内嵌
并排对比
正在显示
6 个修改的文件
包含
9 行增加
和
358 行删除
livekit-android-sdk/src/main/java/io/livekit/android/room/DeviceManager.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/Room.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/participant/Participant.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/participant/RemoteParticipant.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/track/LocalVideoTrackOptions.kt
livekit-android-sdk/src/test/java/io/livekit/android/room/participant/ParticipantTest.kt
livekit-android-sdk/src/main/java/io/livekit/android/room/DeviceManager.kt
已删除
100644 → 0
查看文件 @
e58f9ed
/*
* Copyright 2023-2024 LiveKit, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.livekit.android.room
import android.content.Context
import android.hardware.camera2.CameraManager
import android.os.Handler
import android.os.Looper
import livekit.org.webrtc.Camera1Enumerator
import livekit.org.webrtc.Camera2Enumerator
object DeviceManager {
enum class Kind {
// Only camera input currently, audio input/output only has one option atm.
CAMERA,
}
private val defaultDevices = mutableMapOf<Kind, String>()
private val listeners =
mutableMapOf<Kind, MutableList<OnDeviceAvailabilityChangeListener>>()
private var hasSetupListeners = false
@Synchronized
internal fun setupListenersIfNeeded(context: Context) {
if (hasSetupListeners) {
return
}
hasSetupListeners = true
val cameraManager = context.getSystemService(Context.CAMERA_SERVICE) as CameraManager
cameraManager.registerAvailabilityCallback(
object : CameraManager.AvailabilityCallback() {
override fun onCameraAvailable(cameraId: String) {
notifyListeners(Kind.CAMERA)
}
override fun onCameraUnavailable(cameraId: String) {
notifyListeners(Kind.CAMERA)
}
override fun onCameraAccessPrioritiesChanged() {
notifyListeners(Kind.CAMERA)
}
},
Handler(Looper.getMainLooper()),
)
}
fun getDefaultDevice(kind: Kind): String? {
return defaultDevices[kind]
}
fun setDefaultDevice(kind: Kind, deviceId: String?) {
if (deviceId != null) {
defaultDevices[kind] = deviceId
} else {
defaultDevices.remove(kind)
}
}
/**
* @return the list of device ids for [kind]
*/
fun getDevices(context: Context, kind: Kind): List<String> {
return when (kind) {
Kind.CAMERA -> {
val cameraEnumerator = if (Camera2Enumerator.isSupported(context)) {
Camera2Enumerator(context)
} else {
Camera1Enumerator()
}
cameraEnumerator.deviceNames.toList()
}
}
}
fun registerOnDeviceAvailabilityChange(
kind: Kind,
listener: OnDeviceAvailabilityChangeListener,
) {
if (listeners[kind] == null) {
listeners[kind] = mutableListOf()
}
listeners[kind]!!.add(listener)
}
fun unregisterOnDeviceAvailabilityChange(
kind: Kind,
listener: OnDeviceAvailabilityChangeListener,
) {
listeners[kind]?.remove(listener)
}
private fun notifyListeners(kind: Kind) {
listeners[kind]?.forEach {
it.onDeviceAvailabilityChanged(kind)
}
}
interface OnDeviceAvailabilityChangeListener {
fun onDeviceAvailabilityChanged(kind: Kind)
}
}
livekit-android-sdk/src/main/java/io/livekit/android/room/Room.kt
查看文件 @
2d924ee
...
...
@@ -53,7 +53,6 @@ import livekit.LivekitModels
import livekit.LivekitRtc
import livekit.org.webrtc.*
import javax.inject.Named
import kotlin.jvm.Throws
class Room
@AssistedInject
...
...
@@ -101,9 +100,6 @@ constructor(
@JvmInline
value class Sid(val sid: String)
@Deprecated("Use events instead.")
var listener: RoomListener? = null
/**
* The session id of the room.
*
...
...
@@ -287,7 +283,6 @@ constructor(
)
is ParticipantEvent.MetadataChanged -> {
listener?.onMetadataChanged(it.participant, it.prevMetadata, this@Room)
emitWhenConnected(
RoomEvent.ParticipantMetadataChanged(
this@Room,
...
...
@@ -386,8 +381,7 @@ constructor(
}
if (!response.hasParticipant()) {
listener?.onFailedToConnect(this, RoomException.ConnectException("server didn't return any participants"))
return
throw RoomException.ConnectException("server didn't return a local participant")
}
localParticipant.updateFromInfo(response.participant)
...
...
@@ -407,7 +401,6 @@ constructor(
}
mutableRemoteParticipants = newParticipants
listener?.onParticipantDisconnected(this, removedParticipant)
eventBus.postEvent(RoomEvent.ParticipantDisconnected(this, removedParticipant), coroutineScope)
}
...
...
@@ -481,7 +474,6 @@ constructor(
)
is ParticipantEvent.MetadataChanged -> {
listener?.onMetadataChanged(it.participant, it.prevMetadata, this@Room)
emitWhenConnected(
RoomEvent.ParticipantMetadataChanged(
this@Room,
...
...
@@ -553,7 +545,6 @@ constructor(
}
mutableActiveSpeakers = speakers.toList()
listener?.onActiveSpeakersChanged(mutableActiveSpeakers, this)
eventBus.postEvent(RoomEvent.ActiveSpeakersChanged(this, mutableActiveSpeakers), coroutineScope)
}
...
...
@@ -581,7 +572,6 @@ constructor(
.sortedBy { it.audioLevel }
mutableActiveSpeakers = updatedSpeakersList.toList()
listener?.onActiveSpeakersChanged(mutableActiveSpeakers, this)
eventBus.postEvent(RoomEvent.ActiveSpeakersChanged(this, mutableActiveSpeakers), coroutineScope)
}
...
...
@@ -625,8 +615,6 @@ constructor(
cleanupRoom()
engine.close()
listener?.onDisconnect(this, null)
listener = null
localParticipant.dispose()
// Ensure all observers see the disconnected before closing scope.
...
...
@@ -742,7 +730,6 @@ constructor(
*/
override fun onEngineReconnected() {
state = State.CONNECTED
listener?.onReconnected(this)
eventBus.postEvent(RoomEvent.Reconnected(this), coroutineScope)
}
...
...
@@ -751,7 +738,6 @@ constructor(
*/
override fun onEngineReconnecting() {
state = State.RECONNECTING
listener?.onReconnecting(this)
eventBus.postEvent(RoomEvent.Reconnecting(this), coroutineScope)
}
...
...
@@ -818,7 +804,6 @@ constructor(
} else {
val participant = getOrCreateRemoteParticipant(participantIdentity, info)
if (isNewParticipant) {
listener?.onParticipantConnected(this, participant)
eventBus.postEvent(RoomEvent.ParticipantConnected(this, participant), coroutineScope)
} else {
participant.updateFromInfo(info)
...
...
@@ -872,7 +857,6 @@ constructor(
val quality = ConnectionQuality.fromProto(info.quality)
val participant = getParticipantBySid(info.participantSid) ?: return
participant.connectionQuality = quality
listener?.onConnectionQualityChanged(participant, quality)
eventBus.postEvent(RoomEvent.ConnectionQualityChanged(this, participant, quality), coroutineScope)
}
}
...
...
@@ -896,7 +880,6 @@ constructor(
null
}
listener?.onDataReceived(data, participant, this)
eventBus.postEvent(RoomEvent.DataReceived(this, data, participant, topic), coroutineScope)
participant?.onDataReceived(data, topic)
}
...
...
@@ -940,7 +923,6 @@ constructor(
* @suppress
*/
override fun onFailToConnect(error: Throwable) {
listener?.onFailedToConnect(this, error)
// scope will likely be closed already here, so force it out of scope.
eventBus.tryPostEvent(RoomEvent.FailedToConnect(this, error))
}
...
...
@@ -1001,13 +983,11 @@ constructor(
/** @suppress */
override fun onTrackMuted(publication: TrackPublication, participant: Participant) {
listener?.onTrackMuted(publication, participant, this)
eventBus.postEvent(RoomEvent.TrackMuted(this, publication, participant), coroutineScope)
}
/** @suppress */
override fun onTrackUnmuted(publication: TrackPublication, participant: Participant) {
listener?.onTrackUnmuted(publication, participant, this)
eventBus.postEvent(RoomEvent.TrackUnmuted(this, publication, participant), coroutineScope)
}
...
...
@@ -1015,7 +995,6 @@ constructor(
* @suppress
*/
override fun onTrackUnpublished(publication: RemoteTrackPublication, participant: RemoteParticipant) {
listener?.onTrackUnpublished(publication, participant, this)
eventBus.postEvent(RoomEvent.TrackUnpublished(this, publication, participant), coroutineScope)
}
...
...
@@ -1023,7 +1002,6 @@ constructor(
* @suppress
*/
override fun onTrackPublished(publication: LocalTrackPublication, participant: LocalParticipant) {
listener?.onTrackPublished(publication, participant, this)
if (e2eeManager != null) {
e2eeManager!!.addPublishedTrack(publication.track!!, publication, participant, this)
}
...
...
@@ -1034,7 +1012,6 @@ constructor(
* @suppress
*/
override fun onTrackUnpublished(publication: LocalTrackPublication, participant: LocalParticipant) {
listener?.onTrackUnpublished(publication, participant, this)
e2eeManager?.let { e2eeManager ->
e2eeManager!!.removePublishedTrack(publication.track!!, publication, participant, this)
}
...
...
@@ -1045,7 +1022,6 @@ constructor(
* @suppress
*/
override fun onTrackSubscribed(track: Track, publication: RemoteTrackPublication, participant: RemoteParticipant) {
listener?.onTrackSubscribed(track, publication, participant, this)
if (e2eeManager != null) {
e2eeManager!!.addSubscribedTrack(track, publication, participant, this)
}
...
...
@@ -1060,7 +1036,6 @@ constructor(
exception: Exception,
participant: RemoteParticipant,
) {
listener?.onTrackSubscriptionFailed(sid, exception, participant, this)
eventBus.postEvent(RoomEvent.TrackSubscriptionFailed(this, sid, exception, participant), coroutineScope)
}
...
...
@@ -1072,7 +1047,6 @@ constructor(
publication: RemoteTrackPublication,
participant: RemoteParticipant,
) {
listener?.onTrackUnsubscribed(track, publication, participant, this)
e2eeManager?.let { e2eeManager ->
e2eeManager!!.removeSubscribedTrack(track, publication, participant, this)
}
...
...
@@ -1080,8 +1054,9 @@ constructor(
}
/**
*
// TODO(@dl): can this be moved out of Room/SDK?
*
Initialize a [SurfaceViewRenderer] for rendering a video from this room.
*/
// TODO(@dl): can this be moved out of Room/SDK?
fun initVideoRenderer(viewRenderer: SurfaceViewRenderer) {
viewRenderer.init(eglBase.eglBaseContext, null)
viewRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT)
...
...
@@ -1089,8 +1064,9 @@ constructor(
}
/**
*
// TODO(@dl): can this be moved out of Room/SDK?
*
Initialize a [TextureViewRenderer] for rendering a video from this room.
*/
// TODO(@dl): can this be moved out of Room/SDK?
fun initVideoRenderer(viewRenderer: TextureViewRenderer) {
viewRenderer.init(eglBase.eglBaseContext, null)
viewRenderer.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT)
...
...
@@ -1130,136 +1106,6 @@ constructor(
}
}
/**
* Room Listener, this class provides callbacks that clients should override.
*
*/
@Deprecated("Use Room.events instead")
interface RoomListener {
/**
* A network change has been detected and LiveKit attempts to reconnect to the room
* When reconnect attempts succeed, the room state will be kept, including tracks that are subscribed/published
*/
fun onReconnecting(room: Room) {}
/**
* The reconnect attempt had been successful
*/
fun onReconnected(room: Room) {}
/**
* Disconnected from room
*/
fun onDisconnect(room: Room, error: Exception?) {}
/**
* When a [RemoteParticipant] joins after the local participant. It will not emit events
* for participants that are already in the room
*/
fun onParticipantConnected(room: Room, participant: RemoteParticipant) {}
/**
* When a [RemoteParticipant] leaves after the local participant has joined.
*/
fun onParticipantDisconnected(room: Room, participant: RemoteParticipant) {}
/**
* Could not connect to the room
*/
fun onFailedToConnect(room: Room, error: Throwable) {}
/**
* Active speakers changed. List of speakers are ordered by their audio level. loudest
* speakers first. This will include the [LocalParticipant] too.
*/
fun onActiveSpeakersChanged(speakers: List<Participant>, room: Room) {}
// Participant callbacks
/**
* Participant metadata is a simple way for app-specific state to be pushed to all users.
* When RoomService.UpdateParticipantMetadata is called to change a participant's state,
* this event will be fired for all clients in the room.
*/
fun onMetadataChanged(participant: Participant, prevMetadata: String?, room: Room) {}
/**
* The participant was muted.
*
* For the local participant, the callback will be called if setMute was called on the
* [LocalTrackPublication], or if the server has requested the participant to be muted
*/
fun onTrackMuted(publication: TrackPublication, participant: Participant, room: Room) {}
/**
* The participant was unmuted.
*
* For the local participant, the callback will be called if setMute was called on the
* [LocalTrackPublication], or if the server has requested the participant to be muted
*/
fun onTrackUnmuted(publication: TrackPublication, participant: Participant, room: Room) {}
/**
* When a new track is published to room after the local participant has joined. It will
* not fire for tracks that are already published
*/
fun onTrackPublished(publication: RemoteTrackPublication, participant: RemoteParticipant, room: Room) {}
/**
* A [RemoteParticipant] has unpublished a track
*/
fun onTrackUnpublished(publication: RemoteTrackPublication, participant: RemoteParticipant, room: Room) {}
/**
* When a new track is published to room after the local participant has joined.
*/
fun onTrackPublished(publication: LocalTrackPublication, participant: LocalParticipant, room: Room) {}
/**
* [LocalParticipant] has unpublished a track
*/
fun onTrackUnpublished(publication: LocalTrackPublication, participant: LocalParticipant, room: Room) {}
/**
* The [LocalParticipant] has subscribed to a new track. This event will always fire as
* long as new tracks are ready for use.
*/
fun onTrackSubscribed(track: Track, publication: TrackPublication, participant: RemoteParticipant, room: Room) {}
/**
* Could not subscribe to a track
*/
fun onTrackSubscriptionFailed(sid: String, exception: Exception, participant: RemoteParticipant, room: Room) {}
/**
* A subscribed track is no longer available. Clients should listen to this event and ensure
* the track removes all renderers
*/
fun onTrackUnsubscribed(track: Track, publications: TrackPublication, participant: RemoteParticipant, room: Room) {}
/**
* Received data published by another participant
*/
fun onDataReceived(data: ByteArray, participant: RemoteParticipant?, room: Room) {}
/**
* The connection quality for a participant has changed.
*
* @param participant Either a remote participant or [Room.localParticipant]
* @param quality the new connection quality
*/
fun onConnectionQualityChanged(participant: Participant, quality: ConnectionQuality) {}
companion object {
fun getDefaultDevice(kind: DeviceManager.Kind): String? {
return DeviceManager.getDefaultDevice(kind)
}
fun setDefaultDevice(kind: DeviceManager.Kind, deviceId: String?) {
DeviceManager.setDefaultDevice(kind, deviceId)
}
}
}
sealed class RoomException(message: String? = null, cause: Throwable? = null) :
Exception(message, cause) {
class ConnectException(message: String? = null, cause: Throwable? = null) :
...
...
livekit-android-sdk/src/main/java/io/livekit/android/room/participant/Participant.kt
查看文件 @
2d924ee
...
...
@@ -92,7 +92,6 @@ open class Participant(
@get:FlowObservable
var isSpeaking: Boolean by flowDelegate(false) { newValue, oldValue ->
if (newValue != oldValue) {
listener?.onSpeakingChanged(this)
internalListener?.onSpeakingChanged(this)
eventBus.postEvent(ParticipantEvent.SpeakingChanged(this, newValue), scope)
if (newValue) {
...
...
@@ -118,7 +117,6 @@ open class Participant(
@get:FlowObservable
var metadata: String? by flowDelegate(null) { newMetadata, oldMetadata ->
if (newMetadata != oldMetadata) {
listener?.onMetadataChanged(this, oldMetadata)
internalListener?.onMetadataChanged(this, oldMetadata)
eventBus.postEvent(ParticipantEvent.MetadataChanged(this, oldMetadata), scope)
}
...
...
@@ -167,12 +165,6 @@ open class Participant(
internal set
/**
* Listener for when participant properties change
*/
@Deprecated("Use events instead")
var listener: ParticipantListener? = null
/**
* @suppress
*/
@Deprecated("Use events instead")
...
...
@@ -336,13 +328,11 @@ open class Participant(
// Internal methods just for posting events.
internal fun onTrackMuted(trackPublication: TrackPublication) {
listener?.onTrackMuted(trackPublication, this)
internalListener?.onTrackMuted(trackPublication, this)
eventBus.postEvent(ParticipantEvent.TrackMuted(this, trackPublication), scope)
}
internal fun onTrackUnmuted(trackPublication: TrackPublication) {
listener?.onTrackUnmuted(trackPublication, this)
internalListener?.onTrackUnmuted(trackPublication, this)
eventBus.postEvent(ParticipantEvent.TrackUnmuted(this, trackPublication), scope)
}
...
...
@@ -374,6 +364,9 @@ open class Participant(
}
}
/**
* @suppress
*/
@Deprecated("Use Participant.events instead.")
interface ParticipantListener {
// all participants
...
...
livekit-android-sdk/src/main/java/io/livekit/android/room/participant/RemoteParticipant.kt
查看文件 @
2d924ee
...
...
@@ -101,7 +101,6 @@ class RemoteParticipant(
for (publication in newTrackPublications.values) {
internalListener?.onTrackPublished(publication, this)
listener?.onTrackPublished(publication, this)
eventBus.postEvent(ParticipantEvent.TrackPublished(this, publication), scope)
}
...
...
@@ -133,7 +132,6 @@ class RemoteParticipant(
LKLog.e { "remote participant ${this.sid} --- $message" }
internalListener?.onTrackSubscriptionFailed(sid, exception, this)
listener?.onTrackSubscriptionFailed(sid, exception, this)
eventBus.postEvent(ParticipantEvent.TrackSubscriptionFailed(this, sid, exception), scope)
} else {
coroutineScope.launch {
...
...
@@ -170,7 +168,6 @@ class RemoteParticipant(
// TODO: how does mediatrack send ended event?
internalListener?.onTrackSubscribed(track, publication, this)
listener?.onTrackSubscribed(track, publication, this)
eventBus.postEvent(ParticipantEvent.TrackSubscribed(this, track, publication), scope)
}
...
...
@@ -186,12 +183,10 @@ class RemoteParticipant(
// track may already be disposed, ignore.
}
internalListener?.onTrackUnsubscribed(track, publication, this)
listener?.onTrackUnsubscribed(track, publication, this)
eventBus.postEvent(ParticipantEvent.TrackUnsubscribed(this, track, publication), scope)
}
if (sendUnpublish) {
internalListener?.onTrackUnpublished(publication, this)
listener?.onTrackUnpublished(publication, this)
eventBus.postEvent(ParticipantEvent.TrackUnpublished(this, publication), scope)
}
publication.track = null
...
...
@@ -212,7 +207,6 @@ class RemoteParticipant(
// Internal methods just for posting events.
internal fun onDataReceived(data: ByteArray, topic: String?) {
listener?.onDataReceived(data, this)
eventBus.postEvent(ParticipantEvent.DataReceived(this, data, topic), scope)
}
...
...
livekit-android-sdk/src/main/java/io/livekit/android/room/track/LocalVideoTrackOptions.kt
查看文件 @
2d924ee
...
...
@@ -26,7 +26,7 @@ data class LocalVideoTrackOptions(
*/
val deviceId: String? = null,
val position: CameraPosition? = CameraPosition.FRONT,
val captureParams: VideoCaptureParameter = VideoPreset169.
QHD
.capture,
val captureParams: VideoCaptureParameter = VideoPreset169.
H540
.capture,
)
data class VideoCaptureParameter(
...
...
@@ -126,36 +126,6 @@ enum class VideoPreset169(
VideoCaptureParameter(3840, 2160, 30),
VideoEncoding(8_000_000, 30),
),
@Deprecated("QVGA is deprecated, use H180 instead")
QVGA(
VideoCaptureParameter(320, 180, 15),
VideoEncoding(125_000, 15),
),
@Deprecated("VGA is deprecated, use H360 instead")
VGA(
VideoCaptureParameter(640, 360, 30),
VideoEncoding(400_000, 30),
),
@Deprecated("QHD is deprecated, use H540 instead")
QHD(
VideoCaptureParameter(960, 540, 30),
VideoEncoding(800_000, 30),
),
@Deprecated("HD is deprecated, use H720 instead")
HD(
VideoCaptureParameter(1280, 720, 30),
VideoEncoding(2_500_000, 30),
),
@Deprecated("FHD is deprecated, use H1080 instead")
FHD(
VideoCaptureParameter(1920, 1080, 30),
VideoEncoding(4_000_000, 30),
),
}
/**
...
...
@@ -201,34 +171,4 @@ enum class VideoPreset43(
VideoCaptureParameter(1920, 1440, 30),
VideoEncoding(3_800_000, 30),
),
@Deprecated("QVGA is deprecated, use H120 instead")
QVGA(
VideoCaptureParameter(240, 180, 15),
VideoEncoding(100_000, 15),
),
@Deprecated("VGA is deprecated, use H360 instead")
VGA(
VideoCaptureParameter(480, 360, 30),
VideoEncoding(320_000, 30),
),
@Deprecated("QHD is deprecated, use H540 instead")
QHD(
VideoCaptureParameter(720, 540, 30),
VideoEncoding(640_000, 30),
),
@Deprecated("HD is deprecated, use H720 instead")
HD(
VideoCaptureParameter(960, 720, 30),
VideoEncoding(2_000_000, 30),
),
@Deprecated("FHD is deprecated, use H1080 instead")
FHD(
VideoCaptureParameter(1440, 1080, 30),
VideoEncoding(3_200_000, 30),
),
}
...
...
livekit-android-sdk/src/test/java/io/livekit/android/room/participant/ParticipantTest.kt
查看文件 @
2d924ee
...
...
@@ -72,10 +72,8 @@ class ParticipantTest {
}
}
val publicListener = MetadataListener()
val internalListener = MetadataListener()
participant.listener = publicListener
participant.internalListener = internalListener
val prevMetadata = participant.metadata
...
...
@@ -88,7 +86,6 @@ class ParticipantTest {
assertEquals(prevMetadata, listener.prevMetadataValue)
}
checkValues(publicListener)
checkValues(internalListener)
}
...
...
请
注册
或
登录
后发表评论