I look like you are using an old drprecated version of the XSockets.WebRTC API, i'll try post a quick fix here for you. I recommend you to have a look at this repo at Git ; https://github.com/XSockets/WebRTC
In the code you provided you should move the init of the XSockets.WebRTC() things into the open call back of the broker ; i also notoce that you are using /Generic, that wont work , the controller to use is "Broker" as follows.
var ws, rtc;
var myCtx = "1265343559964af892b7ba86205e5927";
$(function() {
ws = new XSockets.WebSocket("ws://127.0.0.1:4502/Broker");
ws.onopen = function(c) {
rtc = new XSockets.WebRTC(ws);
rtc.onpeerconnectioncreated = function(peer) {
console.log("created a peer", peer);
};
rtc.onpeerconnectionlost = function(peer) {
console.log("lost a peer", peer);
};
rtc.oncontextcreated = function(ctx) {
console.log("ctx", ctx);
};
rtc.onlocalstream = function(stream) {
attachMediaStream(document.querySelector("#myvideo"), stream);
};
rtc.getUserMedia(rtc.userMediaConstraints.qvga(false), function() {
console.log("Yeah, Video");
// Lets use a static context i.e
rtc.changeContext(myCtx);
});
rtc.onremotestream = function(event) {
var v = $("<video>").attr("autoplay", "autoplay").appendTo("div");
attachMediaStream($(v).get(0), event.stream);
};
};
});
</script>
Futher on my .html page contains the following html
<body>
<div></div>
<video id="myvideo" autoplay></video>
</body>
Also make sure you include
<script src="Scripts/jquery-2.1.0.min.js"></script>
<script src="Scripts/XSockets.latest.js"></script>
<script src="Scripts/XSockets.WebRTC.latest.js"></script>
Good luck!