UNPKG

rtc-pluggable-signaller

Version:

Use either rtc-signaller or your own signaller which matches the signaller API

30 lines (23 loc) 1.07 kB
/** # rtc-pluggable-signaller By using `rtc-pluggable-signaller` in your code, you provide the ability for your package to customize which signalling client it uses (and thus have significant control) over how signalling operates in your environment. ## How it Works The pluggable signaller looks in the provided `opts` for a `signaller` attribute. If the value of this attribute is a string, then it is assumed that you wish to use the default [`rtc-signaller`](https://github.com/rtc-io/rtc-signaller) in your package. If, however, it is not a string value then it will be passed straight back as the signaller (assuming that you have provided an object that is compliant with the rtc.io signalling API). **/ module.exports = function(opts) { var signaller = (opts || {}).signaller; var messenger = (opts || {}).messenger || require('rtc-switchboard-messenger'); if (typeof signaller == 'string' || (signaller instanceof String)) { return require('rtc-signaller')(messenger(signaller, opts), opts); } return signaller; };