add caller pin for entering mumble session

caller must enter pin before being unmuted/undeafened in mumble room
This commit is contained in:
Scott Hardin 2017-05-21 16:03:19 +02:00
parent e0a3a67410
commit dc77504338
4 changed files with 51 additions and 2 deletions

View File

@ -144,7 +144,16 @@ namespace sip {
communicator.logger.notice(msgText);
communicator.onStateChange(msgText);
communicator.got_dtmf = "";
/*
* if no pin is set, go ahead and turn off mute/deaf
* otherwise, wait for pin to be entered
*/
if ( communicator.pin.length() == 0 ) {
communicator.onMuteDeafChange(0);
}
} else if (ci.state == PJSIP_INV_STATE_DISCONNECTED) {
auto &acc = dynamic_cast<_Account &>(account);
@ -183,7 +192,31 @@ namespace sip {
}
void _Call::onDtmfDigit(pj::OnDtmfDigitParam &prm) {
communicator.logger.notice("DTMF digit '%s' (call %d).", prm.digit.c_str(), getId());
communicator.logger.notice("DTMF digit '%s' (call %d).",
prm.digit.c_str(), getId());
pj::CallOpParam param;
if ( communicator.pin.length() > 0 ) {
if ( prm.digit == "#" ) {
communicator.logger.notice("DTMF got string command %s",
communicator.got_dtmf.c_str());
if ( communicator.got_dtmf == communicator.pin ) {
communicator.logger.notice("Caller entered correct PIN");
communicator.onMuteDeafChange(0);
} else {
communicator.logger.notice("Caller entered wrong PIN");
param.statusCode = PJSIP_SC_SERVICE_UNAVAILABLE;
this->hangup(param);
}
communicator.got_dtmf = "";
} else {
communicator.logger.notice("DTMF append %s to %s",
prm.digit.c_str(), communicator.got_dtmf.c_str());
communicator.got_dtmf = communicator.got_dtmf + prm.digit;
}
} else {
communicator.logger.notice("DTMF ignoring %s", prm.digit.c_str());
}
}
void _Account::onRegState(pj::OnRegStateParam &prm) {
@ -324,3 +357,4 @@ void sip::PjsuaCommunicator::registerAccount(string host, string user, string pa
account.reset(new _Account(*this));
account->create(accountConfig);
}

View File

@ -76,6 +76,9 @@ namespace sip {
int16_t *samples,
unsigned int length);
std::string pin;
std::string got_dtmf;
std::function<void(int16_t *, int)> onIncomingPcmSamples;
std::function<void(std::string)> onStateChange;

View File

@ -28,6 +28,11 @@ channelNameExpression =
# in the same group
autodeaf = 0
# Caller PIN needed to authenticate the phone call itself. The caller presses
# the PIN, followed by the hash '#' key. On success, the caller is
# unmuted/undeafened. On failure, the SIP call is hung up.
pin = 4321
# Bitrate of Opus encoder in B/s
# Adjust it if you need to meet the specific bandwidth requirements of Murmur server
opusEncoderBitrate = 16000

View File

@ -96,6 +96,13 @@ int main(int argc, char *argv[]) {
mumbleConf.autodeaf = false;
}
/* default to <no pin> */
try {
pjsuaCommunicator.pin = conf.getString("mumble.pin");
} catch (...) {
pjsuaCommunicator.pin = "";
}
mumbleCommunicator.connect(mumbleConf);
pjsuaCommunicator.connect(