Skip to content

Commit

Permalink
Merge pull request #11 from waterbustech/feat/subtitle
Browse files Browse the repository at this point in the history
feat(subtitle): handle socket event subtitle
  • Loading branch information
lambiengcode authored Jul 22, 2024
2 parents e3b72df + bf2f615 commit a852966
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 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,5 @@ abstract class SocketEmiter {
void setScreenSharing(bool isSharing);
void sendNewSdp(String sdp);
void leaveRoom(String roomId);
void setSubtitle(bool isEnabled);
}
5 changes: 5 additions & 0 deletions lib/core/websocket/socket_emiter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,10 @@ class SocketEmiterImpl extends SocketEmiter {
_socket?.emit(SocketEvent.publisherRenegotiationCSS, {'sdp': sdp});
}

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

Socket? get _socket => getIt<SocketHandler>().socket;
}
11 changes: 11 additions & 0 deletions lib/core/websocket/socket_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,17 @@ 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),
);
});
});
}

Expand Down
11 changes: 10 additions & 1 deletion lib/flutter_waterbus_sdk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@ class WaterbusSdk {
static String apiKey = '';
static Function(CallbackPayload)? onEventChanged;
static Function(VideoSenderStats)? onStatsChanged;
static Function(Subtitle)? onSubtitle;

set onEventChangedRegister(Function(CallbackPayload) onEventChanged) {
WaterbusSdk.onEventChanged = onEventChanged;
}

setStatsChanged(Function(VideoSenderStats)? onStatsChanged) {
set setStatsChanged(Function(VideoSenderStats)? onStatsChanged) {
WaterbusSdk.onStatsChanged = onStatsChanged;
}

set setOnSubtitle(Function(Subtitle)? onSubtitle) {
WaterbusSdk.onSubtitle = onSubtitle;
}

Future<void> initializeApp({
required String wsUrl,
required String apiUrl,
Expand Down Expand Up @@ -127,6 +132,10 @@ class WaterbusSdk {
await _sdk.toggleSpeakerPhone();
}

void setSubscribeSubtitle({bool isEnabled = true}) {
_sdk.setSubscribeSubtitle(isEnabled);
}

Future<void> changeCallSetting(CallSetting setting) async {
await _sdk.changeCallSettings(setting);
}
Expand Down
1 change: 1 addition & 0 deletions lib/injection/injection_container.config.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/types/models/index.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export 'avatar_model.dart';
export 'beauty_filters.dart';
export 'auth_payload_model.dart';
export 'media_source.dart';
export 'subtitle.dart';
52 changes: 52 additions & 0 deletions lib/types/models/subtitle.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'dart:convert';

class Subtitle {
final String participant;
final String content;
Subtitle({
required this.participant,
required this.content,
});

Subtitle copyWith({
String? participant,
String? content,
}) {
return Subtitle(
participant: participant ?? this.participant,
content: content ?? this.content,
);
}

Map<String, dynamic> toMap() {
return <String, dynamic>{
'participant': participant,
'content': content,
};
}

factory Subtitle.fromMap(Map<String, dynamic> map) {
return Subtitle(
participant: map['participant'] as String,
content: map['content'] as String,
);
}

String toJson() => json.encode(toMap());

factory Subtitle.fromJson(String source) =>
Subtitle.fromMap(json.decode(source) as Map<String, dynamic>);

@override
String toString() => 'Subtitle(participant: $participant, content: $content)';

@override
bool operator ==(covariant Subtitle other) {
if (identical(this, other)) return true;

return other.participant == participant && other.content == content;
}

@override
int get hashCode => participant.hashCode ^ content.hashCode;
}
8 changes: 8 additions & 0 deletions lib/waterbus_sdk_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:waterbus_sdk/core/api/base/base_remote_data.dart';
import 'package:waterbus_sdk/core/api/meetings/repositories/meeting_repository.dart';
import 'package:waterbus_sdk/core/api/user/repositories/user_repository.dart';
import 'package:waterbus_sdk/core/webrtc/webrtc_interface.dart';
import 'package:waterbus_sdk/core/websocket/interfaces/socket_emiter_interface.dart';
import 'package:waterbus_sdk/core/websocket/interfaces/socket_handler_interface.dart';
import 'package:waterbus_sdk/flutter_waterbus_sdk.dart';
import 'package:waterbus_sdk/native/picture-in-picture/index.dart';
Expand All @@ -20,6 +21,7 @@ import 'package:waterbus_sdk/waterbus_sdk_interface.dart';
@Singleton(as: WaterbusSdkInterface)
class SdkCore extends WaterbusSdkInterface {
final SocketHandler _webSocket;
final SocketEmiter _socketEmiter;
final WaterbusWebRTCManager _rtcManager;
final ReplayKitChannel _replayKitChannel;

Expand All @@ -30,6 +32,7 @@ class SdkCore extends WaterbusSdkInterface {
final WaterbusLogger _logger;
SdkCore(
this._webSocket,
this._socketEmiter,
this._rtcManager,
this._replayKitChannel,
this._baseRepository,
Expand Down Expand Up @@ -177,6 +180,11 @@ class SdkCore extends WaterbusSdkInterface {
await _rtcManager.toggleSpeakerPhone();
}

@override
void setSubscribeSubtitle(bool isEnabled) {
_socketEmiter.setSubtitle(isEnabled);
}

@override
Future<void> startScreenSharing({DesktopCapturerSource? source}) async {
if (WebRTC.platformIsIOS) {
Expand Down
1 change: 1 addition & 0 deletions lib/waterbus_sdk_interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ abstract class WaterbusSdkInterface {
Future<void> toggleVideo();
Future<void> toggleAudio();
Future<void> toggleSpeakerPhone();
void setSubscribeSubtitle(bool isEnabled);
Future<void> startScreenSharing({DesktopCapturerSource? source});
Future<void> stopScreenSharing();
Future<void> enableVirtualBackground({
Expand Down

0 comments on commit a852966

Please sign in to comment.