|
|
@ -6,7 +6,6 @@ import 'package:flutter/foundation.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
import 'package:get/get.dart'; |
|
|
|
|
|
|
|
|
import '../controller/discover/room_controller.dart'; |
|
|
import '../controller/discover/room_controller.dart'; |
|
|
import '../network/network_service.dart'; |
|
|
|
|
|
import '../pages/discover/live_room_page.dart'; |
|
|
import '../pages/discover/live_room_page.dart'; |
|
|
|
|
|
|
|
|
/// RTC 管理器,负责管理声网音视频通话功能 |
|
|
/// RTC 管理器,负责管理声网音视频通话功能 |
|
|
@ -119,6 +118,16 @@ class RTCManager { |
|
|
channelJoinedNotifier.value = true; |
|
|
channelJoinedNotifier.value = true; |
|
|
_currentChannelId = connection.channelId; |
|
|
_currentChannelId = connection.channelId; |
|
|
print('加入频道成功,频道名:${connection.channelId},耗时:${elapsed}ms'); |
|
|
print('加入频道成功,频道名:${connection.channelId},耗时:${elapsed}ms'); |
|
|
|
|
|
|
|
|
|
|
|
// 调用 RoomController 的 fetchRtcChannelDetail 方法 |
|
|
|
|
|
final channelId = connection.channelId; |
|
|
|
|
|
if (Get.isRegistered<RoomController>() && |
|
|
|
|
|
channelId != null && |
|
|
|
|
|
channelId.isNotEmpty) { |
|
|
|
|
|
final roomController = Get.find<RoomController>(); |
|
|
|
|
|
await roomController.fetchRtcChannelDetail(channelId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (connection.localUid == _currentUid) { |
|
|
if (connection.localUid == _currentUid) { |
|
|
await RTMManager.instance.subscribe(_currentChannelId ?? ''); |
|
|
await RTMManager.instance.subscribe(_currentChannelId ?? ''); |
|
|
await RTMManager.instance.publishChannelMessage( |
|
|
await RTMManager.instance.publishChannelMessage( |
|
|
@ -131,21 +140,42 @@ class RTCManager { |
|
|
onJoinChannelSuccess!(connection, elapsed); |
|
|
onJoinChannelSuccess!(connection, elapsed); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
onUserJoined: (RtcConnection connection, int remoteUid, int elapsed) async{ |
|
|
|
|
|
print('用户加入,UID:$remoteUid'); |
|
|
|
|
|
_handleRemoteUserJoined(remoteUid); |
|
|
|
|
|
if (onUserJoined != null) { |
|
|
|
|
|
onUserJoined!(connection, remoteUid, elapsed); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
onUserJoined: |
|
|
|
|
|
(RtcConnection connection, int remoteUid, int elapsed) async { |
|
|
|
|
|
print('用户加入,UID:$remoteUid'); |
|
|
|
|
|
_handleRemoteUserJoined(remoteUid); |
|
|
|
|
|
|
|
|
|
|
|
// 调用 RoomController 的 fetchRtcChannelDetail 方法 |
|
|
|
|
|
final channelId = connection.channelId; |
|
|
|
|
|
if (Get.isRegistered<RoomController>() && |
|
|
|
|
|
channelId != null && |
|
|
|
|
|
channelId.isNotEmpty) { |
|
|
|
|
|
final roomController = Get.find<RoomController>(); |
|
|
|
|
|
await roomController.fetchRtcChannelDetail(channelId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (onUserJoined != null) { |
|
|
|
|
|
onUserJoined!(connection, remoteUid, elapsed); |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
onUserOffline: |
|
|
onUserOffline: |
|
|
( |
|
|
( |
|
|
RtcConnection connection, |
|
|
RtcConnection connection, |
|
|
int remoteUid, |
|
|
int remoteUid, |
|
|
UserOfflineReasonType reason, |
|
|
UserOfflineReasonType reason, |
|
|
) { |
|
|
|
|
|
|
|
|
) async { |
|
|
print('用户离开,UID:$remoteUid,原因:$reason'); |
|
|
print('用户离开,UID:$remoteUid,原因:$reason'); |
|
|
_handleRemoteUserOffline(remoteUid); |
|
|
_handleRemoteUserOffline(remoteUid); |
|
|
|
|
|
|
|
|
|
|
|
// 调用 RoomController 的 fetchRtcChannelDetail 方法 |
|
|
|
|
|
final channelId = connection.channelId; |
|
|
|
|
|
if (Get.isRegistered<RoomController>() && |
|
|
|
|
|
channelId != null && |
|
|
|
|
|
channelId.isNotEmpty) { |
|
|
|
|
|
final roomController = Get.find<RoomController>(); |
|
|
|
|
|
await roomController.fetchRtcChannelDetail(channelId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if (onUserOffline != null) { |
|
|
if (onUserOffline != null) { |
|
|
onUserOffline!(connection, remoteUid, reason); |
|
|
onUserOffline!(connection, remoteUid, reason); |
|
|
} |
|
|
} |
|
|
@ -521,8 +551,13 @@ class RTCManager { |
|
|
await _engine?.muteLocalVideoStream(true); |
|
|
await _engine?.muteLocalVideoStream(true); |
|
|
await RTMManager.instance.publishChannelMessage( |
|
|
await RTMManager.instance.publishChannelMessage( |
|
|
channelName: _currentChannelId ?? '', |
|
|
channelName: _currentChannelId ?? '', |
|
|
message: json.encode({'type': 'leave_chat', 'uid': _currentUid, 'role': role == CurrentRole.maleAudience |
|
|
|
|
|
? 'male_audience' : 'female_audience',}), |
|
|
|
|
|
|
|
|
message: json.encode({ |
|
|
|
|
|
'type': 'leave_chat', |
|
|
|
|
|
'uid': _currentUid, |
|
|
|
|
|
'role': role == CurrentRole.maleAudience |
|
|
|
|
|
? 'male_audience' |
|
|
|
|
|
: 'female_audience', |
|
|
|
|
|
}), |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |