|
@@ -1152,7 +1152,7 @@ var util = {
|
|
var pc = new RTCPeerConnection(defaultConfig, {});
|
|
var pc = new RTCPeerConnection(defaultConfig, {});
|
|
var dc;
|
|
var dc;
|
|
try {
|
|
try {
|
|
- dc = pc.createDataChannel('_PEERJSRELIABLETEST');
|
|
|
|
|
|
+ dc = pc.createDataChannel('_PEERJSRELIABLETEST', {reliable: true});
|
|
} catch (e) {
|
|
} catch (e) {
|
|
pc.close();
|
|
pc.close();
|
|
if (e.name === 'NotSupportedError') {
|
|
if (e.name === 'NotSupportedError') {
|
|
@@ -1510,12 +1510,9 @@ Peer.prototype._handleMessage = function(message) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
// Find messages.
|
|
// Find messages.
|
|
- var messages = this._lostMessages[connection.id];
|
|
|
|
- if (messages) {
|
|
|
|
- for (var i = 0, ii = messages.length; i < ii; i += 1) {
|
|
|
|
- connection.handleMessage(messages[i]);
|
|
|
|
- }
|
|
|
|
- delete this._lostMessages[connection.id];
|
|
|
|
|
|
+ var messages = this._getMessages(connectionId);
|
|
|
|
+ for (var i = 0, ii = messages.length; i < ii; i += 1) {
|
|
|
|
+ connection.handleMessage(messages[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
@@ -1528,7 +1525,7 @@ Peer.prototype._handleMessage = function(message) {
|
|
var id = payload.connectionId;
|
|
var id = payload.connectionId;
|
|
var connection = this.getConnection(peer, id);
|
|
var connection = this.getConnection(peer, id);
|
|
|
|
|
|
- if (connection) {
|
|
|
|
|
|
+ if (connection && connection.pc) {
|
|
// Pass it on.
|
|
// Pass it on.
|
|
connection.handleMessage(message);
|
|
connection.handleMessage(message);
|
|
} else if (id) {
|
|
} else if (id) {
|
|
@@ -1541,7 +1538,7 @@ Peer.prototype._handleMessage = function(message) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-/** Stores messages without a connection, to be claimed later. */
|
|
|
|
|
|
+/** Stores messages without a set up connection, to be claimed later. */
|
|
Peer.prototype._storeMessage = function(connectionId, message) {
|
|
Peer.prototype._storeMessage = function(connectionId, message) {
|
|
if (!this._lostMessages[connectionId]) {
|
|
if (!this._lostMessages[connectionId]) {
|
|
this._lostMessages[connectionId] = [];
|
|
this._lostMessages[connectionId] = [];
|
|
@@ -1549,6 +1546,17 @@ Peer.prototype._storeMessage = function(connectionId, message) {
|
|
this._lostMessages[connectionId].push(message);
|
|
this._lostMessages[connectionId].push(message);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/** Retrieve messages from lost message store */
|
|
|
|
+Peer.prototype._getMessages = function(connectionId) {
|
|
|
|
+ var messages = this._lostMessages[connectionId];
|
|
|
|
+ if (messages) {
|
|
|
|
+ delete this._lostMessages[connectionId];
|
|
|
|
+ return messages;
|
|
|
|
+ } else {
|
|
|
|
+ return [];
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Returns a DataConnection to the specified peer. See documentation for a
|
|
* Returns a DataConnection to the specified peer. See documentation for a
|
|
* complete list of options.
|
|
* complete list of options.
|
|
@@ -1808,11 +1816,9 @@ DataConnection.prototype.send = function(data) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
var self = this;
|
|
var self = this;
|
|
- if (this.serialization === 'none') {
|
|
|
|
- this._dc.send(data);
|
|
|
|
- } else if (this.serialization === 'json') {
|
|
|
|
|
|
+ if (this.serialization === 'json') {
|
|
this._dc.send(JSON.stringify(data));
|
|
this._dc.send(JSON.stringify(data));
|
|
- } else {
|
|
|
|
|
|
+ } else if ('binary-utf8'.indexOf(this.serialization) !== -1) {
|
|
var utf8 = (this.serialization === 'binary-utf8');
|
|
var utf8 = (this.serialization === 'binary-utf8');
|
|
var blob = util.pack(data, utf8);
|
|
var blob = util.pack(data, utf8);
|
|
// DataChannel currently only supports strings.
|
|
// DataChannel currently only supports strings.
|
|
@@ -1823,6 +1829,8 @@ DataConnection.prototype.send = function(data) {
|
|
} else {
|
|
} else {
|
|
this._dc.send(blob);
|
|
this._dc.send(blob);
|
|
}
|
|
}
|
|
|
|
+ } else {
|
|
|
|
+ this._dc.send(data);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1855,7 +1863,6 @@ function MediaConnection(peer, provider, options) {
|
|
this.type = 'media';
|
|
this.type = 'media';
|
|
this.peer = peer;
|
|
this.peer = peer;
|
|
this.provider = provider;
|
|
this.provider = provider;
|
|
-
|
|
|
|
this.metadata = this.options.metadata;
|
|
this.metadata = this.options.metadata;
|
|
this.localStream = this.options._stream;
|
|
this.localStream = this.options._stream;
|
|
|
|
|
|
@@ -1877,7 +1884,7 @@ MediaConnection.prototype.addStream = function(remoteStream) {
|
|
|
|
|
|
this.remoteStream = remoteStream;
|
|
this.remoteStream = remoteStream;
|
|
this.emit('stream', remoteStream); // Should we call this `open`?
|
|
this.emit('stream', remoteStream); // Should we call this `open`?
|
|
- this.open = true;
|
|
|
|
|
|
+
|
|
};
|
|
};
|
|
|
|
|
|
MediaConnection.prototype.handleMessage = function(message) {
|
|
MediaConnection.prototype.handleMessage = function(message) {
|
|
@@ -1887,6 +1894,7 @@ MediaConnection.prototype.handleMessage = function(message) {
|
|
case 'ANSWER':
|
|
case 'ANSWER':
|
|
// Forward to negotiator
|
|
// Forward to negotiator
|
|
Negotiator.handleSDP(message.type, this, payload.sdp);
|
|
Negotiator.handleSDP(message.type, this, payload.sdp);
|
|
|
|
+ this.open = true;
|
|
break;
|
|
break;
|
|
case 'CANDIDATE':
|
|
case 'CANDIDATE':
|
|
Negotiator.handleCandidate(this, payload.candidate);
|
|
Negotiator.handleCandidate(this, payload.candidate);
|
|
@@ -1899,7 +1907,7 @@ MediaConnection.prototype.handleMessage = function(message) {
|
|
|
|
|
|
MediaConnection.prototype.answer = function(stream) {
|
|
MediaConnection.prototype.answer = function(stream) {
|
|
if (this.localStream) {
|
|
if (this.localStream) {
|
|
- // Throw some error.
|
|
|
|
|
|
+ util.warn('Local stream already exists on this MediaConnection. Are you answering a call twice?');
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1910,6 +1918,12 @@ MediaConnection.prototype.answer = function(stream) {
|
|
this,
|
|
this,
|
|
this.options._payload
|
|
this.options._payload
|
|
)
|
|
)
|
|
|
|
+ // Retrieve lost messages stored because PeerConnection not set up.
|
|
|
|
+ var messages = this.provider._getMessages(this.id);
|
|
|
|
+ for (var i = 0, ii = messages.length; i < ii; i += 1) {
|
|
|
|
+ this.handleMessage(messages[i]);
|
|
|
|
+ }
|
|
|
|
+ this.open = true;
|
|
};
|
|
};
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -2115,7 +2129,6 @@ Negotiator.cleanup = function(connection) {
|
|
|
|
|
|
Negotiator._makeOffer = function(connection) {
|
|
Negotiator._makeOffer = function(connection) {
|
|
var pc = connection.pc;
|
|
var pc = connection.pc;
|
|
- console.log('using constraints', connection.options.constraints);
|
|
|
|
pc.createOffer(function(offer) {
|
|
pc.createOffer(function(offer) {
|
|
util.log('Created offer.');
|
|
util.log('Created offer.');
|
|
|
|
|