當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript EventEmitter.call方法代碼示例

本文整理匯總了TypeScript中eventemitter3.EventEmitter.call方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript EventEmitter.call方法的具體用法?TypeScript EventEmitter.call怎麽用?TypeScript EventEmitter.call使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在eventemitter3.EventEmitter的用法示例。


在下文中一共展示了EventEmitter.call方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: Socket

export function Socket(secure, host, port, path, key, wsport) {
  if (!(this instanceof Socket))
    return new Socket(secure, host, port, path, key, wsport);

  wsport = wsport || port;

  EventEmitter.call(this);

  // Disconnected manually.
  this.disconnected = false;
  this._queue = [];

  var httpProtocol = secure ? "https://" : "http://";
  var wsProtocol = secure ? "wss://" : "ws://";
  this._httpUrl = httpProtocol + host + ":" + port + path + key;
  this._wsUrl = wsProtocol + host + ":" + wsport + path + "peerjs?key=" + key;
}
開發者ID:omnajjar,項目名稱:peerjs,代碼行數:17,代碼來源:socket.ts

示例2: DataConnection

export function DataConnection(peer, provider, options) {
  if (!(this instanceof DataConnection))
    return new DataConnection(peer, provider, options);
  EventEmitter.call(this);

  this.options = util.extend(
    {
      serialization: "binary",
      reliable: false
    },
    options
  );

  // Connection is not open yet.
  this.open = false;
  this.type = "data";
  this.peer = peer;
  this.provider = provider;

  this.id =
    this.options.connectionId || DataConnection._idPrefix + util.randomToken();

  this.label = this.options.label || this.id;
  this.metadata = this.options.metadata;
  this.serialization = this.options.serialization;
  this.reliable = this.options.reliable;

  // Data channel buffering.
  this._buffer = [];
  this._buffering = false;
  this.bufferSize = 0;

  // For storing large data.
  this._chunkedData = {};

  if (this.options._payload) {
    this._peerBrowser = this.options._payload.browser;
  }

  Negotiator.startConnection(
    this,
    this.options._payload || {
      originator: true
    }
  );
}
開發者ID:omnajjar,項目名稱:peerjs,代碼行數:46,代碼來源:dataconnection.ts

示例3: MediaConnection

export function MediaConnection(peer, provider, options) {
  if (!(this instanceof MediaConnection))
    return new MediaConnection(peer, provider, options);
  EventEmitter.call(this);

  this.options = util.extend({}, options);

  this.open = false;
  this.type = "media";
  this.peer = peer;
  this.provider = provider;
  this.metadata = this.options.metadata;
  this.localStream = this.options._stream;

  this.id =
    this.options.connectionId || MediaConnection._idPrefix + util.randomToken();
  if (this.localStream) {
    Negotiator.startConnection(this, {
      _stream: this.localStream,
      originator: true
    });
  }
}
開發者ID:omnajjar,項目名稱:peerjs,代碼行數:23,代碼來源:mediaconnection.ts

示例4: Peer

export function Peer(id, options): void {
  if (!(this instanceof Peer)) return new Peer(id, options);
  EventEmitter.call(this);

  // Deal with overloading
  if (id && id.constructor == Object) {
    options = id;
    id = undefined;
  } else if (id) {
    // Ensure id is a string
    id = id.toString();
  }
  //

  // Configurize options
  options = util.extend(
    {
      debug: 0, // 1: Errors, 2: Warnings, 3: All logs
      host: util.CLOUD_HOST,
      port: util.CLOUD_PORT,
      path: "/",
      token: util.randomToken(),
      config: util.defaultConfig
    },
    options
  );
  options.key = "peerjs";
  this.options = options;
  // Detect relative URL host.
  if (options.host === "/") {
    options.host = window.location.hostname;
  }
  // Set path correctly.
  if (options.path[0] !== "/") {
    options.path = "/" + options.path;
  }
  if (options.path[options.path.length - 1] !== "/") {
    options.path += "/";
  }

  // Set whether we use SSL to same as current host
  if (options.secure === undefined && options.host !== util.CLOUD_HOST) {
    options.secure = util.isSecure();
  } else if (options.host == util.CLOUD_HOST) {
    options.secure = true;
  }
  // Set a custom log function if present
  if (options.logFunction) {
    util.setLogFunction(options.logFunction);
  }
  util.setLogLevel(options.debug);
  //

  // Sanity checks
  // Ensure WebRTC supported
  if (!util.supports.audioVideo && !util.supports.data) {
    this._delayedAbort(
      "browser-incompatible",
      "The current browser does not support WebRTC"
    );
    return;
  }
  // Ensure alphanumeric id
  if (!util.validateId(id)) {
    this._delayedAbort("invalid-id", 'ID "' + id + '" is invalid');
    return;
  }
  // Ensure valid key
  // if (!util.validateKey(options.key)) {
  //   this._delayedAbort(
  //     "invalid-key",
  //     'API KEY "' + options.key + '" is invalid'
  //   );
  //   return;
  // }
  // Ensure not using unsecure cloud server on SSL page
  // if (options.secure && options.host === "0.peerjs.com") {
  //   this._delayedAbort(
  //     "ssl-unavailable",
  //     "The cloud server currently does not support HTTPS. Please run your own PeerServer to use HTTPS."
  //   );
  //   return;
  // }
  //

  // States.
  this.destroyed = false; // Connections have been killed
  this.disconnected = false; // Connection to PeerServer killed but P2P connections still active
  this.open = false; // Sockets and such are not yet open.
  //

  // References
  this.connections = {}; // DataConnections for this peer.
  this._lostMessages = {}; // src => [list of messages]
  //

  // Start the server connection
  this._initializeServerConnection();
  if (id) {
    this._initialize(id);
//.........這裏部分代碼省略.........
開發者ID:omnajjar,項目名稱:peerjs,代碼行數:101,代碼來源:peer.ts


注:本文中的eventemitter3.EventEmitter.call方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。