peerConnection.addIceCandidate podający błąd: niepoprawny łańcuch
Próbuję zaimplementować aplikację WebRTC obsługującą tylko Voice. Używam go w ChromeVersion 29.0.1547.0 dev
. Moja aplikacja używa Socket.IO do mechanizmu sygnalizacji.
peerConnection.addIceCandidate()
podaje mi ten błąd:Uncaught SyntaxError: An invalid or illegal string was specified.
i osobnopeerConnection.setRemoteDescription();
podaje mi ten błąd:Uncaught TypeMismatchError: The type of an object was incompatible with the expected type of the parameter associated to the object.
Oto mój kod:
SERWER (w CoffeeScript)
app = require("express")()
server = require("http").createServer(app).listen(3000)
io = require("socket.io").listen(server)
app.get "/", (req, res) -> res.sendfile("index.html")
app.get "/client.js", (req, res) -> res.sendfile("client.js")
io.sockets.on "connection", (socket) ->
socket.on "message", (data) ->
socket.broadcast.emit "message", data
KLIENT (w JavaScript)
var socket = io.connect("http://localhost:3000");
var pc = new webkitRTCPeerConnection({
"iceServers": [{"url": "stun:stun.l.google.com:19302"}]
});
navigator.getUserMedia = navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia;
navigator.getUserMedia({audio: true}, function (stream) {
pc.addStream(stream);
}, function (error) { console.log(error); });
pc.onicecandidate = function (event) {
if (!event || !event.candidate) return;
socket.emit("message", {
type: "iceCandidate",
"candidate": event.candidate
});
};
pc.onaddstream = function(event) {
var audioElem = document.createElement("audio");
audioElem.src = webkitURL.createObjectURL(event.stream);
audioElem.autoplay = true;
document.appendChild(audioElem);
console.log("Got Remote Stream");
};
socket.on("message", function(data) {
if (data.type === "iceCandidate") {
console.log(data.candidate);
candidate = new RTCIceCandidate(data.candidate);
console.log(candidate);
pc.addIceCandidate(candidate);
} else if (data.type === "offer") {
pc.setRemoteDescription(data.description);
pc.createAnswer(function(description) {
pc.setLocalDescription(description);
socket.emit("message", {type: "answer", description: description});
});
} else if (data.type === "answer") {
pc.setRemoteDescription(data.description);
}
});
function offer() {
pc.createOffer( function (description) {
pc.setLocalDescription(description);
socket.emit("message", {type: "offer", "description": description});
});
};
HTML zawiera przycisk, który wywołujeoffer()
.
Mogę potwierdzićICECandidates
iSessionDescriptions
pomyślnie przenoszą się z jednego klienta na drugiego.
Co ja robię źle? A jak mam naprawić te i inne błędy, aby móc przesyłać dźwięk z jednego klienta do drugiego?
PS: Jeśli wiesz o dobrym źródle dokumentującym API WebRTC (z wyjątkiem dokumentacji W3C), powiedz mi o tym!
Dzięki!