diff --git a/public/js/sample.js b/public/js/sample.js index afd2e5b..aa4d30d 100644 --- a/public/js/sample.js +++ b/public/js/sample.js @@ -1,31 +1,26 @@ -var ctx = new webkitAudioContext() - , src - console.log = function(message) { document.getElementById('console').innerHTML += message + "\n"; } -rtc.on('add remote stream', function(stream, socketId) { - console.log("ADDING REMOTE STREAM..."); - connect(stream); -}); - -rtc.on('connect', function() { - console.log("** RTC connected"); -}); +var ws = new WebSocket("ws:"+window.location.href.split(":")[1]+":8000"); -rtc.createStream({audio: true}, function(){}, streamErr); - -function connect( stream ){ - var audio = new Audio(); - audio.src = webkitURL.createObjectURL(stream); - audio.play(); -} +ws.onmessage = function(d) { + d = JSON.parse(d.data); + if (d.type === "assigned_id") { + this._id = d.id; + console.log("id received"); + } else { + console.log(d); + } +}; -function streamErr(){ - alert('O noes! couldn\'t get ur inputz'); +function closeSocket() { + ws.send(JSON.stringify({ + type: "close", + data: { + id: ws._id + } + })); } -window.onload = function() { - rtc.connect('ws://24.­250.­22.­134:­80001', ''); -} \ No newline at end of file +window.onbeforeunload = closeSocket;