<commit_before>var naf = require('../NafIndex');

var EasyRtcInterface = require('../network_interfaces/EasyRtcInterface');
var WebSocketEasyRtcInterface = require('../network_interfaces/WebSocketEasyRtcInterface');
var FirebaseWebRtcInterface = require('../network_interfaces/FirebaseWebRtcInterface');

AFRAME.registerComponent('networked-scene', {
  schema: {
    app: {default: 'default'},
    room: {default: 'default'},
    connectOnLoad: {default: true},
    signalURL: {default: '/'},
    onConnect: {default: 'onConnect'},
    webrtc: {default: false},
    webrtcAudio: {default: false},

    firebase: {default: false},
    firebaseApiKey: {default: ''},
    firebaseAuthType: {default: 'none', oneOf: ['none', 'anonymous']},
    firebaseAuthDomain: {default: ''},
    firebaseDatabaseURL: {default: ''},

    debug: {default: false},
  },

  init: function() {
    this.el.addEventListener('connect', this.connect.bind(this));
    if (this.data.connectOnLoad) {
      this.el.emit('connect', null, false);
    }
  },

  /**
   * Connect to signalling server and begin connecting to other clients
   */
  connect: function () {
    naf.log.setDebug(this.data.debug);
    naf.log.write('Networked-Aframe Connecting...');

    // easyrtc.enableDebug(true);
    this.checkDeprecatedProperties();
    this.setupNetworkInterface();

    if (this.hasOnConnectFunction()) {
      this.callOnConnect();
    }
    naf.connection.connect(this.data.app, this.data.room, this.data.webrtcAudio);
  },

  checkDeprecatedProperties: function() {
    // No current
  },

  setupNetworkInterface: function() {
    var networkInterface;
    if (this.data.webrtc) {
      if (this.data.firebase) {
        var firebaseWebRtcInterface = new FirebaseWebRtcInterface(firebase, {
          authType: this.data.firebaseAuthType,
          apiKey: this.data.firebaseApiKey,
          authDomain: this.data.firebaseAuthDomain,
          databaseURL: this.data.firebaseDatabaseURL
        });
        networkInterface = firebaseWebRtcInterface;
      } else {
        var easyRtcInterface = new EasyRtcInterface(easyrtc);
        easyRtcInterface.setSignalUrl(this.data.signalURL);
        networkInterface = easyRtcInterface;
      }
    } else {
      var websocketInterface = new WebSocketEasyRtcInterface(easyrtc);
      websocketInterface.setSignalUrl(this.data.signalURL);
      networkInterface = websocketInterface;
      if (this.data.webrtcAudio) {
        naf.log.error('networked-scene: webrtcAudio option will only be used if webrtc is set to true. webrtc is currently false');
      }
    }
    naf.connection.setNetworkInterface(networkInterface);
  },

  hasOnConnectFunction: function() {
    return this.data.onConnect != '' && window.hasOwnProperty(this.data.onConnect);
  },

  callOnConnect: function() {
    naf.connection.onLogin(window[this.data.onConnect]);
  }
});<commit_msg>expose NAF options for convenience<commit_after>var naf = require('../NafIndex');

var EasyRtcInterface = require('../network_interfaces/EasyRtcInterface');
var WebSocketEasyRtcInterface = require('../network_interfaces/WebSocketEasyRtcInterface');
var FirebaseWebRtcInterface = require('../network_interfaces/FirebaseWebRtcInterface');

AFRAME.registerComponent('networked-scene', {
  schema: {
    app: {default: 'default'},
    room: {default: 'default'},
    connectOnLoad: {default: true},
    signalURL: {default: '/'},
    onConnect: {default: 'onConnect'},
    webrtc: {default: false},
    webrtcAudio: {default: false},

    firebase: {default: false},
    firebaseApiKey: {default: ''},
    firebaseAuthType: {default: 'none', oneOf: ['none', 'anonymous']},
    firebaseAuthDomain: {default: ''},
    firebaseDatabaseURL: {default: ''},

    debug: {default: false},

    updateRate: {default: 0},
    useLerp: {default: true},
    compressSyncPackets: {default: false},
  },

  init: function() {
    if (this.data.updateRate) { naf.options.updateRate = this.data.updateRate; }
    naf.options.useLerp = this.data.useLerp;
    naf.options.compressSyncPackets = this.data.compressSyncPackets;

    this.el.addEventListener('connect', this.connect.bind(this));
    if (this.data.connectOnLoad) {
      this.el.emit('connect', null, false);
    }
  },

  /**
   * Connect to signalling server and begin connecting to other clients
   */
  connect: function () {
    naf.log.setDebug(this.data.debug);
    naf.log.write('Networked-Aframe Connecting...');

    // easyrtc.enableDebug(true);
    this.checkDeprecatedProperties();
    this.setupNetworkInterface();

    if (this.hasOnConnectFunction()) {
      this.callOnConnect();
    }
    naf.connection.connect(this.data.app, this.data.room, this.data.webrtcAudio);
  },

  checkDeprecatedProperties: function() {
    // No current
  },

  setupNetworkInterface: function() {
    var networkInterface;
    if (this.data.webrtc) {
      if (this.data.firebase) {
        var firebaseWebRtcInterface = new FirebaseWebRtcInterface(firebase, {
          authType: this.data.firebaseAuthType,
          apiKey: this.data.firebaseApiKey,
          authDomain: this.data.firebaseAuthDomain,
          databaseURL: this.data.firebaseDatabaseURL
        });
        networkInterface = firebaseWebRtcInterface;
      } else {
        var easyRtcInterface = new EasyRtcInterface(easyrtc);
        easyRtcInterface.setSignalUrl(this.data.signalURL);
        networkInterface = easyRtcInterface;
      }
    } else {
      var websocketInterface = new WebSocketEasyRtcInterface(easyrtc);
      websocketInterface.setSignalUrl(this.data.signalURL);
      networkInterface = websocketInterface;
      if (this.data.webrtcAudio) {
        naf.log.error('networked-scene: webrtcAudio option will only be used if webrtc is set to true. webrtc is currently false');
      }
    }
    naf.connection.setNetworkInterface(networkInterface);
  },

  hasOnConnectFunction: function() {
    return this.data.onConnect != '' && window.hasOwnProperty(this.data.onConnect);
  },

  callOnConnect: function() {
    naf.connection.onLogin(window[this.data.onConnect]);
  }
});

{'fraction_non_alphanumeric': 0.13181221273801708, 'fraction_numerical': 0.00016414970453053183, 'mean_word_length': 3.581203007518797, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1059761', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1836, 'n_words': 331}