Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

Add switch speaker #89

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<framework src="com.android.volley:volley:1.1.0" />
<asset src="www/opentok.js" target="opentok.js" />
<source-file src="src/android/OpenTokAndroidPlugin.java" target-dir="src/com/tokbox/cordova/" />

<config-file target="AndroidManifest.xml" parent="/manifest">
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.INTERNET" />
Expand All @@ -34,8 +34,8 @@
<param name="android-package" value="com.tokbox.cordova.OpenTokAndroidPlugin"/>
<param name="onload" value="true" />
</feature>
</config-file>
</config-file>

</platform>

<!-- ios -->
Expand All @@ -44,7 +44,11 @@
<asset src="www/opentok.js" target="opentok.js" />

<header-file src="src/ios/OpenTokPlugin.h" />
<header-file src="src/ios/OTDefaultAudioDevice.h" />
<header-file src="src/ios/OTDefaultAudioDeviceWithVolumeControl.h" />
<source-file src="src/ios/OpenTokPlugin.m" />
<source-file src="src/ios/OTDefaultAudioDevice.m" />
<source-file src="src/ios/OTDefaultAudioDeviceWithVolumeControl.m" />

<framework src="libstdc++.dylib" />
<framework src="libc++.dylib" />
Expand Down
21 changes: 18 additions & 3 deletions src/android/OpenTokAndroidPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;

import com.opentok.android.AudioDeviceManager;
import com.opentok.android.BaseAudioDevice;
import com.opentok.android.Connection;
import com.opentok.android.OpentokError;
import com.opentok.android.Publisher;
Expand All @@ -57,6 +59,7 @@ public class OpenTokAndroidPlugin extends CordovaPlugin

private String sessionId;
private String apiKey;
private String callType;
protected Session mSession;
public static final String TAG = "OTPlugin";
public boolean sessionConnected;
Expand Down Expand Up @@ -286,7 +289,7 @@ public void onError(PublisherKit arg0, OpentokError arg1) {
public void onStreamCreated(PublisherKit arg0, Stream arg1) {
Log.i(TAG, "publisher stream received");
streamCollection.put(arg1.getStreamId(), arg1);

streamHasAudio.put(arg1.getStreamId(), arg1.hasAudio());
streamHasVideo.put(arg1.getStreamId(), arg1.hasVideo());
JSONObject videoDimensions = new JSONObject();
Expand Down Expand Up @@ -388,6 +391,16 @@ public void run() {

@Override
public void onConnected(SubscriberKit arg0) {
// Speaker does not switch unless it receives Subscriber's Stream
// switch speaker
if (callType.equals("voice")) {
Log.d(TAG, "debug - Handset");
AudioDeviceManager.getAudioDevice().setOutputMode(BaseAudioDevice.OutputMode.Handset);
} else {
Log.d(TAG, "debug - SpeakerPhone");
AudioDeviceManager.getAudioDevice().setOutputMode(BaseAudioDevice.OutputMode.SpeakerPhone);
}

// TODO Auto-generated method stub
JSONObject eventData = new JSONObject();
String streamId = arg0.getStream().getStreamId();
Expand Down Expand Up @@ -539,6 +552,8 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("initSession")) {
apiKey = args.getString(0);
sessionId = args.getString(1);
callType = args.getString(2);

Log.i(TAG, "created new session with data: " + args.toString());
mSession = new Session(this.cordova.getActivity().getApplicationContext(), apiKey, sessionId);
mSession.setSessionListener(this);
Expand Down Expand Up @@ -873,7 +888,7 @@ public void onStreamHasVideoChanged(Session session, Stream stream, boolean newV
@Override
public void onStreamVideoDimensionsChanged(Session session, Stream stream, int width, int height) {
JSONObject oldValue = this.streamVideoDimensions.get(stream.getStreamId());

JSONObject newValue = new JSONObject();
try {
newValue.put("width", width);
Expand Down Expand Up @@ -1053,4 +1068,4 @@ public void onStreamVideoTypeChanged(Session arg0, Stream arg1,
// TODO Auto-generated method stub

}
}
}
62 changes: 62 additions & 0 deletions src/ios/OTDefaultAudioDevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// OTAudioDeviceIOSDefault.h
//
// Copyright (c) 2014 TokBox, Inc. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <OpenTok/OpenTok.h>

#define kMixerInputBusCount 2
#define kOutputBus 0
#define kInputBus 1

#define AUDIO_DEVICE_HEADSET @"AudioSessionManagerDevice_Headset"
#define AUDIO_DEVICE_BLUETOOTH @"AudioSessionManagerDevice_Bluetooth"
#define AUDIO_DEVICE_SPEAKER @"AudioSessionManagerDevice_Speaker"

@interface OTDefaultAudioDevice : NSObject <OTAudioDevice>
{
AudioStreamBasicDescription stream_format;
}

/**
Returns YES if a wired headset is available.
*/
@property (nonatomic, readonly) BOOL headsetDeviceAvailable;

/**
Returns YES if a bluetooth device is available.
*/
@property (nonatomic, readonly) BOOL bluetoothDeviceAvailable;

- (BOOL)setAudioBus:(id<OTAudioBus>)audioBus;

- (OTAudioFormat*)captureFormat;
- (OTAudioFormat*)renderFormat;

- (BOOL)renderingIsAvailable;
- (BOOL)initializeRendering;
- (BOOL)renderingIsInitialized;
- (BOOL)captureIsAvailable;
- (BOOL)initializeCapture;
- (BOOL)captureIsInitialized;

- (BOOL)startRendering;
- (BOOL)stopRendering;
- (BOOL)isRendering;
- (BOOL)startCapture;
- (BOOL)stopCapture;
- (BOOL)isCapturing;

- (uint16_t)estimatedRenderDelay;
- (uint16_t)estimatedCaptureDelay;

//desired Audio Route can be bluetooth and headset.
//bluetooth has higher priority of all, next headset, next speaker
- (BOOL)configureAudioSessionWithDesiredAudioRoute:(NSString*)desiredAudioRoute;
- (BOOL)detectCurrentRoute;

- (BOOL)setPlayOutRenderCallback:(AudioUnit)unit;

@end
Loading