Skip to content

Commit

Permalink
fix: Conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
chopper985 committed Aug 11, 2024
2 parents 79fb817 + fcdaa76 commit e5ddb64
Show file tree
Hide file tree
Showing 16 changed files with 372 additions and 169 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## 1.4.9

* Chore: remove dependency_overrides

## 1.4.8

* Feat: support flutter wasm

## 1.4.7

* Feat: subtitle

## 1.4.6

* Feat: expose callback sender stats
Expand Down
4 changes: 4 additions & 0 deletions lib/constants/socket_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ class SocketEvent {
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';
}
156 changes: 98 additions & 58 deletions lib/core/webrtc/webrtc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -156,69 +156,39 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {

if (_mParticipant?.peerConnection == null) return;

_roomId = roomId;
_participantId = participantId.toString();

final RTCPeerConnection peerConnection = _mParticipant!.peerConnection;

peerConnection.onRenegotiationNeeded = () async {
String sdp = await _createOffer(peerConnection);

if (_localStream?.getVideoTracks().isNotEmpty ?? false) {
sdp = sdp.enableAudioDTX().setPreferredCodec(
codec: _callSetting.preferedCodec,
);
if (WebRTC.platformIsMobile) {
if (WebRTC.platformIsIOS) {
await Helper.setAppleAudioIOMode(
AppleAudioIOMode.localAndRemote,
preferSpeakerOutput: true,
);
}
await toggleSpeakerPhone(forceValue: true);
}

final RTCSessionDescription description = RTCSessionDescription(
sdp,
DescriptionType.offer.type,
);

await peerConnection.setLocalDescription(description);

_socketEmiter.sendNewSdp(sdp);
};

peerConnection.onIceCandidate = (candidate) {
if (_flagPublisherCanAddCandidate) {
_socketEmiter.sendBroadcastCandidate(candidate);
} else {
_queuePublisherCandidates.add(candidate);
}
};
_roomId = roomId;
_participantId = participantId.toString();

await _enableEncryption(_callSetting.e2eeEnabled);
await _establishBroadcastConnection();

_localStream?.getTracks().forEach((track) {
peerConnection.addTrack(track, _localStream!);
});
_nativeService.startCallKit(roomId.roomCodeFormatted);
}

String sdp = await _createOffer(peerConnection);
@override
Future<void> reconnect() async {
if (_mParticipant == null) return;

if (_localStream?.getVideoTracks().isNotEmpty ?? false) {
sdp = sdp.enableAudioDTX().setPreferredCodec(
codec: _callSetting.preferedCodec,
);
}
_stats.dispose();
_audioStats.dispose();
await _mParticipant?.peerConnection.close();

final RTCSessionDescription description = RTCSessionDescription(
sdp,
DescriptionType.offer.type,
final RTCPeerConnection peerConnection = await _createPeerConnection(
WebRTCConfigurations.offerPublisherSdpConstraints,
);

await peerConnection.setLocalDescription(description);

_socketEmiter.establishBroadcast(
sdp: sdp,
roomId: _roomId!,
participantId: participantId.toString(),
participant: _mParticipant!,
);
_mParticipant = _mParticipant?.copyWith(peerConnection: peerConnection);

_nativeService.startCallKit(roomId.roomCodeFormatted);
_stats.initialize();
_audioStats.initialize();
await _establishBroadcastConnection();
}

@override
Expand Down Expand Up @@ -473,7 +443,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
if (_mParticipant == null) return;

if (WebRTC.platformIsMobile) {
Helper.setSpeakerphoneOn(
await Helper.setSpeakerphoneOn(
forceValue ?? !_mParticipant!.isSpeakerPhoneEnabled,
);
}
Expand Down Expand Up @@ -647,10 +617,6 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {

if (onlyStream) return stream;

if (WebRTC.platformIsMobile) {
await toggleSpeakerPhone(forceValue: true);
}

if (_callSetting.isAudioMuted) {
toggleAudio(forceValue: false);
}
Expand All @@ -676,6 +642,13 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
"video": true,
"audio": false,
};
} else if (WebRTC.platformIsLinux) {
mediaConstraints = {
'video': {
'deviceId': {'exact': source?.id},
'mandatory': {'frameRate': 30.0},
},
};
} else {
mediaConstraints = <String, dynamic>{
'audio': false,
Expand All @@ -698,6 +671,70 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
return stream;
}

Future<void> _establishBroadcastConnection() async {
final RTCPeerConnection peerConnection = _mParticipant!.peerConnection;

peerConnection.onRenegotiationNeeded = () async {
String sdp = await _createOffer(peerConnection);

if (_localStream?.getVideoTracks().isNotEmpty ?? false) {
sdp = sdp.enableAudioDTX().setPreferredCodec(
codec: _callSetting.preferedCodec,
);
}

final RTCSessionDescription description = RTCSessionDescription(
sdp,
DescriptionType.offer.type,
);

await peerConnection.setLocalDescription(description);

_socketEmiter.sendNewSdp(sdp);
};

peerConnection.onIceCandidate = (candidate) {
if (_flagPublisherCanAddCandidate) {
_socketEmiter.sendBroadcastCandidate(candidate);
} else {
_queuePublisherCandidates.add(candidate);
}
};

await _enableEncryption(_callSetting.e2eeEnabled);

_localStream?.getTracks().forEach((track) {
peerConnection.addTrack(track, _localStream!);
});

String sdp = await _createOffer(peerConnection);

if (_localStream?.getVideoTracks().isNotEmpty ?? false) {
sdp = sdp.enableAudioDTX().setPreferredCodec(
codec: _callSetting.preferedCodec,
);
}

final RTCSessionDescription description = RTCSessionDescription(
sdp,
DescriptionType.offer.type,
);

await peerConnection.setLocalDescription(description);

_socketEmiter.establishBroadcast(
sdp: sdp,
roomId: _roomId!,
participantId: _participantId!,
participant: _mParticipant!,
);

if (WebRTC.platformIsLinux) return;

_stats.initialize();
_audioStats.initialize();
}

Future<RTCPeerConnection> _createPeerConnection([
Map<String, dynamic> constraints = const {},
]) async {
Expand Down Expand Up @@ -898,4 +935,7 @@ class WaterbusWebRTCManagerIpml extends WaterbusWebRTCManager {
participants: _subscribers,
);
}

@override
String? get roomId => _roomId;
}
3 changes: 3 additions & 0 deletions lib/core/webrtc/webrtc_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:waterbus_sdk/flutter_waterbus_sdk.dart';

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> setSubscriberRemoteSdp({
Expand Down Expand Up @@ -49,6 +50,8 @@ abstract class WaterbusWebRTCManager {
});
Future<void> disableVirtualBackground({bool reset = false});

// Getter
CallState callState();
Stream<CallbackPayload> get notifyChanged;
String? get roomId;
}
3 changes: 3 additions & 0 deletions lib/core/websocket/interfaces/socket_emiter_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ abstract class SocketEmiter {
void setScreenSharing(bool isSharing);
void sendNewSdp(String sdp);
void leaveRoom(String roomId);
void setSubtitle(bool isEnabled);

void reconnect();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:socket_io_client/socket_io_client.dart';
abstract class SocketHandler {
void establishConnection({bool forceConnection = false});
void disconnection();
void reconnect({required Function callbackConnected});

Socket? get socket;

Expand Down
10 changes: 10 additions & 0 deletions lib/core/websocket/socket_emiter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,15 @@ class SocketEmiterImpl extends SocketEmiter {
_socket?.emit(SocketEvent.publisherRenegotiationCSS, {'sdp': sdp});
}

@override
void setSubtitle(bool isEnabled) {
_socket?.emit(SocketEvent.setSubscribeSubtitleCSS, {'enabled': isEnabled});
}

@override
void reconnect() {
_socket?.emit(SocketEvent.reconnect);
}

Socket? get _socket => getIt<SocketHandler>().socket;
}
45 changes: 45 additions & 0 deletions lib/core/websocket/socket_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ class SocketHandlerImpl extends SocketHandler {
);

Socket? _socket;
String _podName = '';

@override
void establishConnection({
bool forceConnection = false,
int numberOfRetries = 3,
String? forceAccessToken,
Function? callbackConnected,
}) {
if (_authLocal.accessToken.isEmpty ||
(_socket != null && !forceConnection)) {
Expand Down Expand Up @@ -72,6 +74,8 @@ class SocketHandlerImpl extends SocketHandler {
});

_socket?.onConnect((_) async {
callbackConnected?.call();

_logger.log('established connection - sid: ${_socket?.id}');

_socket?.on(SocketEvent.publishSSC, (data) {
Expand Down Expand Up @@ -242,6 +246,37 @@ class SocketHandlerImpl extends SocketHandler {
sdp: sdp,
);
});

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

final participantId = data['participantId'];
final content = data['transcription'];

WaterbusSdk.onSubtitle?.call(
Subtitle(participant: participantId, content: content),
);
});

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

_podName = data['podName'];
});

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

final String podName = data['podName'];

if (_podName == podName && _rtcManager.roomId != null) {
reconnect(
callbackConnected: () {
_rtcManager.reconnect();
},
);
}
});
});
}

Expand All @@ -251,6 +286,16 @@ class SocketHandlerImpl extends SocketHandler {

_socket?.disconnect();
_socket = null;
_podName = '';
}

@override
void reconnect({required Function callbackConnected}) {
disconnection();
establishConnection(
forceConnection: true,
callbackConnected: callbackConnected,
);
}

@override
Expand Down
Loading

0 comments on commit e5ddb64

Please sign in to comment.