Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use promise version of API #98

Merged
merged 1 commit into from
Jul 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 33 additions & 15 deletions rtcpeerconnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,14 @@ PeerConnection.prototype._role = function () {
// Add a stream to the peer connection object
PeerConnection.prototype.addStream = function (stream) {
this.localStream = stream;
this.pc.addStream(stream);
stream.getTracks().forEach(
function(track) {
this.pc.addTrack(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC this was problematic in chrome. It only allows calling addTrack once? It's been a while since I used this. @jensengar do you remember?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've been using this in production for over a year

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping? Since I heard (from a random person on the street) you're still using this in production

track,
stream
);
}
);
};

// helper function to check if a remote candidate is a stun/relay
Expand Down Expand Up @@ -306,9 +313,11 @@ PeerConnection.prototype.processIce = function (update, cb) {
candidate: iceCandidate,
sdpMLineIndex: mline,
sdpMid: mid
}), function () {
// well, this success callback is pretty meaningless
},
})
).then(
function () {
// well, this success callback is pretty meaningless
},
function (err) {
self.emit('error', err);
}
Expand All @@ -332,7 +341,9 @@ PeerConnection.prototype.processIce = function (update, cb) {
role: self._role(),
direction: 'incoming'
});
self.pc.setRemoteDescription(new RTCSessionDescription(offer),
self.pc.setRemoteDescription(
new RTCSessionDescription(offer)
).then(
function () {
processCandidates();
},
Expand Down Expand Up @@ -362,7 +373,8 @@ PeerConnection.prototype.processIce = function (update, cb) {
}

self.pc.addIceCandidate(
new RTCIceCandidate(update.candidate),
new RTCIceCandidate(update.candidate)
).then(
function () { },
function (err) {
self.emit('error', err);
Expand All @@ -388,6 +400,8 @@ PeerConnection.prototype.offer = function (constraints, cb) {

// Actually generate the offer
this.pc.createOffer(
mediaConstraints
).then(
function (offer) {
// does not work for jingle, but jingle.js doesn't need
// this hack...
Expand All @@ -400,7 +414,7 @@ PeerConnection.prototype.offer = function (constraints, cb) {
cb(null, expandedOffer);
}
self._candidateBuffer = [];
self.pc.setLocalDescription(offer,
self.pc.setLocalDescription(offer).then(
function () {
var jingle;
if (self.config.useJingle) {
Expand Down Expand Up @@ -444,8 +458,7 @@ PeerConnection.prototype.offer = function (constraints, cb) {
function (err) {
self.emit('error', err);
cb(err);
},
mediaConstraints
}
);
};

Expand Down Expand Up @@ -525,7 +538,9 @@ PeerConnection.prototype.handleOffer = function (offer, cb) {
self._checkRemoteCandidate(line);
}
});
self.pc.setRemoteDescription(new RTCSessionDescription(offer),
self.pc.setRemoteDescription(
new RTCSessionDescription(offer)
).then(
function () {
cb();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can just pass cb here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this highly confusing:

.then(cb, cb)

it works because the success has arguments and the error uses the first one but...

},
Expand Down Expand Up @@ -598,14 +613,16 @@ PeerConnection.prototype.handleAnswer = function (answer, cb) {
}
});
self.pc.setRemoteDescription(
new RTCSessionDescription(answer),
new RTCSessionDescription(answer)
).then(
function () {
if (self.wtFirefox) {
window.setTimeout(function () {
self.firefoxcandidatebuffer.forEach(function (candidate) {
// add candidates later
self.pc.addIceCandidate(
new RTCIceCandidate(candidate),
new RTCIceCandidate(candidate)
).then(
function () { },
function (err) {
self.emit('error', err);
Expand Down Expand Up @@ -644,6 +661,8 @@ PeerConnection.prototype._answer = function (constraints, cb) {
if (this.pc.signalingState === 'closed') return cb('Already closed');

self.pc.createAnswer(
constraints
).then(
function (answer) {
var sim = [];
if (self.enableChromeNativeSimulcast) {
Expand Down Expand Up @@ -700,7 +719,7 @@ PeerConnection.prototype._answer = function (constraints, cb) {
cb(null, copy);
}
self._candidateBuffer = [];
self.pc.setLocalDescription(answer,
self.pc.setLocalDescription(answer).then(
function () {
if (self.config.useJingle) {
var jingle = SJJ.toSessionJSON(answer.sdp, {
Expand Down Expand Up @@ -757,8 +776,7 @@ PeerConnection.prototype._answer = function (constraints, cb) {
function (err) {
self.emit('error', err);
cb(err);
},
constraints
}
);
};

Expand Down