On GitHub I was asked how to implement own signal using NextRTC.
In configuration file you have to autowire SignalResolver as shown below:
@Autowired private SignalResolver resolver; @Autowired private MessageSender sender;
then you have to add bean which will add your handlers. Handler has to implement only one interface SignalHandler. That interface has only one method so you can write it just like a inline lambda expression:
@Bean public Signal addCustomNextRTCHandlers(){ Signal upperCase = Signal.fromString("upperCase"); resolver.addCustomSignal(upperCase, (msg)-> { sender.send(InternalMessage.create() .to(msg.getFrom()) .content(msg.getContent().toUpperCase()) .signal(upperCase) .build()); }); return upperCase; }
In this example new handler (upperCase) will take a content of incomming message, and resend the content to sender with uppercase letters.
Whole configuration should like this:
@Configuration @Import(NextRTCConfig.class) public class EndpointConfig { @Autowired private SignalResolver resolver; @Autowired private MessageSender sender; @Bean public Signal addCustomNextRTCHandlers(){ Signal upperCase = Signal.fromString("upperCase"); resolver.addCustomSignal(upperCase, (msg)-> { sender.send(InternalMessage.create() .to(msg.getFrom()) .content(msg.getContent().toUpperCase()) .signal(upperCase) .build()); }); return upperCase; } }
On the js side you have to write two methods. One for sending new signal, and one which will react on the response:
NextRTC.prototype.upperCase = function upperCase(content, custom) { var nextRTC = this; nextRTC.request('upperCase', null, content, custom); }; // this one will send content which will be handled by our handler nextRTC.on('upperCase', content => { // here you should handle the response });