Search in sources :

Example 16 with IConnection

use of org.red5.server.api.IConnection in project bigbluebutton by bigbluebutton.

the class VideoApplication method recordStream.

/**
     * A hook to record a stream. A file is written in webapps/video/streams/
     * @param stream
     */
private void recordStream(IBroadcastStream stream) {
    IConnection conn = Red5.getConnectionLocal();
    long now = System.currentTimeMillis();
    // + "-" + now; /** Comment out for now...forgot why I added this - ralam */
    String recordingStreamName = stream.getPublishedName();
    try {
        log.info("Recording stream " + recordingStreamName);
        ClientBroadcastStream cstream = (ClientBroadcastStream) this.getBroadcastStream(conn.getScope(), stream.getPublishedName());
        cstream.saveAs(recordingStreamName, false);
    } catch (Exception e) {
        log.error("ERROR while recording stream " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : IConnection(org.red5.server.api.IConnection) ClientBroadcastStream(org.red5.server.stream.ClientBroadcastStream)

Example 17 with IConnection

use of org.red5.server.api.IConnection in project bigbluebutton by bigbluebutton.

the class VideoApplication method roomConnect.

@Override
public boolean roomConnect(IConnection connection, Object[] params) {
    log.info("BBB Video roomConnect");
    String meetingId = ((String) params[0]).toString();
    String userId = ((String) params[1]).toString();
    Red5.getConnectionLocal().setAttribute("MEETING_ID", meetingId);
    Red5.getConnectionLocal().setAttribute("USERID", userId);
    String connType = getConnectionType(Red5.getConnectionLocal().getType());
    String sessionId = Red5.getConnectionLocal().getSessionId();
    /**
		* Find if there are any other connections owned by this user. If we find one,
		* that means that the connection is old and the user reconnected. Clear the
		* userId attribute so that messages would not be sent in the defunct connection.
		*/
    Set<IConnection> conns = Red5.getConnectionLocal().getScope().getClientConnections();
    for (IConnection conn : conns) {
        String connUserId = (String) conn.getAttribute("USERID");
        String connSessionId = conn.getSessionId();
        String clientId = conn.getClient().getId();
        String remoteHost = conn.getRemoteAddress();
        int remotePort = conn.getRemotePort();
        if (connUserId != null && connUserId.equals(userId) && !connSessionId.equals(sessionId)) {
            conn.removeAttribute("USERID");
            Map<String, Object> logData = new HashMap<String, Object>();
            logData.put("meetingId", meetingId);
            logData.put("userId", userId);
            logData.put("oldConnId", connSessionId);
            logData.put("newConnId", sessionId);
            logData.put("clientId", clientId);
            logData.put("remoteAddress", remoteHost + ":" + remotePort);
            logData.put("event", "removing_defunct_connection");
            logData.put("description", "Removing defunct connection BBB Video.");
            Gson gson = new Gson();
            String logStr = gson.toJson(logData);
            log.info("Removing defunct connection: data={}", logStr);
        }
    }
    String remoteHost = Red5.getConnectionLocal().getRemoteAddress();
    int remotePort = Red5.getConnectionLocal().getRemotePort();
    String clientId = Red5.getConnectionLocal().getClient().getId();
    Map<String, Object> logData = new HashMap<String, Object>();
    logData.put("meetingId", meetingId);
    logData.put("userId", userId);
    logData.put("connType", connType);
    logData.put("connId", sessionId);
    logData.put("clientId", clientId);
    logData.put("remoteAddress", remoteHost + ":" + remotePort);
    logData.put("event", "user_joining_bbb_video");
    logData.put("description", "User joining BBB Video.");
    Gson gson = new Gson();
    String logStr = gson.toJson(logData);
    log.info("User joining bbb-video: data={}", logStr);
    return super.roomConnect(connection, params);
}
Also used : HashMap(java.util.HashMap) Gson(com.google.gson.Gson) IConnection(org.red5.server.api.IConnection)

Example 18 with IConnection

use of org.red5.server.api.IConnection in project bigbluebutton by bigbluebutton.

the class VideoApplication method streamBroadcastClose.

@Override
public void streamBroadcastClose(IBroadcastStream stream) {
    super.streamBroadcastClose(stream);
    IConnection conn = Red5.getConnectionLocal();
    String scopeName;
    if (conn != null) {
        scopeName = conn.getScope().getName();
    } else {
        log.info("Connection local was null, using scope name from the stream: {}", stream);
        scopeName = stream.getScope().getName();
    }
    log.info("Stream broadcast closed for stream=[{}] meeting=[{}]", stream.getPublishedName(), scopeName);
    String userId = getUserId();
    String meetingId = conn.getScope().getName();
    String streamId = stream.getPublishedName();
    Matcher matcher = RECORD_STREAM_ID_PATTERN.matcher(stream.getPublishedName());
    if (matcher.matches()) {
        IStreamListener listener = streamListeners.remove(scopeName + "-" + stream.getPublishedName());
        if (listener != null) {
            ((VideoStreamListener) listener).streamStopped();
            stream.removeStreamListener(listener);
        }
        long publishDuration = (System.currentTimeMillis() - stream.getCreationTime()) / 1000;
        log.info("Stop recording event for stream=[{}] meeting=[{}]", stream.getPublishedName(), scopeName);
        Map<String, String> event = new HashMap<String, String>();
        event.put("module", "WEBCAM");
        event.put("timestamp", genTimestamp().toString());
        event.put("meetingId", scopeName);
        event.put("stream", stream.getPublishedName());
        event.put("duration", new Long(publishDuration).toString());
        event.put("eventName", "StopWebcamShareEvent");
        recordingService.record(scopeName, event);
    }
}
Also used : IStreamListener(org.red5.server.api.stream.IStreamListener) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) IConnection(org.red5.server.api.IConnection)

Example 19 with IConnection

use of org.red5.server.api.IConnection in project bigbluebutton by bigbluebutton.

the class VideoApplication method streamPublishStart.

@Override
public void streamPublishStart(IBroadcastStream stream) {
    super.streamPublishStart(stream);
    IConnection conn = Red5.getConnectionLocal();
    log.info("streamPublishStart " + stream.getPublishedName() + " " + System.currentTimeMillis() + " " + conn.getScope().getName());
}
Also used : IConnection(org.red5.server.api.IConnection)

Example 20 with IConnection

use of org.red5.server.api.IConnection in project bigbluebutton by bigbluebutton.

the class Red5AppAdapter method streamBroadcastClose.

@Override
public void streamBroadcastClose(IBroadcastStream stream) {
    super.streamBroadcastClose(stream);
    log.info("streamBroadcastStop " + stream.getPublishedName() + "]");
    String streamId = stream.getPublishedName();
    Matcher matcher = STREAM_ID_PATTERN.matcher(stream.getPublishedName());
    if (matcher.matches()) {
        String meetingId = matcher.group(1).trim();
        app.streamStopped(meetingId, streamId);
        boolean recordVideoStream = app.recordStream(meetingId, streamId);
        if (recordVideoStream) {
            IConnection conn = Red5.getConnectionLocal();
            String scopeName;
            if (conn != null) {
                scopeName = conn.getScope().getName();
            } else {
                log.info("Connection local was null, using scope name from the stream: {}", stream);
                scopeName = stream.getScope().getName();
            }
            IStreamListener listener = streamListeners.remove(scopeName + "-" + stream.getPublishedName());
            if (listener != null) {
                stream.removeStreamListener(listener);
            }
            String filename = recordingDirectory;
            if (!filename.endsWith("/")) {
                filename.concat("/");
            }
            filename = filename.concat(meetingId).concat("/").concat(stream.getPublishedName()).concat(".flv");
            long publishDuration = (System.currentTimeMillis() - stream.getCreationTime()) / 1000;
            Map<String, String> event = new HashMap<String, String>();
            event.put("module", "Deskshare");
            event.put("timestamp", genTimestamp().toString());
            event.put("meetingId", scopeName);
            event.put("stream", stream.getPublishedName());
            event.put("file", filename);
            event.put("duration", new Long(publishDuration).toString());
            event.put("eventName", "DeskshareStoppedEvent");
            recordingService.record(scopeName, event);
        }
        Map<String, Object> logData = new HashMap<String, Object>();
        logData.put("meetingId", meetingId);
        logData.put("streamId", streamId);
        logData.put("recorded", recordVideoStream);
        Gson gson = new Gson();
        String logStr = gson.toJson(logData);
        log.info("ScreenShare broadcast stopped: data={}", logStr);
    } else {
        log.error("Invalid streamid format [{}]", streamId);
    }
}
Also used : IStreamListener(org.red5.server.api.stream.IStreamListener) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) IConnection(org.red5.server.api.IConnection)

Aggregations

IConnection (org.red5.server.api.IConnection)33 HashMap (java.util.HashMap)8 IScope (org.red5.server.api.scope.IScope)7 Gson (com.google.gson.Gson)6 Matcher (java.util.regex.Matcher)4 IServiceCapableConnection (org.red5.server.api.service.IServiceCapableConnection)4 ClientBroadcastStream (org.red5.server.stream.ClientBroadcastStream)4 ArrayList (java.util.ArrayList)2 ISharedObject (org.red5.server.api.so.ISharedObject)2 IStreamListener (org.red5.server.api.stream.IStreamListener)2 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 IoBuffer (org.apache.mina.core.buffer.IoBuffer)1 ScreenshareStreamListener (org.bigbluebutton.app.screenshare.ScreenshareStreamListener)1 PeerNotFoundException (org.bigbluebutton.voiceconf.sip.PeerNotFoundException)1 ConnectionClientMethodInvoker (org.red5.app.sip.ConnectionClientMethodInvoker)1 RTMPMinaConnection (org.red5.server.net.rtmp.RTMPMinaConnection)1 VideoData (org.red5.server.net.rtmp.event.VideoData)1