muaz-khan / WebRTC-Experiment

WebRTC, WebRTC and WebRTC. Everything here is all about WebRTC!!
https://www.webrtc-experiment.com/
MIT License
11.77k stars 3.95k forks source link

Radio #218

Open ghost opened 10 years ago

ghost commented 10 years ago

Hi, I'm trying to make a radio that sends the audio for audio player in html5 and I'm seeing the "WebRTC-broadcasting" and wanted to know if you have any way to send the audio being recorded live for audio player in html5?

And this example dont work: https://github.com/muaz-khan/WebRTC-Experiment/tree/master/webrtc-broadcasting

SerRashin commented 10 years ago

test it work

broadcaster code

<script src="http://www.rtcmulticonnection.org/latest.js"></script>
<button id="audio">Audio stream</button>
<script>

var connection = new RTCMultiConnection('channel-654654-34434-12121');
connection.session = {
    data: true
};
connection.open();

document.querySelector('#audio').onclick = function() {
    connection.addStream({audio:true,oneway:true});
};
</script>

viewers code


<script src="http://www.rtcmulticonnection.org/latest.js"></script>
<script>

var connection = new RTCMultiConnection('channel-654654-34434-12121');
connection.session = {
    audio: true
};
connection.connect();

</script>

test here http://htmledit.squarefree.com/ open two browser windows and paste the above code

ghost commented 10 years ago

WoW!!! Thanks!!! RTCMultiConnection is cool!!

muaz-khan commented 10 years ago

@AlanPS I really didn't understand your question. Icecast2/shoutcast can easily be used along with nodejs to stream binary data (ogg/mp3 encoded) to the browser and you can play them directly in the <audio> element. Otherwise you can read mp4 (h264 encoded) or webm (vp8 encoded) over nodejs and stream binary and play blocks as soon as received without waiting for entire file to be streamed.

RecordRTC is useful only to record locally and push to server using HTTP-POST or other means.

ghost commented 10 years ago

Hi, @muaz-khan what I needed was what @serhanters posted...Thanks!!!

ghost commented 10 years ago

This system works on differents ips / machines? Can transmit like a radio right?

Works only in chrome?

ghost commented 10 years ago

@serhanters this code dont work, the client does not receive the áudio!

SerRashin commented 10 years ago

@AlanPS you wont transmit pre-recorded audio or live audio?

broadcaster

<script src="http://www.rtcmulticonnection.org/latest.js"></script>
<script>

var connection = new RTCMultiConnection('radio');
connection.session = {
    audio: true,
    oneway:true
};
connection.open();

</script>

viewers

<script src="http://www.rtcmulticonnection.org/latest.js"></script>
<script>

connection = new RTCMultiConnection('radio');

connection.join(connection.channel);

</script>
ghost commented 10 years ago

Hi @serhanters , i will transmit live áudio, this second script dont works again!

ghost commented 10 years ago

@muaz-khan This system works on differents ips / machines? Can transmit like a radio right?

Works only in chrome?

muaz-khan commented 10 years ago

RTCMultiConnection can transmit audio on multiple browsers and devices in both one-way and two-way directions however firewall bypassing depends entirely upon ice-servers you're using. XirSys claims to bypassing many restricted symmetric networks and you should try their TURN servers as well.

Remember, it rarely fails on chrome if any single user is sitting behind a public network.

You should try following snippet:

<script src="//www.rtcmulticonnection.org/latest.js"></script>
<button id="openNewSessionButton">Open New Room</button>
<script>
var connection = new RTCMultiConnection();

// easiest way to customize what you need!
connection.session = {
    audio: true,
    oneway: true
};

// on getting local or remote media stream
connection.onstream = function(e) {
    document.body.appendChild(e.mediaElement);
};

// setup signaling channel
connection.connect();

// open new session
document.querySelector('#openNewSessionButton').onclick = function() {
    connection.open();
};
</script>
ghost commented 10 years ago

Yes, now!!! Thanks @muaz-khan!! Thanks @serhanters!!