Skip to content

Commit

Permalink
Add the server (videobridge) region to jingle (#316)
Browse files Browse the repository at this point in the history
* ref: Refactors the way extensions are added to Jingle packets.

The Jingle operation set does not need to know about all of the
extensions we support (and take their configuration as parameters).

* feat: Adds the bridge region to session-initiate packets.

* ref: Renames and moves jicofo's JingleUtils.

* ref: Fixes docs and renames a method.
  • Loading branch information
bgrozev authored Sep 17, 2018
1 parent 7bc890d commit 05b37ae
Show file tree
Hide file tree
Showing 6 changed files with 369 additions and 119 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Jicofo, the Jitsi Conference Focus.
*
* Copyright @ 2018 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jitsi.impl.protocol.xmpp.extensions;

import net.java.sip.communicator.impl.protocol.jabber.extensions.*;

/**
* A packet extension which contains the server's region.
*
* @author Boris Grozev
*/
public class ServerRegionPacketExtension
extends AbstractPacketExtension
{
/**
* The name of the {@code server-region} element.
*/
public static final String ELEMENT_NAME = "server-region";

/**
* The namespace for the {@code server-region} element.
*/
public static final String NAMESPACE = ConferenceIq.NAMESPACE;

/**
* The name of the "region" attribute.
*/
public static final String REGION_ATTR_NAME = "region";

/**
* Creates an {@link AbstractPacketExtension} instance for the specified
* <tt>namespace</tt> and <tt>elementName</tt>.
*
* @param namespace the XML namespace for this element.
* @param elementName the name of the element
*/
protected ServerRegionPacketExtension(String namespace,
String elementName)
{
super(namespace, elementName);
}

public ServerRegionPacketExtension(String region)
{
this(NAMESPACE, ELEMENT_NAME);

setRegion(region);
}

/**
* @return the region.
*/
public String getRegion()
{
return getAttributeAsString(REGION_ATTR_NAME);
}

/**
* Sets the region.
* @param region the value to set.
*/
public void setRegion(String region)
{
setAttribute(REGION_ATTR_NAME, region);
}
}
47 changes: 31 additions & 16 deletions src/main/java/org/jitsi/jicofo/LipSyncHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,13 @@ private void processAllParticipantsSSRCs(
*/
@Override
public boolean initiateSession(
boolean useBundle,
Jid address,
List<ContentPacketExtension> contents,
JingleRequestHandler requestHandler,
boolean[] startMuted)
JingleIQ jingleIQ,
JingleRequestHandler requestHandler)
throws OperationFailedException
{
processAllParticipantsSSRCs(contents, address);
processAllParticipantsSSRCs(jingleIQ.getContentList(), jingleIQ.getTo());

return jingleImpl.initiateSession(
useBundle, address, contents, requestHandler, startMuted);
return jingleImpl.initiateSession(jingleIQ, requestHandler);
}

/**
Expand All @@ -263,17 +259,36 @@ public boolean initiateSession(
* {@inheritDoc}
*/
@Override
public boolean replaceTransport(
boolean useBundle,
JingleSession session,
List<ContentPacketExtension> contents,
boolean[] startMuted)
public boolean replaceTransport(JingleIQ jingleIQ, JingleSession session)
throws OperationFailedException
{
processAllParticipantsSSRCs(contents, session.getAddress());
processAllParticipantsSSRCs(
jingleIQ.getContentList(),
session.getAddress());

return jingleImpl.replaceTransport(jingleIQ, session);
}

return jingleImpl.replaceTransport(
useBundle, session, contents, startMuted);
/**
* {@inheritDoc}
*/
@Override
public JingleIQ createTransportReplace(
JingleSession session,
List<ContentPacketExtension> contents)
{
return jingleImpl.createTransportReplace(session, contents);
}

/**
* {@inheritDoc}
*/
@Override
public JingleIQ createSessionInitiate(
Jid address,
List<ContentPacketExtension> contents)
{
return jingleImpl.createSessionInitiate(address, contents);
}

/**
Expand Down
113 changes: 83 additions & 30 deletions src/main/java/org/jitsi/jicofo/ParticipantChannelAllocator.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import net.java.sip.communicator.impl.protocol.jabber.extensions.jitsimeet.*;
import net.java.sip.communicator.impl.protocol.jabber.jinglesdp.*;
import net.java.sip.communicator.service.protocol.*;
import org.jitsi.impl.protocol.xmpp.extensions.*;
import org.jitsi.jicofo.discovery.*;
import org.jitsi.jicofo.util.*;
import org.jitsi.protocol.xmpp.*;
Expand Down Expand Up @@ -76,6 +77,9 @@ public ParticipantChannelAllocator(
this.logger = Logger.getLogger(classLogger, meetConference.getLogger());
}

/**
* {@inheritDoc}
*/
@Override
protected List<ContentPacketExtension> createOffer()
{
Expand Down Expand Up @@ -130,6 +134,9 @@ protected List<ContentPacketExtension> createOffer()
return contents;
}

/**
* {@inheritDoc}
*/
@Override
protected ColibriConferenceIQ doAllocateChannels(
List<ContentPacketExtension> offer)
Expand All @@ -143,6 +150,9 @@ protected ColibriConferenceIQ doAllocateChannels(
offer);
}

/**
* {@inheritDoc}
*/
@Override
protected void invite(List<ContentPacketExtension> offer)
throws OperationFailedException
Expand Down Expand Up @@ -179,38 +189,9 @@ else if (meetConference.findMember(address) == null)
}
else if (!canceled)
{
OperationSetJingle jingle = meetConference.getJingle();
boolean ack;
JingleSession jingleSession = participant.getJingleSession();
if (!reInvite || jingleSession == null)
{
// will throw OperationFailedExc if XMPP connection is broken
ack = jingle.initiateSession(
participant.hasBundleSupport(),
address,
offer,
meetConference,
startMuted);
}
else
if (!doInviteOrReinvite(address, offer))
{
// will throw OperationFailedExc if XMPP connection is broken
ack = jingle.replaceTransport(
participant.hasBundleSupport(),
jingleSession,
offer,
startMuted);
}
if (!ack)
{
// Failed to invite
logger.info(
"Expiring " + address + " channels - no RESULT for "
+ (reInvite ? "transport-replace" : "session-initiate"));
expireChannels = true;

// TODO: let meetConference know that our Jingle session failed,
// so it can either retry or remove the participant?
}
}

Expand All @@ -233,6 +214,78 @@ else if (reInvite)
}
}

/**
* Invites or re-invites (based on the value of {@link #reInvite}) the
* {@code participant} to the jingle session.
* Creates and sends the appropriate Jingle IQ ({@code session-initiate} for
* and invite or {@code transport-replace} for a re-invite) and sends it to
* the {@code participant}. Blocks until a response is received or a timeout
* occurs.
*
* @param address the destination JID.
* @param contents the list of contents to include.
* @return {@code false} on failure.
* @throws OperationFailedException if we are unable to send a packet
* because the XMPP connection is broken.
*/
private boolean doInviteOrReinvite(
Jid address, List<ContentPacketExtension> contents)
throws OperationFailedException
{
OperationSetJingle jingle = meetConference.getJingle();
JingleSession jingleSession = participant.getJingleSession();
boolean initiateSession = !reInvite || jingleSession == null;
boolean ack;
JingleIQ jingleIQ;

if (initiateSession)
{
// will throw OperationFailedExc if XMPP connection is broken
jingleIQ = jingle.createSessionInitiate(address, contents);
}
else
{
jingleIQ = jingle.createTransportReplace(jingleSession, contents);
}

if (participant.hasBundleSupport())
{
JicofoJingleUtils.addBundleExtensions(jingleIQ);
}
if (startMuted[0] || startMuted[1])
{
JicofoJingleUtils.addStartMutedExtension(
jingleIQ, startMuted[0], startMuted[1]);
}
String serverRegion = bridgeSession.bridge.getRegion();
if (serverRegion != null)
{
jingleIQ.addExtension(new ServerRegionPacketExtension(serverRegion));
}

if (initiateSession)
{
ack = jingle.initiateSession(jingleIQ, meetConference);
}
else
{
// will throw OperationFailedExc if XMPP connection is broken
ack = jingle.replaceTransport(jingleIQ, jingleSession);
}

if (!ack)
{
// Failed to invite
logger.info(
"Expiring " + address + " channels - no RESULT for "
+ (initiateSession ? "session-initiate"
: "transport-replace"));
return false;
}

return true;
}

/**
* {@inheritDoc}
*/
Expand Down
Loading

0 comments on commit 05b37ae

Please sign in to comment.