forked from muaz-khan/RTCMultiConnection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream-mp3-live.html
executable file
·69 lines (56 loc) · 1.9 KB
/
stream-mp3-live.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<script src="//cdn.webrtc-experiment.com/RTCMultiConnection.js"></script>
<script src="//cdn.webrtc-experiment.com/firebase.js"></script>
<input type="file">
<button id="openNewSessionButton" disabled>Open New Room</button>
<br />
<script>
var connection = new RTCMultiConnection();
connection.session = {
audio: true,
oneway: true
};
connection.onstream = function(e) {
document.body.appendChild(e.mediaElement);
};
// connect to signaling gateway
connection.connect();
// open new session
document.getElementById('openNewSessionButton').onclick = function() {
this.disabled = true;
connection.open();
};
window.AudioContext = window.AudioContext || window.webkitAudioContext;
var context = new AudioContext();
var gainNode = context.createGain();
gainNode.connect(context.destination);
// don't play for self
gainNode.gain.value = 0;
document.querySelector('input[type=file]').onchange = function() {
this.disabled = true;
var reader = new FileReader();
reader.onload = (function(e) {
// Import callback function that provides PCM audio data decoded as an audio buffer
context.decodeAudioData(e.target.result, function(buffer) {
// Create the sound source
var soundSource = context.createBufferSource();
soundSource.buffer = buffer;
soundSource.start(0, 0 / 1000);
soundSource.connect(gainNode);
var destination = context.createMediaStreamDestination();
soundSource.connect(destination);
connection.attachStreams.push(destination.stream);
connection.dontCaptureUserMedia = true;
document.getElementById('openNewSessionButton').disabled = false;
});
});
reader.readAsArrayBuffer(this.files[0]);
};
</script>
<style>
input,
button[disabled] {
background: none;
border: 1px solid rgb(226, 223, 223);
color: rgb(219, 217, 217);
}
</style>