sink.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. function SinkPeer(options, readyfn) {
  2. this._config = options.config || {};
  3. this._source = options.source || 'StreamAPI';
  4. this._pc = null;
  5. this._id = null;
  6. this._dc = null;
  7. this._socket = io.connect('http://localhost');
  8. this.socketInit(readyfn);
  9. };
  10. SinkPeer.prototype.socketInit = function(cb) {
  11. self = this;
  12. this._socket.emit('sink', { source: this._source }, function(data) {
  13. self._id = data.id;
  14. self._pc = new mozRTCPeerConnection(self._config);
  15. this.setupDataChannel();
  16. self._socket.on('offer', function(data) {
  17. self._pc.setRemoteDescription(data.sdp, function() {
  18. self._pc.createAnswer(function(answer) {
  19. self._pc.setLocalDescription(answer, function() {
  20. self._socket.emit('answer',
  21. { 'sink' = this._id,'sdp': answer, 'source': data.source });
  22. // Firefoxism
  23. self._pc.connectDataConnection(5001,5000);
  24. });
  25. });
  26. });
  27. });
  28. cb(self._id);
  29. });
  30. });
  31. SinkPeer.prototype.setupDataChannel = function() {
  32. this._pc.ondatachannel = function(dc) {
  33. dc.binaryType = "blob";
  34. dc.onmessage = function(e) {
  35. };
  36. this._dc = dc;
  37. };
  38. this._pc.onclosedconnection = function() {
  39. // ??
  40. };
  41. };