我可以连接ios应用程序与kurento房间进行电话会议没有任何问题,但我无法连接到android,这里我正在关注教程 Kurento WebRTC Peer For Android 使android客户端连接kurento室。
以下是我正在尝试的代码
public class MainActivity extends AppCompatActivity implements
RoomListener,NBMWebRTCPeer.Observer {
private LooperExecutor executor;
private static KurentoRoomAPI kurentoRoomAPI;
private EglBase rootEglBase;
private NBMWebRTCPeer nbmWebRTCPeer;
private SurfaceViewRenderer localView;
private SurfaceViewRenderer remoteView;
private VideoRenderer.Callbacks localRender;
private SessionDescription localSdp;
private SessionDescription remoteSdp;
NBMMediaConfiguration.NBMVideoFormat receiverVideoFormat = new NBMMediaConfiguration.NBMVideoFormat(1280, 720, ImageFormat.YUV_420_888, 30);
NBMMediaConfiguration mediaConfiguration = new NBMMediaConfiguration(NBMMediaConfiguration.NBMRendererType.OPENGLES, NBMMediaConfiguration.NBMAudioCodec.OPUS, 0, NBMMediaConfiguration.NBMVideoCodec.VP8, 0, receiverVideoFormat, NBMMediaConfiguration.NBMCameraPosition.FRONT);
private boolean isMyVideoPublished = false;
private boolean isMyIceCandidateSent = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
int hasCameraPermission = checkSelfPermission(Manifest.permission.CAMERA);
List<String> permissions = new ArrayList<String>();
if (hasCameraPermission != PackageManager.PERMISSION_GRANTED) {
permissions.add(Manifest.permission.CAMERA);
}
if (!permissions.isEmpty()) {
requestPermissions(permissions.toArray(new String[permissions.size()]), 111);
}
}
executor = new LooperExecutor();
executor.requestStart();
String wsRoomUri = "wss://172.16.1.9:8443/room";
kurentoRoomAPI = new KurentoRoomAPI(executor, wsRoomUri, this);
kurentoRoomAPI.connectWebSocket();
localView = (SurfaceViewRenderer) findViewById(R.id.gl_surface_local);
remoteView = (SurfaceViewRenderer) findViewById(R.id.gl_surface_remote);
localView.init(EglBase.create().getEglBaseContext(), null);
localView.setZOrderMediaOverlay(true);
localView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
localView.setMirror(true);
localView.requestLayout();
remoteView.init(EglBase.create().getEglBaseContext(), null);
remoteView.setZOrderMediaOverlay(true);
remoteView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL);
remoteView.setMirror(true);
remoteView.requestLayout();
nbmWebRTCPeer = new NBMWebRTCPeer(mediaConfiguration, this, localView, this);
nbmWebRTCPeer.initialize();
//nbmWebRTCPeer.generateOffer("local", true);
//nbmWebRTCPeer.generateOffer("MyRemotePeer", false);
}
@Override
public void onRoomResponse(RoomResponse response) {
Log.d("onRoomResponse", "******** onRoomResponse : "+response.toString());
if (response.getId() == 123) {
Log.d("onRoomResponse", "Successfully connected to the room!");
nbmWebRTCPeer.generateOffer("Jeeva", true);
//kurentoRoomAPI.sendMessage("112233", "Jeeva Moto", "Hello room!", 125);
} else if (response.getId() == 125) {
Log.d("onRoomResponse", "The server received my message!");
} else if (response.getId() == 126) {
}else if (response.getId() == 129) {
}
}
@Override
public void onRoomError(RoomError error) {
Log.d("onRoomError", "******** onRoomError : "+error.toString());
}
@Override
public void onRoomNotification(RoomNotification notification) {
if(notification.getMethod().equals(RoomListener.METHOD_SEND_MESSAGE)) {
final String username = notification.getParam("user").toString();
final String message = notification.getParam("message").toString();
Log.d("onRoomNotification", "Oh boy! " + username + " sent me a message: " + message);
}
Log.d("onRoomNotification", "******** RoomNotification : " + notification);
if(notification.getMethod().equals("iceCandidate"))
{
Map<String, Object> map = notification.getParams();
Log.d("onRoomNotification", "******** Map RoomNotification : " + map);
String sdpMid = map.get("sdpMid").toString();
int sdpMLineIndex = Integer.valueOf(map.get("sdpMLineIndex").toString());
String sdp = map.get("candidate").toString();
IceCandidate ic = new IceCandidate(sdpMid, sdpMLineIndex, sdp);
nbmWebRTCPeer.addRemoteIceCandidate(ic, "remote");
}
}
@Override
public void onRoomConnected() {
Log.d("onRoomConnected","******** Called");
kurentoRoomAPI.sendJoinRoom("Jeeva", "112233", true, 123);
}
@Override
public void onRoomDisconnected() {
}
@Override
public void onInitialize() {
}
@Override
public void onLocalSdpOfferGenerated(SessionDescription localSdpOffer, NBMPeerConnection connection) {
Log.d("onLclSdpOfrGen","******** localSdpOffer : "+localSdpOffer.description+" connection : "+connection.getConnectionId());
if (!isMyVideoPublished) {
kurentoRoomAPI.sendPublishVideo(localSdpOffer.description,false,129);
//String username = "qwerty";
//kurentoRoomAPI.sendReceiveVideoFrom(username, "webcam", localSdpOffer.description, 129);
isMyVideoPublished = true;
}else {
String username = "qwerty";
kurentoRoomAPI.sendReceiveVideoFrom(username, "webcam", localSdpOffer.description, 129);
}
}
@Override
public void onLocalSdpAnswerGenerated(SessionDescription localSdpAnswer, NBMPeerConnection connection) {
Log.d("onLclSdpAnsGen","******** localSdpAnswer : "+localSdpAnswer.description+" connection : "+connection.getConnectionId());
}
@Override
public void onIceCandidate(IceCandidate iceCandidate, NBMPeerConnection nbmPeerConnection) {
Log.d("onIceCandidate", "******** iceCandidate : " + iceCandidate.sdp + " nbmPeerConnection : " + nbmPeerConnection.getConnectionId());
if (!isMyIceCandidateSent){
isMyIceCandidateSent = true;
kurentoRoomAPI.sendOnIceCandidate("Jeeva", iceCandidate.sdp, iceCandidate.sdpMid, Integer.toString(iceCandidate.sdpMLineIndex),129);
} else {
kurentoRoomAPI.sendOnIceCandidate("qwerty", iceCandidate.sdp,
iceCandidate.sdpMid, Integer.toString(iceCandidate.sdpMLineIndex), 129);
nbmWebRTCPeer.addRemoteIceCandidate(iceCandidate, iceCandidate.sdp);
}
}
@Override
public void onIceStatusChanged(PeerConnection.IceConnectionState state, NBMPeerConnection connection) {
Log.d("onIceStatusChanged","******** state : "+state+" connection : "+connection);
}
@Override
public void onRemoteStreamAdded(MediaStream stream, NBMPeerConnection connection) {
Log.d("onRemoteStreamAdded","******** stream : "+stream+" connection : "+connection);
nbmWebRTCPeer.attachRendererToRemoteStream(remoteView, stream);
}
@Override
public void onRemoteStreamRemoved(MediaStream stream, NBMPeerConnection connection) {
Log.d("onRemoteStreamRemoved","******** stream : "+stream+" connection : "+connection);
}
@Override
public void onPeerConnectionError(String error) {
Log.d("onPeerConnectionError","******** error : "+error);
}
@Override
public void onDataChannel(DataChannel dataChannel, NBMPeerConnection connection) {
Log.d("onDataChannel","******** dataChannel : "+dataChannel+" connection : "+connection);
}
@Override
public void onBufferedAmountChange(long l, NBMPeerConnection connection, DataChannel channel) {
Log.d("onBufferedAmountChange","******** channel : "+channel+" connection : "+connection);
}
@Override
public void onStateChange(NBMPeerConnection connection, DataChannel channel) {
Log.d("onStateChange","******** channel : "+channel+" connection : "+connection);
}
@Override
public void onMessage(DataChannel.Buffer buffer, NBMPeerConnection connection, DataChannel channel) {
Log.d("onMessage","******** channel : "+channel+" buffer : "+buffer+" connection : "+connection);
}}
我正在为Android客户端寻找任何连接kurento会议室的工作样本。
答案 0 :(得分:1)
Kurento还使用简单的UI完成了Android客户端。
它允许连接到&#34; kurento-room&#34;服务器使用他们的KurentoAPI。
它只有2p2,但包含所有需要信令的实现,因此它可能是一个很好的起点。
更多详情请见there。