View difference between Paste ID: m4xHL6i9 and w3C4iU0i
SHOW: | | - or go back to the newest paste.
1
package com.testing.myoflademo;
2
3
4
import java.io.IOException;
5
import java.util.ArrayList;
6
import java.util.Iterator;
7
import java.util.List;
8
9
import org.red5.server.adapter.MultiThreadedApplicationAdapter;
10
import org.red5.server.api.IClient;
11
import org.red5.server.api.IConnection;
12
import org.red5.server.api.Red5;
13
import org.red5.server.api.scope.IScope;
14
import org.red5.server.api.service.IServiceCapableConnection;
15
import org.red5.server.api.stream.IBroadcastStream;
16
import org.red5.server.api.stream.IStreamAwareScopeHandler;
17
import org.red5.server.api.stream.ResourceExistException;
18
import org.red5.server.api.stream.ResourceNotFoundException;
19
20
public class Application extends MultiThreadedApplicationAdapter implements IStreamAwareScopeHandler {
21
22
	private List<String> streamsInRoom = new ArrayList<String>();	
23
	
24
	@Override
25
	public boolean appStart(IScope scope) {
26
		System.out.println("[ appStart ]");
27
		return true;
28
	}
29
	
30
	@Override
31
	public boolean appConnect(IConnection conn, Object[] params) {
32
		System.out.println("[ appConnect ]");
33
		return true;
34
	}
35
	
36
	@Override
37
	public boolean appJoin(IClient client, IScope scope) {
38
		System.out.println("[ appJoin ]");
39
		return true;
40
	}
41
	
42
	public void streamPublishStart(IBroadcastStream stream) {
43
		System.out.println("[ streamPublishStart ]");
44
	}
45
	
46
	public void streamBroadcastStart(IBroadcastStream stream) {
47
    	System.out.println("[ streamBroadcastStart ]");
48
    	for (String streamName : streamsInRoom) {
49
    		((IServiceCapableConnection) Red5.getConnectionLocal()).invoke("newStreamInRoom", new Object[] {streamName});
50
    	}
51
    	streamsInRoom.add(stream.getPublishedName());
52
    	// Save stream
53-
//		try {
53+
		try {
54-
//			stream.saveAs(stream.getName(), false);
54+
			stream.saveAs(stream.getName(), false);
55-
//		} catch (IOException | ResourceNotFoundException
55+
		} catch (IOException | ResourceNotFoundException
56-
//				| ResourceExistException e) {
56+
				| ResourceExistException e) {
57-
//			e.printStackTrace();
57+
			e.printStackTrace();
58-
//		}
58+
		}
59
    	// Notifico a todos los usuarios menos el actual
60
    	IClient newClient = Red5.getConnectionLocal().getClient();
61
    	Iterator<IConnection> itConnections = Red5.getConnectionLocal().getScope().getClientConnections().iterator();
62
    	while(itConnections.hasNext()) {
63
    		IConnection conn = itConnections.next();
64
    		if (!conn.getClient().getId().equals(newClient.getId()) && conn instanceof IServiceCapableConnection) {
65
    			((IServiceCapableConnection) conn).invoke("newStreamInRoom", new Object[] {stream.getPublishedName()});
66
    		}
67
    	}
68
	}
69
	
70
    public void streamBroadcastClose(IBroadcastStream stream) {
71
    	System.out.println("[ streamBroadcastClose ]");
72
    	streamsInRoom.remove(stream.getPublishedName());
73
	}
74
	
75
}