本文整理汇总了Java中org.webrtc.PeerConnection类的典型用法代码示例。如果您正苦于以下问题:Java PeerConnection类的具体用法?Java PeerConnection怎么用?Java PeerConnection使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PeerConnection类属于org.webrtc包,在下文中一共展示了PeerConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: signalingStateString
import org.webrtc.PeerConnection; //导入依赖的package包/类
@Nullable
private String signalingStateString(PeerConnection.SignalingState signalingState) {
switch (signalingState) {
case STABLE:
return "stable";
case HAVE_LOCAL_OFFER:
return "have-local-offer";
case HAVE_LOCAL_PRANSWER:
return "have-local-pranswer";
case HAVE_REMOTE_OFFER:
return "have-remote-offer";
case HAVE_REMOTE_PRANSWER:
return "have-remote-pranswer";
case CLOSED:
return "closed";
}
return null;
}
示例2: onSetSuccess
import org.webrtc.PeerConnection; //导入依赖的package包/类
@Override
public void onSetSuccess() {
if (BuildConfig.DEBUG) {
Log.d(TAG, "@@@ onSetSuccess");
}
PeerConnection.SignalingState state = mPeerConnection.signalingState();
if (state == PeerConnection.SignalingState.HAVE_REMOTE_OFFER) {
mPeerConnection.createAnswer(this, createSDPMediaConstraints());
} else /*if (state == PeerConnection.SignalingState.HAVE_LOCAL_OFFER)*/ {
if (mCallback != null && mSdp != null) {
mCallback.onLocalDescription(MediaConnection.this, mSdp);
}
mSdp = null;
}
}
示例3: iceConnectionStateString
import org.webrtc.PeerConnection; //导入依赖的package包/类
@Nullable
private String iceConnectionStateString(PeerConnection.IceConnectionState iceConnectionState) {
switch (iceConnectionState) {
case NEW:
return "new";
case CHECKING:
return "checking";
case CONNECTED:
return "connected";
case COMPLETED:
return "completed";
case FAILED:
return "failed";
case DISCONNECTED:
return "disconnected";
case CLOSED:
return "closed";
}
return null;
}
示例4: onIceConnectionChange
import org.webrtc.PeerConnection; //导入依赖的package包/类
@Override
public void onIceConnectionChange(final PeerConnection.IceConnectionState newState) {
executor.execute(new Runnable() {
@Override
public void run() {
Log.d(TAG, "IceConnectionState: " + newState);
if (newState == IceConnectionState.CONNECTED) {
events.onIceConnected();
} else if (newState == IceConnectionState.DISCONNECTED) {
events.onIceDisconnected();
} else if (newState == IceConnectionState.FAILED) {
reportError("ICE connection failed.");
}
}
});
}
示例5: iceServersFromPCConfigJSON
import org.webrtc.PeerConnection; //导入依赖的package包/类
private LinkedList<PeerConnection.IceServer> iceServersFromPCConfigJSON(String pcConfig)
throws JSONException {
JSONObject json = new JSONObject(pcConfig);
JSONArray servers = json.getJSONArray("iceServers");
LinkedList<PeerConnection.IceServer> ret = new LinkedList<PeerConnection.IceServer>();
for (int i = 0; i < servers.length(); ++i) {
JSONObject server = servers.getJSONObject(i);
String url = server.getString("urls");
String credential = server.has("credential") ? server.getString("credential") : "";
PeerConnection.IceServer turnServer =
PeerConnection.IceServer.builder(url)
.setPassword(credential)
.createIceServer();
ret.add(turnServer);
}
return ret;
}
示例6: onTCPConnected
import org.webrtc.PeerConnection; //导入依赖的package包/类
/**
* If the client is the server side, this will trigger onConnectedToRoom.
*/
@Override
public void onTCPConnected(boolean isServer) {
if (isServer) {
roomState = ConnectionState.CONNECTED;
SignalingParameters parameters = new SignalingParameters(
// Ice servers are not needed for direct connections.
new LinkedList<PeerConnection.IceServer>(),
isServer, // Server side acts as the initiator on direct connections.
null, // clientId
null, // wssUrl
null, // wwsPostUrl
null, // offerSdp
null // iceCandidates
);
events.onConnectedToRoom(parameters);
}
}
示例7: onIceConnectionChange
import org.webrtc.PeerConnection; //导入依赖的package包/类
@Override
public void onIceConnectionChange(final PeerConnection.IceConnectionState newState) {
executor.execute(new Runnable() {
@Override
public void run() {
Log.d(TAG, "IceConnectionState: " + newState);
if (newState == IceConnectionState.CONNECTED) {
events.onIceConnected();
} else if (newState == IceConnectionState.DISCONNECTED) {
events.onIceDisconnected();
} else if (newState == IceConnectionState.FAILED) {
reportError("ICE connection failed.");
}
}
});
}
示例8: onTCPConnected
import org.webrtc.PeerConnection; //导入依赖的package包/类
/**
* If the client is the server side, this will trigger onConnectedToRoom.
*/
@Override
public void onTCPConnected(boolean isServer) {
if (isServer) {
roomState = ConnectionState.CONNECTED;
SignalingParameters parameters = new SignalingParameters(
// Ice servers are not needed for direct connections.
new LinkedList<PeerConnection.IceServer>(),
isServer, // Server side acts as the initiator on direct connections.
null, // clientId
null, // wssUrl
null, // wwsPostUrl
null, // offerSdp
null // iceCandidates
);
events.onConnectedToRoom(parameters);
}
}
示例9: createPeerConnectionClient
import org.webrtc.PeerConnection; //导入依赖的package包/类
PeerConnectionClient createPeerConnectionClient(MockRenderer localRenderer,
MockRenderer remoteRenderer, PeerConnectionParameters peerConnectionParameters,
VideoCapturer videoCapturer, EglBase.Context eglContext) {
List<PeerConnection.IceServer> iceServers = new LinkedList<PeerConnection.IceServer>();
SignalingParameters signalingParameters =
new SignalingParameters(iceServers, true, // iceServers, initiator.
null, null, null, // clientId, wssUrl, wssPostUrl.
null, null); // offerSdp, iceCandidates.
PeerConnectionClient client = PeerConnectionClient.getInstance();
PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
options.networkIgnoreMask = 0;
options.disableNetworkMonitor = true;
client.setPeerConnectionFactoryOptions(options);
client.createPeerConnectionFactory(
InstrumentationRegistry.getTargetContext(), peerConnectionParameters, this);
client.createPeerConnection(
eglContext, localRenderer, remoteRenderer, videoCapturer, signalingParameters);
client.createOffer();
return client;
}
示例10: WebRTC
import org.webrtc.PeerConnection; //导入依赖的package包/类
WebRTC(WebRTCTask task, MainActivity activity) {
this.task = task;
this.activity = activity;
// Initialize Android globals
// See https://bugs.chromium.org/p/webrtc/issues/detail?id=3416
PeerConnectionFactory.initializeAndroidGlobals(activity, false);
// Set ICE servers
List<PeerConnection.IceServer> iceServers = new ArrayList<>();
iceServers.add(new org.webrtc.PeerConnection.IceServer("stun:" + Config.STUN_SERVER));
if (Config.TURN_SERVER != null) {
iceServers.add(new org.webrtc.PeerConnection.IceServer("turn:" + Config.TURN_SERVER,
Config.TURN_USER, Config.TURN_PASS));
}
// Create peer connection
final PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();
this.factory = new PeerConnectionFactory(options);
this.constraints = new MediaConstraints();
this.pc = this.factory.createPeerConnection(iceServers, constraints, new PeerConnectionObserver());
// Add task message event handler
this.task.setMessageHandler(new TaskMessageHandler());
}
示例11: onIceConnectionChange
import org.webrtc.PeerConnection; //导入依赖的package包/类
@Override
public void onIceConnectionChange(
final PeerConnection.IceConnectionState newState) {
// executor.execute(new Runnable() {
// @Override
// public void run() {
// Log.d(TAG, "IceConnectionState: " + newState);
// if (newState == IceConnectionState.CONNECTED) {
// events.onIceConnected();
// } else if (newState == IceConnectionState.DISCONNECTED) {
// events.onIceDisconnected();
// } else if (newState == IceConnectionState.FAILED) {
// reportError("ICE connection failed.");
// }
// }
// });
}
示例12: WebRtcClient
import org.webrtc.PeerConnection; //导入依赖的package包/类
public WebRtcClient(RtcListener listener, String host, PeerConnectionClient.PeerConnectionParameters params) {
mListener = listener;
pcParams = params;
PeerConnectionFactory.initializeAndroidGlobals(listener, true, true,
params.videoCodecHwAcceleration);
factory = new PeerConnectionFactory();
MessageHandler messageHandler = new MessageHandler();
try {
client = IO.socket(host);
} catch (URISyntaxException e) {
e.printStackTrace();
}
client.on("id", messageHandler.onId);
client.on("message", messageHandler.onMessage);
client.connect();
iceServers.add(new PeerConnection.IceServer("stun:23.21.150.121"));
iceServers.add(new PeerConnection.IceServer("stun:stun.l.google.com:19302"));
pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveAudio", "true"));
pcConstraints.mandatory.add(new MediaConstraints.KeyValuePair("OfferToReceiveVideo", "true"));
pcConstraints.optional.add(new MediaConstraints.KeyValuePair("DtlsSrtpKeyAgreement", "true"));
}
示例13: onIceGatheringChange
import org.webrtc.PeerConnection; //导入依赖的package包/类
@Override
public void onIceGatheringChange(@Nonnull final PeerConnection.IceGatheringState state) {
Log.d("WebRTC", "IceGatheringState is " + state);
if (state == PeerConnection.IceGatheringState.COMPLETE
&& peerConnection.iceConnectionState() != PeerConnection.IceConnectionState.CONNECTED
&& peerConnection.iceConnectionState() != PeerConnection.IceConnectionState.CLOSED
&& progressState.getValue() != ProgressState.ENDED) {
progressState.changeValue(ProgressState.IDLE);
bin.add(xmpp.subscribe(
it -> it.getSessions().get(localJid).getPluginManager().getPlugin(WebRtcPlugin.class).sendSdp(
remoteJid,
id,
peerConnection.getLocalDescription(),
ACTION_CALL_OUTBOUND.equals(getIntent().getAction())
),
CallingActivity.this::fail
));
}
}
示例14: initializeIceServers
import org.webrtc.PeerConnection; //导入依赖的package包/类
private void initializeIceServers() {
final Document xml;
try {
xml = DomUtils.readDocument(getResources().openRawResource(R.raw.ice));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
synchronized (iceServers) {
iceServers.clear();
for (Node it : DomUtils.convertToList(xml.getDocumentElement().getElementsByTagName("url"))) {
final Element element = (Element) it;
final PeerConnection.IceServer.Builder builder = PeerConnection.IceServer.builder(
element.getTextContent()
);
final String username = element.getAttribute("username");
if (StringUtils.isNotBlank(username)) {
builder.setUsername(username);
}
final String password = element.getAttribute("password");
if (StringUtils.isNotBlank(password)) {
builder.setPassword(password);
}
iceServers.add(builder.createIceServer());
}
}
}
示例15: onIceConnectionChange
import org.webrtc.PeerConnection; //导入依赖的package包/类
@Override
public void onIceConnectionChange(final PeerConnection.IceConnectionState iceConnectionState) {
if (BuildConfig.DEBUG) {
Log.d(TAG, "@@@ onIceConnectionChange");
Log.d(TAG, "@@@ IceConnectionState: " + iceConnectionState.toString());
}
switch (iceConnectionState) {
case FAILED:
if (mCallback != null) {
mCallback.onError(MediaConnection.this);
}
// no break;
case DISCONNECTED:
close();
break;
default:
if (BuildConfig.DEBUG) {
Log.d(TAG, "@@@ iceConnectionState=" + iceConnectionState);
}
break;
}
}