123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- function SourcePeer(options) {
- this._config = options.config || {};
- this._streams = options.streamType || 'd';
- this._name = options.name || 'StreamAPI';
-
- this._pcs = {};
- this._id = null;
-
- this._dcs = {};
- this._socket = io.connect('http://localhost');
- this.socketInit();
- };
- SourcePeer.prototype.socketInit = function() {
- self = this;
- this._socket.emit('source', function(data) {
- self._id = data.id;
- self._socket.on('sink-connected', function(data) {
-
- target = data.sink;
- var pc = new mozRTCPeerConnection(self._config);
- self._pcs[target] = pc;
-
- self.handleStream(pc, target, function() {
- pc.createOffer(function(offer) {
- pc.setLocalDescription(offer);
- self._socket.emit('offer',
- { 'sdp': offer, 'sink': target, 'source': this._id });
- });
- });
- });
- self._socket.on('answer', function(data, fn) {
- self._pcs[data.sink].setRemoteDescription(data.sdp);
- fn();
-
- self._pcs[data.sink].connectDataConnection(5000,5001);
- });
- });
- };
- SourcePeer.prototype.handleStream(pc, target, cb) {
-
- this.setupDataChannel(pc, target);
-
- };
- SourcePeer.prototype.setupDataChannel = function(pc, target) {
- pc.onconnection = function() {
- var dc = pc.createDataChannel(this._name, {}, target);
- this._dc[target] = dc;
- dc.binaryType = 'blob';
- dc.onmessage = function(e) {
- this.handleDataMessage(pc, e);
-
- };
- };
- pc.onclosedconnection = function() {
-
- };
- };
- SourcePeer.prototype.on = function(code, cb) {
-
- };
- SourcePeer.prototype.gotDescription = function(desc) {
- this._pc
- };
|