Skip to content

Commit

Permalink
add custom server with path support and build binary for example
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan-Feofanov committed Nov 14, 2020
1 parent b105044 commit 655895f
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 24 deletions.
15 changes: 4 additions & 11 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,8 @@ Quick start
```js
<script>
var streamer = new WSAudioAPI.Streamer({
server: {
host: window.location.hostname, //websockets server addres. In this example - localhost
port: 5000 //websockets server port
});
server: 'wss://localhost:5000' // dont't forget about scheme
});
</script>
<button onclick="streamer.start()">Start stream</button>
Expand All @@ -78,9 +76,7 @@ Quick start
```js
<script>
var player = new WSAudioAPI.Player({
server: {
host: window.location.hostname, //websockets server addres. In this example - localhost
port: 5000 //websockets server port
server: 'wss://localhost:5000' // dont't forget about scheme
});
</script>
<button onclick="player.start()">Play stream</button>
Expand All @@ -102,10 +98,7 @@ var defaultConfig = {
frameDuration: 20,
bufferSize: 4096
},
server: {
host: window.location.hostname,
port: 5000
}
server: 'ws://' + window.location.hostname + ':5000'
}
```

Expand Down
3 changes: 2 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
uglifyjs src/libopus.js src/opus.js src/xaudio.js src/ws-audio-api.js -o dist/ws-audio-api.min.js
uglifyjs src/libopus.js src/opus.js src/xaudio.js src/ws-audio-api.js -o dist/ws-audio-api.min.js
cp dist/ws-audio-api.min.js example
2 changes: 1 addition & 1 deletion dist/ws-audio-api.min.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<input id="volume" type="range" min ="0.0" max="1.0" step ="0.01" oninput="setVol(this.value)" onchange="setVol(this.value)" style="-webkit-appearance: slider-vertical">
<input type="text" id="volumeIndicator">
</body>
<script src="scripts/ws-audio-api.min.js"></script>
<script src="ws-audio-api.min.js"></script>
<script>
var player = new WSAudioAPI.Player();
var player = new WSAudioAPI.Player(); // Note that here i use default server location. Don't forget set correct address
var streamer = new WSAudioAPI.Streamer();
var mute = document.querySelector('.mute');
var volume = document.querySelector('#volume');
Expand All @@ -40,4 +40,4 @@
}
}
</script>
</html>
</html>
1 change: 0 additions & 1 deletion example/scripts

This file was deleted.

28 changes: 28 additions & 0 deletions example/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions example/ws-audio-api.min.js

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ws-audio-api",
"version": "0.1.5",
"version": "0.2",
"description": "WebSocket Audio API: library to broadcast the sound from the microphone through a WebSocket",
"main": "dist/ws-audio-api.min.js",
"scripts": {
Expand Down
9 changes: 3 additions & 6 deletions src/ws-audio-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
frameDuration: 20,
bufferSize: 4096
},
server: {
host: window.location.hostname,
port: 5000
}
server: 'wss://' + window.location.hostname + ':5000'
};

var audioContext = new(window.AudioContext || window.webkitAudioContext)();
Expand Down Expand Up @@ -72,7 +69,7 @@
var _this = this;

if (!this.parentSocket) {
this.socket = new WebSocket('wss://' + this.config.server.host + ':' + this.config.server.port);
this.socket = new WebSocket(this.config.server);
} else {
this.socket = this.parentSocket;
}
Expand Down Expand Up @@ -190,7 +187,7 @@
this.gainNode.connect(audioContext.destination);

if (!this.parentSocket) {
this.socket = new WebSocket('wss://' + this.config.server.host + ':' + this.config.server.port);
this.socket = new WebSocket(this.config.server);
} else {
this.socket = this.parentSocket;
}
Expand Down

0 comments on commit 655895f

Please sign in to comment.