Attempted to understand volume code and retry fixes

This commit is contained in:
abalabahaha
2016-03-12 21:53:34 -08:00
parent 5e64d96272
commit 13055f67d2
4 changed files with 20 additions and 34 deletions

View File

@@ -124,19 +124,16 @@ var VoiceConnection = (function (_EventEmitter) {
count = 0, count = 0,
length = 20, length = 20,
retStream = new _StreamIntent2["default"](), retStream = new _StreamIntent2["default"](),
onWarning = false, onWarning = false;
lastVolume = this.volume !== undefined ? this.volume.get() : 1;
this.volume = stream;
this.playing = true; this.playing = true;
this.playingIntent = retStream; this.playingIntent = retStream;
this.setVolume(lastVolume);
function send() { function send() {
if (!self.playingIntent || !self.playing) { if (!self.playingIntent || !self.playing) {
self.setSpeaking(false); self.setSpeaking(false);
retStream.emit("end"); retStream.emit("end");
//console.log("ending 1");
return; return;
} }
try { try {
@@ -147,7 +144,6 @@ var VoiceConnection = (function (_EventEmitter) {
if (onWarning) { if (onWarning) {
retStream.emit("end"); retStream.emit("end");
self.setSpeaking(false); self.setSpeaking(false);
//console.log("ending 2");
return; return;
} else { } else {
onWarning = true; onWarning = true;
@@ -253,9 +249,7 @@ var VoiceConnection = (function (_EventEmitter) {
callback = options; callback = options;
options = {}; options = {};
} }
if (options.volume != null) { options.volume = options.volume !== undefined ? options.volume : this.getVolume();
this.setVolume(options.volume);
}
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
_this.encoder.encodeFile(stream, options)["catch"](error).then(function (data) { _this.encoder.encodeFile(stream, options)["catch"](error).then(function (data) {
self.streamProc = data.proc; self.streamProc = data.proc;
@@ -285,9 +279,7 @@ var VoiceConnection = (function (_EventEmitter) {
callback = options; callback = options;
options = {}; options = {};
} }
if (options.volume != null) { options.volume = options.volume !== undefined ? options.volume : this.getVolume();
this.setVolume(options.volume);
}
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
_this2.encoder.encodeStream(stream, options)["catch"](error).then(function (data) { _this2.encoder.encodeStream(stream, options)["catch"](error).then(function (data) {
self.streamProc = data.proc; self.streamProc = data.proc;
@@ -317,9 +309,7 @@ var VoiceConnection = (function (_EventEmitter) {
callback = options; callback = options;
options = {}; options = {};
} }
if (options.volume != null) { options.volume = options.volume !== undefined ? options.volume : this.getVolume();
this.setVolume(options.volume);
}
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject) {
_this3.encoder.encodeArbitraryFFmpeg(ffmpegOptions)["catch"](error).then(function (data) { _this3.encoder.encodeArbitraryFFmpeg(ffmpegOptions)["catch"](error).then(function (data) {
self.streamProc = data.proc; self.streamProc = data.proc;

View File

@@ -11,10 +11,11 @@ var Transform = require('stream').Transform;
var Volume = (function (_Transform) { var Volume = (function (_Transform) {
_inherits(Volume, _Transform); _inherits(Volume, _Transform);
function Volume() { function Volume(volume) {
_classCallCheck(this, Volume); _classCallCheck(this, Volume);
_Transform.apply(this, arguments); _Transform.call(this);
this.set(volume);
} }
Volume.prototype.get = function get() { Volume.prototype.get = function get() {
@@ -22,7 +23,7 @@ var Volume = (function (_Transform) {
}; };
Volume.prototype.set = function set(volume) { Volume.prototype.set = function set(volume) {
this.volume = volume; this.volume = volume === undefined ? 1 : volume;
}; };
Volume.prototype._transform = function _transform(buffer, encoding, callback) { Volume.prototype._transform = function _transform(buffer, encoding, callback) {

View File

@@ -89,19 +89,16 @@ export default class VoiceConnection extends EventEmitter {
count = 0, count = 0,
length = 20, length = 20,
retStream = new StreamIntent(), retStream = new StreamIntent(),
onWarning = false, onWarning = false;
lastVolume = this.volume !== undefined ? this.volume.get() : 1;
this.volume = stream;
this.playing = true; this.playing = true;
this.playingIntent = retStream; this.playingIntent = retStream;
this.setVolume(lastVolume);
function send() { function send() {
if (!self.playingIntent || !self.playing) { if (!self.playingIntent || !self.playing) {
self.setSpeaking(false); self.setSpeaking(false);
retStream.emit("end"); retStream.emit("end");
//console.log("ending 1");
return; return;
} }
try { try {
@@ -112,7 +109,6 @@ export default class VoiceConnection extends EventEmitter {
if (onWarning) { if (onWarning) {
retStream.emit("end"); retStream.emit("end");
self.setSpeaking(false); self.setSpeaking(false);
//console.log("ending 2");
return; return;
} else { } else {
onWarning = true; onWarning = true;
@@ -216,9 +212,7 @@ export default class VoiceConnection extends EventEmitter {
callback = options; callback = options;
options = {}; options = {};
} }
if (options.volume != null) { options.volume = options.volume !== undefined ? options.volume : this.getVolume();
this.setVolume(options.volume);
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.encoder this.encoder
.encodeFile(stream, options) .encodeFile(stream, options)
@@ -245,9 +239,7 @@ export default class VoiceConnection extends EventEmitter {
callback = options; callback = options;
options = {}; options = {};
} }
if (options.volume != null) { options.volume = options.volume !== undefined ? options.volume : this.getVolume();
this.setVolume(options.volume);
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.encoder this.encoder
.encodeStream(stream, options) .encodeStream(stream, options)
@@ -275,9 +267,7 @@ export default class VoiceConnection extends EventEmitter {
callback = options; callback = options;
options = {}; options = {};
} }
if (options.volume != null) { options.volume = options.volume !== undefined ? options.volume : this.getVolume();
this.setVolume(options.volume);
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
this.encoder this.encoder
.encodeArbitraryFFmpeg(ffmpegOptions) .encodeArbitraryFFmpeg(ffmpegOptions)

View File

@@ -1,6 +1,11 @@
const Transform = require('stream').Transform; const Transform = require('stream').Transform;
class Volume extends Transform { class Volume extends Transform {
constructor(volume) {
super();
this.set(volume);
}
get volume() { get volume() {
return this._volume === undefined ? 1 : this._volume; return this._volume === undefined ? 1 : this._volume;
} }
@@ -18,7 +23,7 @@ class Volume extends Transform {
} }
set(volume) { set(volume) {
this.volume = volume; this.volume = volume === undefined ? 1 : volume;
} }
_transform(buffer, encoding, callback) { _transform(buffer, encoding, callback) {