当前位置: 首页>>代码示例>>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;未经允许,请勿转载。