Skip to content

Commit 322847b

Browse files
Praxeyslycoder
Praxey
authored andcommittedMar 23, 2019
Permits toggling of audio settings (blackuy#192)
* adds scaleType prop for video rendering * minor fixes * add variable declaration * upgrades Android to Twilio Video 3.2.1 * Adds function to toggle sound setup * fixes variable for scaletype, adds variable to complete upgrade on togglesoundsetup * fixes syntax error
1 parent 8920d46 commit 322847b

6 files changed

+59
-2
lines changed
 

‎android/src/main/java/com/twiliorn/library/CustomTwilioVideoView.java

+9
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,15 @@ public void toggleVideo(boolean enabled) {
450450
}
451451
}
452452

453+
public void toggleSoundSetup(boolean speaker){
454+
AudioManager audioManager = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
455+
if(speaker){
456+
audioManager.setSpeakerphoneOn(true);
457+
} else {
458+
audioManager.setSpeakerphoneOn(false);
459+
}
460+
}
461+
453462
public void toggleAudio(boolean enabled) {
454463
if (localAudioTrack != null) {
455464
localAudioTrack.enable(enabled);

‎android/src/main/java/com/twiliorn/library/CustomTwilioVideoViewManager.java

+5
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class CustomTwilioVideoViewManager extends SimpleViewManager<CustomTwilio
4545
private static final int TOGGLE_SOUND = 5;
4646
private static final int GET_STATS = 6;
4747
private static final int DISABLE_OPENSL_ES = 7;
48+
private static final int TOGGLE_SOUND_SETUP = 8;
4849

4950
@Override
5051
public String getName() {
@@ -84,6 +85,10 @@ public void receiveCommand(CustomTwilioVideoView view, int commandId, @Nullable
8485
case DISABLE_OPENSL_ES:
8586
view.disableOpenSLES();
8687
break;
88+
case TOGGLE_SOUND_SETUP:
89+
Boolean speaker = args.getBoolean(0);
90+
view.toggleSoundSetup(speaker);
91+
break;
8792
}
8893
}
8994

‎android/src/main/java/com/twiliorn/library/TwilioRemotePreviewManager.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public String getName() {
2828
}
2929

3030
@ReactProp(name = "scaleType")
31-
public void setScaleType(TwilioVideoPreview view, @Nullable String scaleType) {
31+
public void setScaleType(TwilioRemotePreview view, @Nullable String scaleType) {
3232

3333
if (scaleType.equals("fit")) {
3434
view.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);

‎ios/RCTTWVideoModule.m

+30
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,36 @@ - (void)addParticipantView:(TVIVideoView *)view sid:(NSString *)sid trackSid:(NS
171171
}
172172
}
173173

174+
RCT_EXPORT_METHOD(toggleSoundSetup:(BOOL)speaker) {
175+
if(speaker){
176+
kDefaultAVAudioSessionConfigurationBlock();
177+
178+
// Overwrite the audio route
179+
AVAudioSession *session = [AVAudioSession sharedInstance];
180+
NSError *error = nil;
181+
if (![session setMode:AVAudioSessionModeVideoChat error:&error]) {
182+
NSLog(@"AVAudiosession setMode %@",error);
183+
}
184+
185+
if (![session overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&error]) {
186+
NSLog(@"AVAudiosession overrideOutputAudioPort %@",error);
187+
}
188+
} else {
189+
kDefaultAVAudioSessionConfigurationBlock();
190+
191+
// Overwrite the audio route
192+
AVAudioSession *session = [AVAudioSession sharedInstance];
193+
NSError *error = nil;
194+
if (![session setMode:AVAudioSessionModeVoiceChat error:&error]) {
195+
NSLog(@"AVAudiosession setMode %@",error);
196+
}
197+
198+
if (![session overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&error]) {
199+
NSLog(@"AVAudiosession overrideOutputAudioPort %@",error);
200+
}
201+
}
202+
}
203+
174204
-(void)convertBaseTrackStats:(TVIBaseTrackStats *)stats result:(NSMutableDictionary *)result {
175205
result[@"trackSid"] = stats.trackSid;
176206
result[@"packetsLost"] = @(stats.packetsLost);

‎src/TwilioVideo.android.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ const nativeEvents = {
109109
toggleVideo: 4,
110110
toggleSound: 5,
111111
getStats: 6,
112-
disableOpenSLES: 7
112+
disableOpenSLES: 7,
113+
toggleSoundSetup: 8
113114
}
114115

115116
class CustomTwilioVideoView extends Component {
@@ -143,6 +144,10 @@ class CustomTwilioVideoView extends Component {
143144
this.runCommand(nativeEvents.disableOpenSLES, [])
144145
}
145146

147+
toggleSoundSetup (speaker) {
148+
this.runCommand(nativeEvents.toggleSoundSetup, [speaker])
149+
}
150+
146151
runCommand (event, args) {
147152
switch (Platform.OS) {
148153
case 'android':

‎src/TwilioVideo.ios.js

+8
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ export default class extends Component {
133133
this.setLocalVideoEnabled = this.setLocalVideoEnabled.bind(this)
134134
this.setLocalAudioEnabled = this.setLocalAudioEnabled.bind(this)
135135
this.flipCamera = this.flipCamera.bind(this)
136+
this.toggleSoundSetup = this.toggleSoundSetup.bind(this)
136137
this.connect = this.connect.bind(this)
137138
this.disconnect = this.disconnect.bind(this)
138139
this.setRemoteAudioPlayback = this.setRemoteAudioPlayback.bind(this)
@@ -178,6 +179,13 @@ export default class extends Component {
178179
TWVideoModule.flipCamera()
179180
}
180181

182+
/**
183+
* Toggle audio setup from speaker (default) and headset
184+
*/
185+
toggleSoundSetup (speaker) {
186+
TWVideoModule.toggleSoundSetup(speaker)
187+
}
188+
181189
/**
182190
* Get connection stats
183191
*/

0 commit comments

Comments
 (0)
Failed to load comments.