本文整理汇总了Java中javax.sdp.MediaDescription.setAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java MediaDescription.setAttribute方法的具体用法?Java MediaDescription.setAttribute怎么用?Java MediaDescription.setAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.sdp.MediaDescription
的用法示例。
在下文中一共展示了MediaDescription.setAttribute方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleOffer
import javax.sdp.MediaDescription; //导入方法依赖的package包/类
/**
*
* @param offer the received offer
* @return The answer to respond with.
*/
public Answer handleOffer(Offer offer) throws Exception {
String fingerPrint = CertUtil.getCertFingerPrint(
keyStoreInfo.getFilePath(),
keyStoreInfo.getAlias(),
keyStoreInfo.getPassword());
SessionDescription sdp = offer.getSdp();
sdp.setAttribute("fingerprint", fingerPrint);
MediaDescription med = (MediaDescription)sdp.getMediaDescriptions(true).get(0);
med.setAttribute("fingerprint", fingerPrint);
String pwd = med.getAttribute("ice-pwd");
String user = med.getAttribute("ice-ufrag");
String cand = med.getAttribute("candidate");
List<String> candData = Arrays.asList(cand.split(" "));
String ip = candData.get(4);
String port = candData.get(5);
this.setRemote(new UserData(user,pwd));
/**
* TODO The below should be defined outside PeerConnection
*
* This is a huge hack now. Should follow browser API
* and create datachannel from the outside.
*/
DataChannelImpl conn = new DataChannelImpl(this);
//Add handling of input
conn.onOpen(() -> {
logger.info("Running onOpen");
conn.send("I'M SO OPEN!!!");
});
conn.onMessage((i)->{
String in = new String(i.getData());
//logger.info("Running onMessage: " + in);
conn.send("ECHO: " + in);
});
conn.onError((i)->{
logger.info("Received error",i.getError());
});
new Thread(conn).start();
String localAddress = InetAddress.getLocalHost().getHostAddress();
String address = System.getProperty("com.bitbreeds.ip",localAddress);
logger.info("Adr: {}", address);
med.setAttribute("ice-pwd",local.getPassword());
med.setAttribute("ice-ufrag",local.getUserName());
med.setAttribute("candidate","1 1 UDP 2122252543 "+address+" "+conn.getPort()+" typ host");
return new Answer(sdp);
}
示例2: generateHoldSdpDescription
import javax.sdp.MediaDescription; //导入方法依赖的package包/类
/**
* Generates the Hold Description for a Call.
*
* @param setAudio set hold on Audio.
* @param setVideo set hold on Video.
* @param call the call that you want to hold.
* @return SessionDescription of a call.
* @throws MediaException
*/
public SessionDescription generateHoldSdpDescription(boolean setAudio, boolean setVideo, Call call)
throws MediaException {
try {
SessionDescription sessDescr = sdpFactory
.createSessionDescription();
Version v = sdpFactory.createVersion(0);
InetSocketAddress publicAudioAddress = NetworkAddressManager
.getPublicAddressFor(((MediaDescription) (call.getLocalSdpDescription().getMediaDescriptions(true).get(0))).getMedia().getMediaPort());
InetAddress publicIpAddress = publicAudioAddress.getAddress();
String addrType = publicIpAddress instanceof Inet6Address ? "IP6"
: "IP4";
Origin o = sdpFactory.createOrigin(SIPConfig.getUserName()
.replace(' ', '_'), 20109217, 2, "IN", addrType,
publicIpAddress.getHostAddress());
SessionName s = sdpFactory.createSessionName("<SparkPhone>");
Connection c = sdpFactory.createConnection("IN", addrType,
publicIpAddress.getHostAddress());
TimeDescription t = sdpFactory.createTimeDescription();
Vector<TimeDescription> timeDescs = new Vector<TimeDescription>();
timeDescs.add(t);
String[] formats = new String[getAudioFormats().size()];
int i = 0;
for (AudioFormat audioFormat : getAudioFormats()) {
formats[i++] = AudioFormatUtils.findCorrespondingSdpFormat(audioFormat.getEncoding());
}
MediaDescription am = sdpFactory.createMediaDescription(
"audio", publicAudioAddress.getPort(), 1, "RTP/AVP",
formats);
am.setAttribute(setAudio ? "sendonly" : "sendrecv", null);
am.setAttribute("rtmap:101", "telephone-event/"
+ publicAudioAddress.getPort());
Vector<MediaDescription> mediaDescs = new Vector<MediaDescription>();
mediaDescs.add(am);
sessDescr.setVersion(v);
sessDescr.setOrigin(o);
sessDescr.setConnection(c);
sessDescr.setSessionName(s);
sessDescr.setTimeDescriptions(timeDescs);
if (mediaDescs.size() > 0)
sessDescr.setMediaDescriptions(mediaDescs);
return sessDescr;
}
catch (SdpException exc) {
throw new MediaException(
"An SDP exception occurred while generating local sdp description",
exc);
}
}