1 /* 2 * Jicofo, the Jitsi Conference Focus. 3 * 4 * Copyright @ 2015 Atlassian Pty Ltd 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 package org.jitsi.jicofo; 19 20 import org.jitsi.utils.version.*; 21 import org.jitsi.xmpp.extensions.jitsimeet.*; 22 import net.java.sip.communicator.service.protocol.*; 23 import net.java.sip.communicator.util.*; 24 25 import org.jitsi.eventadmin.*; 26 import org.jitsi.jicofo.discovery.Version; 27 import org.jitsi.jicofo.event.*; 28 import org.jitsi.osgi.*; 29 30 import org.jxmpp.jid.*; 31 import org.osgi.framework.*; 32 33 import java.util.*; 34 import java.util.stream.*; 35 36 /** 37 * The class listens for "focus joined room" and "conference created" events 38 * and adds the info about all conference components versions to Jicofo's MUC 39 * presence. 40 * 41 * @author Pawel Domas 42 */ 43 public class VersionBroadcaster 44 extends EventHandlerActivator 45 { 46 /** 47 * The logger 48 */ 49 private static final Logger logger 50 = Logger.getLogger(VersionBroadcaster.class); 51 52 /** 53 * <tt>FocusManager</tt> instance used to access 54 * <tt>JitsiMeetConference</tt>. 55 */ 56 private FocusManager focusManager; 57 58 /** 59 * <tt>VersionService</tt> which provides Jicofo version. 60 */ 61 private VersionService versionService; 62 63 /** 64 * Jitsi Meet tools used to add packet extension to Jicofo presence. 65 */ 66 private OperationSetJitsiMeetTools meetTools; 67 68 /** 69 * Creates new instance of <tt>VersionBroadcaster</tt>. 70 */ VersionBroadcaster()71 public VersionBroadcaster() 72 { 73 super(new String[] { 74 EventFactory.FOCUS_JOINED_ROOM_TOPIC, 75 EventFactory.CONFERENCE_ROOM_TOPIC 76 }); 77 } 78 79 /** 80 * {@inheritDoc} 81 */ 82 @Override start(BundleContext bundleContext)83 public void start(BundleContext bundleContext) 84 throws Exception 85 { 86 focusManager 87 = ServiceUtils.getService(bundleContext, FocusManager.class); 88 89 Objects.requireNonNull(focusManager, "focusManager"); 90 91 versionService 92 = ServiceUtils.getService(bundleContext, VersionService.class); 93 94 Objects.requireNonNull(versionService, "versionService"); 95 96 meetTools 97 = focusManager.getOperationSet(OperationSetJitsiMeetTools.class); 98 99 Objects.requireNonNull(meetTools, "meetTools"); 100 101 super.start(bundleContext); 102 } 103 104 /** 105 * {@inheritDoc} 106 */ 107 @Override stop(BundleContext bundleContext)108 public void stop(BundleContext bundleContext) 109 throws Exception 110 { 111 super.stop(bundleContext); 112 113 focusManager = null; 114 versionService = null; 115 meetTools = null; 116 } 117 118 /** 119 * Handles {@link EventFactory#FOCUS_JOINED_ROOM_TOPIC} and 120 * {@link EventFactory#CONFERENCE_ROOM_TOPIC}. 121 * 122 * {@inheritDoc} 123 */ 124 @Override handleEvent(Event event)125 public void handleEvent(Event event) 126 { 127 String topic = event.getTopic(); 128 if (!topic.equals(EventFactory.FOCUS_JOINED_ROOM_TOPIC) 129 && !topic.equals(EventFactory.CONFERENCE_ROOM_TOPIC)) 130 { 131 logger.error("Unexpected event topic: " + topic); 132 return; 133 } 134 135 EntityBareJid roomJid 136 = (EntityBareJid)event.getProperty(EventFactory.ROOM_JID_KEY); 137 138 JitsiMeetConference conference 139 = focusManager.getConference(roomJid); 140 if (conference == null) 141 { 142 logger.error("Conference is null"); 143 return; 144 } 145 146 ChatRoom chatRoom = conference.getChatRoom(); 147 if (chatRoom == null) 148 { 149 logger.error("Chat room is null"); 150 return; 151 } 152 153 JitsiMeetServices meetServices = focusManager.getJitsiMeetServices(); 154 ComponentVersionsExtension versionsExtension 155 = new ComponentVersionsExtension(); 156 157 // XMPP 158 Version xmppServerVersion = meetServices.getXMPPServerVersion(); 159 if (xmppServerVersion != null) 160 { 161 versionsExtension.addComponentVersion( 162 ComponentVersionsExtension.COMPONENT_XMPP_SERVER, 163 xmppServerVersion.getNameVersionOsString()); 164 } 165 166 // Conference focus 167 org.jitsi.utils.version.Version jicofoVersion 168 = versionService.getCurrentVersion(); 169 versionsExtension.addComponentVersion( 170 ComponentVersionsExtension.COMPONENT_FOCUS, 171 jicofoVersion.getApplicationName() 172 + "(" + jicofoVersion.toString() + "," 173 + System.getProperty("os.name") + ")"); 174 175 String jvbVersions = conference.getBridges().keySet().stream() 176 .map(b -> b.getVersion()) 177 .filter(Objects::nonNull) 178 .distinct() 179 .sorted() 180 .collect(Collectors.joining(", ")); 181 182 if (jvbVersions.length() > 0) 183 { 184 versionsExtension.addComponentVersion( 185 ComponentVersionsExtension.COMPONENT_VIDEOBRIDGE, 186 String.join(",", jvbVersions)); 187 } 188 189 meetTools.sendPresenceExtension(chatRoom, versionsExtension); 190 191 if (logger.isDebugEnabled()) 192 logger.debug("Sending versions: " + versionsExtension.toXML()); 193 } 194 } 195