Skip to content

Commit

Permalink
feat(meeting): map socket hand raising and recording
Browse files Browse the repository at this point in the history
  • Loading branch information
lambiengcode committed Oct 17, 2024
1 parent 0fe025d commit 412aa31
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 8 deletions.
15 changes: 11 additions & 4 deletions lib/constants/socket_events.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class SocketEvent {
// Meeting
static const String publishCSS = 'PUBLISH_CSS';
static const String publishSSC = 'PUBLISH_SSC';
static const String subscribeCSS = 'SUBSCRIBE_CSS';
Expand All @@ -21,19 +22,25 @@ class SocketEvent {
static const String setAudioEnabledSSC = "SET_AUDIO_ENABLED_SSC";
static const String setScreenSharingSSC = "SET_SCREEN_SHARING_SSC";
static const String setScreenSharingCSS = "SET_SCREEN_SHARING_CSS";
static const String handRaisingSSC = 'HAND_RAISING_SSC';
static const String handRaisingCSS = 'HAND_RAISING_CSS';
static const String subtitleSSC = 'SUBTITLE_SSC';
static const String setSubscribeSubtitleCSS = 'SET_SUBSCRIBE_SUBTITLE_CSS';
static const String startRecordSSC = 'START_RECORD_SSC';
static const String stopRecordSSC = 'STOP_RECORD_SSC';

static const String publisherRenegotiationCSS = 'PUBLISHER_RENEGOTIATION_CSS';
static const String publisherRenegotiationSSC = 'PUBLISHER_RENEGOTIATION_SSC';
static const String subscriberRenegotiationSSC =
'SUBSCRIBER_RENEGOTIATION_SSC';

static const String sendPodNameSSC = 'SEND_POD_NAME_SSC';
static const String reconnect = 'reconnect_CSS';
static const String destroy = 'destroy';

// Chats
static const String sendMessageSSC = 'SEND_MESSAGE_SSC';
static const String updateMessageSSC = 'UPDATE_MESSAGE_SSC';
static const String deleteMessageSSC = 'DELETE_MESSAGE_SSC';

// System
static const String sendPodNameSSC = 'SEND_POD_NAME_SSC';
static const String reconnect = 'reconnect_CSS';
static const String destroy = 'destroy';
}
32 changes: 31 additions & 1 deletion lib/core/webrtc/webrtc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
MediaStream? _displayStream;
ParticipantSFU? _mParticipant;
bool _flagPublisherCanAddCandidate = false;
bool _isRecording = false;
CallSetting _callSetting = CallSetting();
final Map<String, ParticipantSFU> _subscribers = {};
final Map<String, List<RTCIceCandidate>> _queueRemoteSubCandidates = {};
Expand Down Expand Up @@ -199,7 +200,9 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
}

@override
Future<void> setPublisherRemoteSdp(String sdp) async {
Future<void> setPublisherRemoteSdp(String sdp, [bool? isRecording]) async {
if (isRecording != null) _isRecording = isRecording;

final RTCSessionDescription description = RTCSessionDescription(
sdp,
DescriptionType.answer.type,
Expand All @@ -223,6 +226,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
required bool audioEnabled,
required bool isScreenSharing,
required bool isE2eeEnabled,
required bool isHandRaising,
required CameraType type,
required WebRTCCodec codec,
}) async {
Expand All @@ -240,6 +244,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
audioEnabled,
isScreenSharing,
isE2eeEnabled,
isHandRaising,
type,
codec,
);
Expand Down Expand Up @@ -456,6 +461,14 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
_notify(CallbackEvents.shouldBeUpdateState);
}

@override
void toggleRaiseHand() {
if (_mParticipant == null) return;

_mParticipant!.isHandRaising = !_mParticipant!.isHandRaising;
_socketEmiter.setHandRaising(_mParticipant!.isHandRaising);
}

@override
Future<void> setE2eeEnabled({
required String targetId,
Expand Down Expand Up @@ -510,6 +523,18 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
_notify(CallbackEvents.shouldBeUpdateState);
}

@override
void setHandRaising({required String targetId, required bool isRaising}) {
_subscribers[targetId]?.isHandRaising = isRaising;
_notify(CallbackEvents.shouldBeUpdateState);
}

@override
void setIsRecording({required bool isRecording}) {
_isRecording = isRecording;
_notify(CallbackEvents.shouldBeUpdateState);
}

@override
Future<void> dispose() async {
try {
Expand Down Expand Up @@ -784,6 +809,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
bool videoEnabled,
bool audioEnabled,
bool isScreenSharing,
bool isHandRaising,
bool isE2eeEnabled,
CameraType type,
WebRTCCodec codec,
Expand All @@ -800,6 +826,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
isVideoEnabled: videoEnabled,
isSharingScreen: isScreenSharing,
isE2eeEnabled: isE2eeEnabled,
isHandRaising: isHandRaising,
cameraType: type,
videoCodec: codec,
stats: _stats,
Expand Down Expand Up @@ -940,4 +967,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {

@override
String? get roomId => _roomId;

@override
bool get isRecording => _isRecording;
}
7 changes: 6 additions & 1 deletion lib/core/webrtc/webrtc_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ abstract class WaterbusWebRTCManager {
Future<void> joinRoom({required String roomId, required int participantId});
Future<void> reconnect();
Future<void> subscribe(List<String> targetIds);
Future<void> setPublisherRemoteSdp(String sdp);
Future<void> setPublisherRemoteSdp(String sdp, [bool? isRecording]);
Future<void> setSubscriberRemoteSdp({
required String targetId,
required String sdp,
required bool videoEnabled,
required bool audioEnabled,
required bool isScreenSharing,
required bool isE2eeEnabled,
required bool isHandRaising,
required CameraType type,
required WebRTCCodec codec,
});
Expand All @@ -39,11 +40,14 @@ abstract class WaterbusWebRTCManager {
Future<void> toggleSpeakerPhone({bool? forceValue});
Future<void> toggleVideo();
Future<void> switchCamera();
void toggleRaiseHand();
void setE2eeEnabled({required String targetId, required bool isEnabled});
void setVideoEnabled({required String targetId, required bool isEnabled});
void setCameraType({required String targetId, required CameraType type});
void setAudioEnabled({required String targetId, required bool isEnabled});
void setScreenSharing({required String targetId, required bool isSharing});
void setHandRaising({required String targetId, required bool isRaising});
void setIsRecording({required bool isRecording});
Future<void> enableVirtualBackground({
required Uint8List backgroundImage,
double thresholdConfidence = 0.7,
Expand All @@ -54,4 +58,5 @@ abstract class WaterbusWebRTCManager {
CallState callState();
Stream<CallbackPayload> get notifyChanged;
String? get roomId;
bool get isRecording;
}
4 changes: 3 additions & 1 deletion lib/core/websocket/interfaces/socket_emiter_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ abstract class SocketEmiter {
void setVideoEnabled(bool isEnabled);
void setAudioEnabled(bool isEnabled);
void setScreenSharing(bool isSharing);
void setSubtitle(bool isEnabled);
void setHandRaising(bool isRaising);

void sendNewSdp(String sdp);
void leaveRoom(String roomId);
void setSubtitle(bool isEnabled);

void reconnect();
}
5 changes: 5 additions & 0 deletions lib/core/websocket/socket_emiter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class SocketEmiterImpl extends SocketEmiter {
_socket?.emit(SocketEvent.setSubscribeSubtitleCSS, {'enabled': isEnabled});
}

@override
void setHandRaising(bool isRaising) {
_socket?.emit(SocketEvent.handRaisingCSS, {'isRaising': isRaising});
}

@override
void reconnect() {
_socket?.emit(SocketEvent.reconnect);
Expand Down
24 changes: 23 additions & 1 deletion lib/core/websocket/socket_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@ class SocketHandlerImpl extends SocketHandler {
if (data == null) return;

final String sdp = data['sdp'];
final bool isRecording = data['isRecording'];

_rtcManager.setPublisherRemoteSdp(sdp);
_rtcManager.setPublisherRemoteSdp(sdp, isRecording);
});

_socket?.on(SocketEvent.newParticipantSSC, (data) {
Expand Down Expand Up @@ -119,6 +120,7 @@ class SocketHandlerImpl extends SocketHandler {
videoEnabled: data['videoEnabled'] ?? false,
isScreenSharing: data['isScreenSharing'] ?? false,
isE2eeEnabled: data['isE2eeEnabled'] ?? false,
isHandRaising: data['isHandRaising'] ?? false,
type: CameraType.values[type],
codec: codec,
);
Expand Down Expand Up @@ -259,6 +261,26 @@ class SocketHandlerImpl extends SocketHandler {
);
});

_socket?.on(SocketEvent.handRaisingSSC, (data) {
if (data == null) return;

final String participantId = data['participantId'];
final bool isRaising = data['isRaising'];

_rtcManager.setHandRaising(
targetId: participantId,
isRaising: isRaising,
);
});

_socket?.on(SocketEvent.startRecordSSC, (data) {
_rtcManager.setIsRecording(isRecording: true);
});

_socket?.on(SocketEvent.stopRecordSSC, (data) {
_rtcManager.setIsRecording(isRecording: false);
});

_socket?.on(SocketEvent.sendPodNameSSC, (data) {
if (data == null) return;

Expand Down
4 changes: 4 additions & 0 deletions lib/types/error/failures.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import 'package:equatable/equatable.dart';

abstract class Failure extends Equatable {
final String? message;

const Failure([this.message]);

@override
List<Object> get props => [];
}
Expand Down
2 changes: 2 additions & 0 deletions lib/types/models/participant_sfu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class ParticipantSFU extends Equatable {
bool isE2eeEnabled;
bool isSpeakerPhoneEnabled;
bool isSharingScreen;
bool isHandRaising;
CameraType cameraType;
AudioLevel audioLevel;
MediaSource? cameraSource;
Expand All @@ -29,6 +30,7 @@ class ParticipantSFU extends Equatable {
this.isSharingScreen = false,
this.isE2eeEnabled = false,
this.isSpeakerPhoneEnabled = true,
this.isHandRaising = false,
this.cameraType = CameraType.front,
this.audioLevel = AudioLevel.kSilence,
required this.peerConnection,
Expand Down
14 changes: 14 additions & 0 deletions lib/types/result.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'package:waterbus_sdk/types/error/failures.dart';

class Result<T> {
final T? value;
final Failure? error;

Result._({this.value, this.error});

bool get isSuccess => value != null;
bool get isFailure => error != null;

static Result<T> success<T>(T value) => Result._(value: value);
static Result<T> failure<T>(Failure error) => Result._(error: error);
}
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies:
web: ^1.0.0
cryptography: ^2.7.0
convert: ^3.1.1
diffutil_dart: ^4.0.1

# WebRTC
sdp_transform: ^0.3.2
Expand Down

0 comments on commit 412aa31

Please sign in to comment.