1
0
mirror of https://github.com/danog/php-libtgvoip.git synced 2024-11-30 04:19:26 +01:00

Bugfixes and initial group call API

This commit is contained in:
Daniil Gentili 2018-09-04 15:49:20 +02:00
parent 19d858dafa
commit a1ed35bdad
2 changed files with 30 additions and 6 deletions

View File

@ -65,7 +65,7 @@ void VoIP::initVoIPController()
callbacks.upgradeToGroupCallRequested = NULL;
inst->SetCallbacks(callbacks);
inst->SetAudioDataCallbacks([this](int16_t *buffer, size_t size) { this->sendAudioFrame(buffer, size); }, [this](int16_t *buffer, size_t size) { this->recvAudioFrame(buffer, size); });
inst->Start();
}
void VoIP::deinitVoIPController()
@ -73,10 +73,11 @@ void VoIP::deinitVoIPController()
if (callState != CALL_STATE_ENDED)
{
callState = CALL_STATE_ENDED;
inst->Stop();
if (inst)
{
inst->Stop();
delete inst;
inst=NULL;
}
while (holdFiles.size())
@ -141,10 +142,10 @@ Php::Value VoIP::discard(Php::Parameters &params)
return false;
}
Php::Value self(this);
if (!self["configuration"])
/*if (!self["configuration"]["auth_key"])
{
return false;
}
}*/
if (self["madeline"] && self["madeline"].value().instanceOf("danog\\MadelineProto\\MTProto"))
{
Php::Array reason;
@ -168,6 +169,7 @@ Php::Value VoIP::discard(Php::Parameters &params)
}
else
debug = true;
self["madeline"].value().call("discard_call", self["internalStorage"]["callID"].value(), reason, rating, debug);
}
deinitVoIPController();
@ -239,7 +241,7 @@ Php::Value VoIP::startTheMagic()
deinitVoIPController();
return false;
}
//inst->Start();
inst->Start();
inst->Connect();
Php::Value self(this);
self["internalStorage"]["created"] = (int64_t)time(NULL);
@ -499,9 +501,9 @@ Php::Value VoIP::getDebugString()
}
Php::Value VoIP::getStats()
{
Php::Value stats;
VoIPController::TrafficStats _stats;
inst->GetStats(&_stats);
Php::Value stats;
stats["bytesSentWifi"] = (int64_t)_stats.bytesSentWifi;
stats["bytesSentMobile"] = (int64_t)_stats.bytesSentMobile;
stats["bytesRecvdWifi"] = (int64_t)_stats.bytesRecvdWifi;
@ -509,6 +511,22 @@ Php::Value VoIP::getStats()
return stats;
}
Php::Value VoIP::getPeerCapabilities()
{
return (int64_t) inst->GetPeerCapabilities();
}
void VoIP::requestCallUpgrade()
{
return inst->RequestCallUpgrade();
}
void VoIP::sendGroupCallKey(Php::Parameters &params)
{
unsigned char *key = (unsigned char *)malloc(256);
memcpy(key, params[0], 256);
inst->SendGroupCallKey(key);
}
Php::Value VoIP::getState()
{
return state;
@ -573,6 +591,9 @@ extern "C"
voip.method<&VoIP::getSignalBarsCount>("getSignalBarsCount", Php::Public | Php::Final);
voip.method<&VoIP::getDebugString>("getDebugString", Php::Public | Php::Final);
voip.method<&VoIP::getStats>("getStats", Php::Public | Php::Final);
voip.method<&VoIP::getPeerCapabilities>("getPeerCapabilities", Php::Public | Php::Final);
voip.method<&VoIP::sendGroupCallKey>("sendGroupCallKey", Php::Public | Php::Final, {Php::ByVal("key", Php::Type::String)});
voip.method<&VoIP::requestCallUpgrade>("requestCallUpgrade", Php::Public | Php::Final);
voip.method<&VoIP::startTheMagic>("startTheMagic", Php::Public | Php::Final);
voip.method<&VoIP::play>("then", Php::Public | Php::Final, {Php::ByVal("file", Php::Type::String)});

3
main.h
View File

@ -81,6 +81,9 @@ public:
Php::Value getDebugLog();
Php::Value getDebugString();
Php::Value getSignalBarsCount();
Php::Value getPeerCapabilities();
void requestCallUpgrade();
void sendGroupCallKey(Php::Parameters &params);
Php::Value debugCtl(Php::Parameters &params);
Php::Value setBitrate(Php::Parameters &params);