What is NextRTC?

PROJECT IS NO LONGER SUPPORTED!

NextRTC is a rich java library providing WebRTC signaling server. You can use it as standalone web application, or add it as a tenant to your existing Spring application. It can use various websocket implementation (e.g. JSR 356, Spring WebSocket, Netty WebSocket) to communicate with clients. Solution called NextRTC has easy to use backend and frontend API. The frontend implementation is done in similar way as it was done by Simple WebRTC. Frontend client to NextRTC is available here. To setup working example you have to implement only code shown below:

var nextRTC = new NextRTC({
wsURL: ‘wss://’ + location.hostname + (location.port ? ‘:’ + location.port : ”) + ‘/signaling’,
mediaConfig: { video: true, audio: false },
peerConfig: {
iceServers: [{ urls: ‘stun:23.21.150.121’ }, { urls: ‘stun:stun.l.google.com:19302’ }],
iceTransportPolicy: ‘all’
}
});
nextRTC.on(‘created’, function (event) {
// do something when room has been created
});

nextRTC.on(‘joined’, function(event) {
// do something when you have been joined
});
nextRTC.on(‘newJoined’, function(event) {
// do something when someone has joined
});
nextRTC.on(‘localStream’, function(stream) {
// do something when local stream comes
});
nextRTC.on(‘remoteStream’, function(stream) {
// do something when remote stream comes
});
nextRTC.on(‘left’, function(event) {
// do something when someone left
});

Above example was taken from small web application used as frontend for all examples.

Then on backend side you have to write an adapter for websocket implementation used by you. Here is example prepared for Spring Websocket implementation.

public class MyEndpoint extends TextWebSocketHandler {
private final NextRTCServer server;

@Autowired
MyEndpoint(NextRTCServer server) {
this.server = server;
}

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
server.register(new SessionWrapper(session));
}

@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
server.handle(NextRTCServer.MessageDecoder.decode(message.getPayload()), new SessionWrapper(session));
}

@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
server.unregister(new SessionWrapper(session), status.getReason());
}

private static class SessionWrapper implements Connection {
private final WebSocketSession session;

public SessionWrapper(WebSocketSession session) {
this.session = session;
}

@Override
public String getId() {
return session.getId();
}

@Override
public boolean isOpen() {
return session.isOpen();
}

@Override
public void sendObject(Object object) {
try {
session.sendMessage(new TextMessage(NextRTCServer.MessageEncoder.encode(object)));
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}

And It’s all what you need to create a videochat.

For more details please take a look to github project.

Already I have some simple examples, try it out and leave comment!

Enjoy!!!