mirror of
https://github.com/danog/php-libtgvoip.git
synced 2024-11-26 20:04:48 +01:00
let's not create a callback hell
This commit is contained in:
parent
70ecd6db72
commit
63a0b4aaa5
27
.vscode/settings.json
vendored
27
.vscode/settings.json
vendored
@ -4,6 +4,31 @@
|
|||||||
"initializer_list": "cpp",
|
"initializer_list": "cpp",
|
||||||
"utility": "cpp",
|
"utility": "cpp",
|
||||||
"system_error": "cpp",
|
"system_error": "cpp",
|
||||||
"type_traits": "cpp"
|
"type_traits": "cpp",
|
||||||
|
"*.tcc": "cpp",
|
||||||
|
"cctype": "cpp",
|
||||||
|
"clocale": "cpp",
|
||||||
|
"cstdint": "cpp",
|
||||||
|
"cstdio": "cpp",
|
||||||
|
"cstdlib": "cpp",
|
||||||
|
"cwchar": "cpp",
|
||||||
|
"exception": "cpp",
|
||||||
|
"iosfwd": "cpp",
|
||||||
|
"new": "cpp",
|
||||||
|
"stdexcept": "cpp",
|
||||||
|
"tuple": "cpp",
|
||||||
|
"typeinfo": "cpp",
|
||||||
|
"cmath": "cpp",
|
||||||
|
"cstdarg": "cpp",
|
||||||
|
"cstddef": "cpp",
|
||||||
|
"cstring": "cpp",
|
||||||
|
"cwctype": "cpp",
|
||||||
|
"functional": "cpp",
|
||||||
|
"istream": "cpp",
|
||||||
|
"limits": "cpp",
|
||||||
|
"memory": "cpp",
|
||||||
|
"ostream": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"streambuf": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,6 @@ AudioInputPHP::AudioInputPHP(Php::Value callbacks){
|
|||||||
startMethod = callbacks["start"];
|
startMethod = callbacks["start"];
|
||||||
stopMethod = callbacks["stop"];
|
stopMethod = callbacks["stop"];
|
||||||
configureMethod = callbacks["configure"];
|
configureMethod = callbacks["configure"];
|
||||||
call = callbacks["call"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -25,18 +24,20 @@ AudioInputPHP::~AudioInputPHP(){
|
|||||||
|
|
||||||
}
|
}
|
||||||
void AudioInputPHP::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels) {
|
void AudioInputPHP::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels) {
|
||||||
configureMethod(static_cast<VoIP*> call, (int32_t)sampleRate, (int32_t)bitsPerSample, (int32_t)channels);
|
configureMethod((int32_t)sampleRate, (int32_t)bitsPerSample, (int32_t)channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInputPHP::Start(){
|
void AudioInputPHP::Start(){
|
||||||
if(running)
|
if(running)
|
||||||
return;
|
return;
|
||||||
startMethod(static_cast<VoIP*> call);
|
startMethod();
|
||||||
|
running = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioInputPHP::Stop(){
|
void AudioInputPHP::Stop(){
|
||||||
stopMethod(static_cast<VoIP*> call);
|
stopMethod();
|
||||||
|
running = false;
|
||||||
}
|
}
|
||||||
void AudioInputPHP::writeFrames(Php::Parameters ¶ms){
|
void AudioInputPHP::writeFrames(Php::Parameters ¶ms){
|
||||||
if(!running)
|
if(!running)
|
||||||
|
@ -26,7 +26,6 @@ private:
|
|||||||
Php::Value configureMethod;
|
Php::Value configureMethod;
|
||||||
Php::Value startMethod;
|
Php::Value startMethod;
|
||||||
Php::Value stopMethod;
|
Php::Value stopMethod;
|
||||||
void* call;
|
|
||||||
bool running;
|
bool running;
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
|
@ -17,24 +17,23 @@ AudioOutputPHP::AudioOutputPHP(Php::Value callbacks){
|
|||||||
stopMethod = callbacks["stop"];
|
stopMethod = callbacks["stop"];
|
||||||
configureMethod = callbacks["configure"];
|
configureMethod = callbacks["configure"];
|
||||||
getLevelMethod = callbacks["get_level"];
|
getLevelMethod = callbacks["get_level"];
|
||||||
call = callbacks["call"];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioOutputPHP::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels){
|
void AudioOutputPHP::Configure(uint32_t sampleRate, uint32_t bitsPerSample, uint32_t channels){
|
||||||
configureMethod(static_cast<VoIP*> call, (int32_t)sampleRate, (int32_t)bitsPerSample, (int32_t)channels);
|
configureMethod((int32_t)sampleRate, (int32_t)bitsPerSample, (int32_t)channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioOutputPHP::Start(){
|
void AudioOutputPHP::Start(){
|
||||||
if(running)
|
if(running)
|
||||||
return;
|
return;
|
||||||
|
startMethod();
|
||||||
running = true;
|
running = true;
|
||||||
startMethod(static_cast<VoIP*> call);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioOutputPHP::Stop(){
|
void AudioOutputPHP::Stop(){
|
||||||
if(!running)
|
if(!running)
|
||||||
return;
|
return;
|
||||||
stopMethod(static_cast<VoIP*> call);
|
stopMethod();
|
||||||
running = false;
|
running = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +42,7 @@ bool AudioOutputPHP::IsPlaying(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
float AudioOutputPHP::GetLevel(){
|
float AudioOutputPHP::GetLevel(){
|
||||||
return (double)getLevelMethod(static_cast<VoIP*> call);
|
return (double)getLevelMethod();
|
||||||
}
|
}
|
||||||
|
|
||||||
Php::Value AudioOutputPHP::readFrames() {
|
Php::Value AudioOutputPHP::readFrames() {
|
||||||
|
@ -30,7 +30,6 @@ private:
|
|||||||
Php::Value stopMethod;
|
Php::Value stopMethod;
|
||||||
Php::Value isPlayingMethod;
|
Php::Value isPlayingMethod;
|
||||||
Php::Value getLevelMethod;
|
Php::Value getLevelMethod;
|
||||||
void* call;
|
|
||||||
bool running;
|
bool running;
|
||||||
};
|
};
|
||||||
}}
|
}}
|
||||||
|
8
main.cpp
8
main.cpp
@ -35,11 +35,12 @@ If not, see <http://www.gnu.org/licenses/>.
|
|||||||
#include "libtgvoip/NetworkSocket.cpp"
|
#include "libtgvoip/NetworkSocket.cpp"
|
||||||
#include "libtgvoip/os/posix/NetworkSocketPosix.cpp"
|
#include "libtgvoip/os/posix/NetworkSocketPosix.cpp"
|
||||||
|
|
||||||
|
#include "audio/AudioInputPHP.h"
|
||||||
|
#include "audio/AudioOutputPHP.h"
|
||||||
|
|
||||||
#include "libtgvoip/audio/AudioInput.cpp"
|
#include "libtgvoip/audio/AudioInput.cpp"
|
||||||
#include "libtgvoip/audio/AudioOutput.cpp"
|
#include "libtgvoip/audio/AudioOutput.cpp"
|
||||||
|
|
||||||
#include "audio/AudioInputPHP.h"
|
|
||||||
#include "audio/AudioOutputPHP.h"
|
|
||||||
|
|
||||||
|
|
||||||
using namespace tgvoip;
|
using namespace tgvoip;
|
||||||
@ -52,8 +53,6 @@ public:
|
|||||||
setStateMethod = params[0];
|
setStateMethod = params[0];
|
||||||
madeline = params[3];
|
madeline = params[3];
|
||||||
current_call = params[4];
|
current_call = params[4];
|
||||||
params[1]["call"] = static_cast<void*>(this);
|
|
||||||
params[2]["call"] = static_cast<void*>(this);
|
|
||||||
inst=new VoIPController(params[1], params[2]);
|
inst=new VoIPController(params[1], params[2]);
|
||||||
inst->implData = static_cast<void*>(this);
|
inst->implData = static_cast<void*>(this);
|
||||||
inst->SetStateCallback([](tgvoip::VoIPController *controller, int state) {
|
inst->SetStateCallback([](tgvoip::VoIPController *controller, int state) {
|
||||||
@ -282,7 +281,6 @@ extern "C" {
|
|||||||
Php::ByVal("frames", Php::Type::String)
|
Php::ByVal("frames", Php::Type::String)
|
||||||
});
|
});
|
||||||
|
|
||||||
voip.constant("STATE_READY_TO_INIT", 0);
|
|
||||||
voip.constant("STATE_WAIT_INIT", 1);
|
voip.constant("STATE_WAIT_INIT", 1);
|
||||||
voip.constant("STATE_WAIT_INIT_ACK", 2);
|
voip.constant("STATE_WAIT_INIT_ACK", 2);
|
||||||
voip.constant("STATE_ESTABLISHED", 3);
|
voip.constant("STATE_ESTABLISHED", 3);
|
||||||
|
Loading…
Reference in New Issue
Block a user