Skip to content

Commit

Permalink
fix record not stop
Browse files Browse the repository at this point in the history
  • Loading branch information
AderanFeng committed Mar 1, 2024
1 parent ebd3aa5 commit 2bd3b33
Show file tree
Hide file tree
Showing 10 changed files with 245 additions and 28 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ dependencies {
// Room
def room_version = "2.4.0-alpha03"
implementation "androidx.room:room-runtime:$room_version"
implementation "androidx.room:room-ktx:$room_version"
kapt "androidx.room:room-compiler:$room_version"

// Concurrent library for asynchronous coroutines
Expand Down
84 changes: 84 additions & 0 deletions app/schemas/io.agora.flat.data.AppDatabase/2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "8e39fc3e9e9f41852f6f4800436c7f89",
"entities": [
{
"tableName": "room_config",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`uuid` TEXT NOT NULL, `enable_video` INTEGER NOT NULL, `enable_audio` INTEGER NOT NULL, PRIMARY KEY(`uuid`))",
"fields": [
{
"fieldPath": "uuid",
"columnName": "uuid",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "enableVideo",
"columnName": "enable_video",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "enableAudio",
"columnName": "enable_audio",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"uuid"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "record_history",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`roomUuid` TEXT NOT NULL, `resourceId` TEXT NOT NULL, `sid` TEXT NOT NULL, `mode` TEXT NOT NULL, PRIMARY KEY(`resourceId`))",
"fields": [
{
"fieldPath": "roomUuid",
"columnName": "roomUuid",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "resourceId",
"columnName": "resourceId",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "sid",
"columnName": "sid",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "mode",
"columnName": "mode",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"resourceId"
],
"autoGenerate": false
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '8e39fc3e9e9f41852f6f4800436c7f89')"
]
}
}
11 changes: 10 additions & 1 deletion app/src/main/java/io/agora/flat/data/AppDatabase.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
package io.agora.flat.data

import androidx.room.AutoMigration
import androidx.room.Database
import androidx.room.RoomDatabase
import io.agora.flat.data.dao.RecordHistoryDao
import io.agora.flat.data.dao.RoomConfigDao
import io.agora.flat.data.model.RecordHistory
import io.agora.flat.data.model.RoomConfig

@Database(entities = [RoomConfig::class], version = 1)
@Database(
entities = [RoomConfig::class, RecordHistory::class],
version = 2,
autoMigrations = [AutoMigration(from = 1, to = 2)]
)
abstract class AppDatabase : RoomDatabase() {
abstract fun roomConfigDao(): RoomConfigDao

abstract fun recordHistoryDao(): RecordHistoryDao
}
25 changes: 25 additions & 0 deletions app/src/main/java/io/agora/flat/data/dao/RecordHistoryDao.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.agora.flat.data.dao

import androidx.room.*
import io.agora.flat.data.model.RecordHistory

@Dao
interface RecordHistoryDao {
@Query("SELECT * FROM record_history")
suspend fun getAll(): List<RecordHistory>

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insert(recordHistory: RecordHistory)

@Query("SELECT * FROM record_history WHERE roomUuid = :roomUuid")
suspend fun getByRoomUuid(roomUuid: String): List<RecordHistory>

@Query("SELECT * FROM record_history WHERE resourceId = :resourceId")
suspend fun getByResourceId(resourceId: String): List<RecordHistory>

@Query("DELETE FROM record_history WHERE roomUuid = :roomUuid")
suspend fun deleteByRoomUuid(roomUuid: String)

@Query("DELETE FROM record_history WHERE resourceId = :resourceId")
suspend fun deleteByResourceId(resourceId: String)
}
13 changes: 13 additions & 0 deletions app/src/main/java/io/agora/flat/data/model/RecordHistory.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.agora.flat.data.model

import androidx.room.Entity
import androidx.room.PrimaryKey

@Entity(tableName = "record_history")
data class RecordHistory(
val roomUuid: String,
@PrimaryKey
val resourceId: String,
val sid: String,
val mode: AgoraRecordMode = AgoraRecordMode.Mix,
)
2 changes: 1 addition & 1 deletion app/src/main/java/io/agora/flat/data/model/RecordReq.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.agora.flat.data.model

data class RecordReq constructor(
data class RecordReq(
val roomUUID: String,
val agoraParams: AgoraRecordParams,
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ class CloudRecordRepository @Inject constructor(

suspend fun queryRecordWithAgora(
roomUUID: String,
resourceId: String, mode: AgoraRecordMode = AgoraRecordMode.Mix,
resourceId: String,
sid: String,
mode: AgoraRecordMode = AgoraRecordMode.Mix,
): Result<RecordQueryRespData> {
return withContext(Dispatchers.IO) {
cloudRecordService.queryRecordWithAgora(
RecordReq(
roomUUID,
AgoraRecordParams(resourceId, mode),
AgoraRecordParams(resourceid = resourceId, mode = mode, sid = sid),
)
).toResult()
}
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/io/agora/flat/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ object AppModule {
@Provides
fun provideRoomConfigDao(db: AppDatabase) = db.roomConfigDao()

@Singleton
@Provides
fun provideRecordHistoryDao(db: AppDatabase) = db.recordHistoryDao()

@Singleton
@Provides
fun providerAppEnv(@ApplicationContext context: Context): AppEnv {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,51 @@ import io.agora.flat.common.android.ClipboardController
import io.agora.flat.common.board.AgoraBoardRoom
import io.agora.flat.common.board.DeviceState
import io.agora.flat.common.rtc.RtcJoinOptions
import io.agora.flat.common.rtm.*
import io.agora.flat.common.rtm.ChatMessage
import io.agora.flat.common.rtm.ClassRtmEvent
import io.agora.flat.common.rtm.EnterRoomEvent
import io.agora.flat.common.rtm.EventUserInfo
import io.agora.flat.common.rtm.ExpirationWarningEvent
import io.agora.flat.common.rtm.Message
import io.agora.flat.common.rtm.MessageFactory
import io.agora.flat.common.rtm.NotifyDeviceOffEvent
import io.agora.flat.common.rtm.OnMemberJoined
import io.agora.flat.common.rtm.OnMemberLeft
import io.agora.flat.common.rtm.OnRemoteLogin
import io.agora.flat.common.rtm.RaiseHandEvent
import io.agora.flat.common.rtm.RequestDeviceEvent
import io.agora.flat.common.rtm.RequestDeviceResponseEvent
import io.agora.flat.common.rtm.RewardEvent
import io.agora.flat.common.rtm.RoomBanEvent
import io.agora.flat.common.rtm.RoomStateEvent
import io.agora.flat.data.AppEnv
import io.agora.flat.data.AppKVCenter
import io.agora.flat.data.model.*
import io.agora.flat.data.model.InviteInfo
import io.agora.flat.data.model.RoomInfo
import io.agora.flat.data.model.RoomPlayInfo
import io.agora.flat.data.model.RoomStatus
import io.agora.flat.data.model.RoomType
import io.agora.flat.data.model.RoomUser
import io.agora.flat.data.model.RtcShareScreen
import io.agora.flat.data.repository.RoomRepository
import io.agora.flat.data.repository.UserRepository
import io.agora.flat.di.interfaces.Logger
import io.agora.flat.di.interfaces.RtcApi
import io.agora.flat.di.interfaces.RtmApi
import io.agora.flat.di.interfaces.SyncedClassState
import io.agora.flat.event.*
import io.agora.flat.event.ClassroomEvent
import io.agora.flat.event.Event
import io.agora.flat.event.EventBus
import io.agora.flat.event.ExpirationEvent
import io.agora.flat.event.MessagesAppended
import io.agora.flat.event.NoOptPermission
import io.agora.flat.event.NotifyDeviceOffReceived
import io.agora.flat.event.RemoteLoginEvent
import io.agora.flat.event.RequestDeviceReceived
import io.agora.flat.event.RequestDeviceResponseReceived
import io.agora.flat.event.RequestDeviceSent
import io.agora.flat.event.RequestMuteAllSent
import io.agora.flat.event.RewardReceived
import io.agora.flat.ui.manager.RecordManager
import io.agora.flat.ui.manager.RoomErrorManager
import io.agora.flat.ui.manager.UserManager
Expand All @@ -31,7 +65,15 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.cancel
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onCompletion
import kotlinx.coroutines.flow.take
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down Expand Up @@ -181,6 +223,7 @@ class ClassRoomViewModel @Inject constructor(
),
ownerUUID = roomInfo.ownerUUID
)

recordManager.reset(roomUUID, viewModelScope)

onStageLimit = when (roomInfo.roomType) {
Expand Down Expand Up @@ -354,11 +397,13 @@ class ClassRoomViewModel @Inject constructor(
}

is ExpirationWarningEvent -> {
eventbus.produceEvent(ExpirationEvent(
roomLevel = event.roomLevel,
expireAt = event.expireAt,
leftMinutes = event.leftMinutes,
))
eventbus.produceEvent(
ExpirationEvent(
roomLevel = event.roomLevel,
expireAt = event.expireAt,
leftMinutes = event.leftMinutes,
)
)
}

else -> {
Expand Down Expand Up @@ -584,6 +629,8 @@ class ClassRoomViewModel @Inject constructor(
if (roomRepository.startRoomClass(roomUUID).isSuccess) {
rtmApi.sendChannelCommand(RoomStateEvent(roomUUID = roomUUID, status = RoomStatus.Started))
_state.value = state.copy(roomStatus = RoomStatus.Started)
} else {
logger.e("start class error")
}
}
}
Expand All @@ -600,7 +647,7 @@ class ClassRoomViewModel @Inject constructor(
val result = roomRepository.stopRoomClass(roomUUID)
if (result.isSuccess) {
rtmApi.sendChannelCommand(RoomStateEvent(roomUUID = roomUUID, status = RoomStatus.Stopped))
recordManager.stopRecord()
recordManager.stopRecord(true)
}
return result.isSuccess
}
Expand Down Expand Up @@ -675,7 +722,7 @@ class ClassRoomViewModel @Inject constructor(
return InviteInfo(
username = currentUserName,
roomTitle = state.title,
link = "${appEnv.baseInviteUrl}/join/$linkCode",
link = "${appEnv.baseInviteUrl}/join/$linkCode",
roomUuid = state.inviteCode.toInviteCodeDisplay(),
beginTime = state.beginTime,
endTime = state.endTime,
Expand Down
Loading

0 comments on commit 2bd3b33

Please sign in to comment.