mediaconnection.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /**
  2. * Wraps the streaming interface between two Peers.
  3. */
  4. function MediaConnection(peer, localStream, options) {
  5. if (!(this instanceof MediaConnection)) return new MediaConnection(peer, localStream, options);
  6. EventEmitter.call(this);
  7. options = util.extend({
  8. }, options);
  9. this.localStream = localStream;
  10. this.peer = peer;
  11. };
  12. util.inherits(MediaConnection, EventEmitter);
  13. MediaConnection.prototype.receiveStream = function(stream) {
  14. console.log('receiving stream', stream);
  15. this.remoteStream = stream;
  16. this.emit('stream', stream);
  17. //this._cleanup();
  18. };
  19. MediaConnection.prototype.answer = function(stream) {
  20. this.localStream = stream;
  21. this.emit('answer', stream);
  22. //this._cleanup();
  23. };
  24. MediaConnection.prototype.answered = function(stream) {
  25. this.emit('stream', this.remoteStream);
  26. //this._cleanup();
  27. };
  28. /**
  29. * Exposed functionality for users.
  30. */
  31. /** Allows user to close connection. */
  32. MediaConnection.prototype.close = function() {
  33. //this._cleanup();
  34. };
  35. /**
  36. * Gets the brokering ID of the peer that you are connected with.
  37. * Note that this ID may be out of date if the peer has disconnected from the
  38. * server, so it's not recommended that you use this ID to identify this
  39. * connection.
  40. */
  41. MediaConnection.prototype.getPeer = function() {
  42. return this.peer;
  43. };