vendor/opentok.js
function PeerConnectionChannels (pc) {
    /// Private Data
    var channels = [],
        api = {};


    /// Private API

    var remove = function remove (channel) {
      OT.$.filter(channels, function(c) {
        return channel !== c;
      });
    };

    var add = function add (nativeChannel) {
      var channel = new DataChannel(nativeChannel);
      channels.push(channel);

      channel.on('close', function() {
        remove(channel);
      });

      return channel;
    };


    /// Public API

    api.add = function (label, options) {
      return add(pc.createDataChannel(label, options));
    };

    api.addMany = function (newChannels) {
      for (var label in newChannels) {
        if (newChannels.hasOwnProperty(label)) {
          api.add(label, newChannels[label]);
        }
      }
    };

    api.get = function (label, options) {
      return OT.$.find(channels, function(channel) {
        return channel.equals(label, options);
      });
    };

    api.getOrAdd = function (label, options) {
      var channel = api.get(label, options);
      if (!channel) {
        channel = api.add(label, options);
      }

      return channel;
    };

    api.destroy = function () {
      OT.$.forEach(channels, function(channel) {
        channel.close();
      });

      channels = [];
    };


    /// Init

    pc.addEventListener('datachannel', function(event) {
      add(event.channel);
    }, false);

    return api;
  }
function PeerConnectionChannels (pc) {
    /// Private Data
    var channels = [],
        api = {};


    /// Private API

    var remove = function remove (channel) {
      OT.$.filter(channels, function(c) {
        return channel !== c;
      });
    };

    var add = function add (nativeChannel) {
      var channel = new DataChannel(nativeChannel);
      channels.push(channel);

      channel.on('close', function() {
        remove(channel);
      });

      return channel;
    };


    /// Public API

    api.add = function (label, options) {
      return add(pc.createDataChannel(label, options));
    };

    api.addMany = function (newChannels) {
      for (var label in newChannels) {
        if (newChannels.hasOwnProperty(label)) {
          api.add(label, newChannels[label]);
        }
      }
    };

    api.get = function (label, options) {
      return OT.$.find(channels, function(channel) {
        return channel.equals(label, options);
      });
    };

    api.getOrAdd = function (label, options) {
      var channel = api.get(label, options);
      if (!channel) {
        channel = api.add(label, options);
      }

      return channel;
    };

    api.destroy = function () {
      OT.$.forEach(channels, function(channel) {
        channel.close();
      });

      channels = [];
    };


    /// Init

    pc.addEventListener('datachannel', function(event) {
      add(event.channel);
    }, false);

    return api;
  }
function PeerConnectionChannels ( pc ) { /// Private Data var channels = [ ] , api = { } ; /// Private API var remove = function remove ( channel ) { OT . $ . filter ( channels , function ( c ) { return channel !== c ; } ) ; } ; var add = function add ( nativeChannel ) { var channel = new DataChannel ( nativeChannel ) ; channels . push ( channel ) ; channel . on ( 'close' , function ( ) { remove ( channel ) ; } ) ; return channel ; } ; /// Public API api . add = function ( label , options ) { return add ( pc . createDataChannel ( label , options ) ) ; } ; api . addMany = function ( newChannels ) { for ( var label in newChannels ) { if ( newChannels . hasOwnProperty ( label ) ) { api . add ( label , newChannels [ label ] ) ; } } } ; api . get = function ( label , options ) { return OT . $ . find ( channels , function ( channel ) { return channel . equals ( label , options ) ; } ) ; } ; api . getOrAdd = function ( label , options ) { var channel = api . get ( label , options ) ; if ( ! channel ) { channel = api . add ( label , options ) ; } return channel ; } ; api . destroy = function ( ) { OT . $ . forEach ( channels , function ( channel ) { channel . close ( ) ; } ) ; channels = [ ] ; } ; /// Init pc . addEventListener ( 'datachannel' , function ( event ) { add ( event . channel ) ; } , false ) ; return api ; }
Contains a collection of DataChannels for a particular RTCPeerConnection  @param [RTCPeerConnection] pc A native peer connection object  @constructor @private
Contains a collection of DataChannels for a particular RTCPeerConnection