当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript eventemitter3.EventEmitter类代码示例

本文整理汇总了TypeScript中eventemitter3.EventEmitter的典型用法代码示例。如果您正苦于以下问题:TypeScript EventEmitter类的具体用法?TypeScript EventEmitter怎么用?TypeScript EventEmitter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了EventEmitter类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: constructor

  constructor() {
    var eventBus = new EventEmitter()

    this.on = function (type: string, fn: Function) {
      return eventBus.on(type, fn as EventEmitter.ListenerFn)
    }

    this.off = function (type: string, fn: Function) {
      return eventBus.off(type, fn as EventEmitter.ListenerFn)
    }

    this.emit =  function (type: string, event: any) {
      return eventBus.emit(type, event)
    }
  }
开发者ID:olegsmetanin,项目名称:uikit,代码行数:15,代码来源:EventBus.ts

示例2: 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

示例3: 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

示例4: 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

示例5: EventEmitter

#!/bin/sh
':' //# http://sambal.org/?p=1014 ; exec `dirname $0`/../../node_modules/.bin/ts-node "$0" "$@"
console.log('Hello, world !')

import { ListenerFn, EventEmitter } from 'eventemitter3'


const ee = new EventEmitter()

ee.on('event', () => {
	console.log('an event occurred!')
})
ee.emit('event')
开发者ID:Offirmo,项目名称:web-tech-experiments,代码行数:13,代码来源:index.ts

示例6: 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

示例7:

comm_socket.on("disconnect", () => {
    for (let id in state) {
        state[id] = false;
        for (let i = 0; i < listeners[id].length; ++i) {
            listeners[id][i](id, state[id]);
        }
    }
    event_emitter.emit("users-online-updated");
});
开发者ID:PowerOlive,项目名称:online-go.com,代码行数:9,代码来源:online_status.ts

示例8: on

  on(name, handler, scope?) {
    this.emitter.on(name, handler);

    if (scope) {
      const unbind = scope.$on('$destroy', () => {
        this.emitter.off(name, handler);
        unbind();
      });
    }
  }
开发者ID:grafana,项目名称:grafana,代码行数:10,代码来源:emitter.ts

示例9: function

 this.emit =  function (type: string, event: any) {
   return eventBus.emit(type, event)
 }
开发者ID:olegsmetanin,项目名称:uikit,代码行数:3,代码来源:EventBus.ts

示例10: emit

 emit(name, data?) {
   this.emitter.emit(name, data);
 }
开发者ID:grafana,项目名称:grafana,代码行数:3,代码来源:emitter.ts

示例11: off

 off(name, handler) {
   this.emitter.off(name, handler);
 }
开发者ID:grafana,项目名称:grafana,代码行数:3,代码来源:emitter.ts

示例12: removeAllListeners

 removeAllListeners(evt?) {
   this.emitter.removeAllListeners(evt);
 }
开发者ID:grafana,项目名称:grafana,代码行数:3,代码来源:emitter.ts

示例13: unbind

 const unbind = scope.$on('$destroy', () => {
   this.emitter.off(name, handler);
   unbind();
 });
开发者ID:grafana,项目名称:grafana,代码行数:4,代码来源:emitter.ts


注:本文中的eventemitter3.EventEmitter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。