All pastes #17793 Raw Edit

Someone

public text v1 · immutable
#17793 ·published 2005-07-15 20:04 UTC
rendered paste body
sub get_vol {
  my $cmd = AUMIX." -vq";
  my $vol = `$cmd`;
  $vol =~ s/vol //;
  $vol =~ s/,.*//;
  chomp($vol);
  return $vol
}

sub set_vol {
  my $vol = shift;
  warn "VOL - Setting volume to $vol\n";
  my $cmd = AUMIX . " -v " . $vol;
  system($cmd);
}

sub monitor_ring {
  my ($manager, $normvol) = @_;
  while (my $line = $manager->getline( Timeout => 60 ))
  # It's safe to do it like this - Net::Telnet will just block waiting for
  # feedback from the Asterisk Manager
  {
    if ($line =~ /^Event: Newchannel/) {
      my $chan = $manager->getline();
      foreach (@channels) {
        if ($chan =~ /Channel: $_-/) {
          my $state = $manager->getline();
          if($state =~ /^State: Ring/) { # Captures both 'Ring' (outbound)
                                         # and 'Ringing' (inbound)
            $manager->getline();
            my $uid = $manager->getline();
            $uid =~ s/Uniqueid: //;
            unless (scalar keys %activecalls) { # If this is < 1 no 
                                                #calls are active
                        $normvol = get_vol();
                        set_vol(RINGVOL); # Set volume to 'quiet' level
            if(KOPETE_AWAY){
                                warn "AWAY - Setting kopete away";
                                system("dcop kopete KopeteIface setAway");
                        }
           }
           $activecalls{$uid} = 1; # Add this call to the hash
          }
        }
      }
    }
    elsif ($line =~ /^Event: Hangup/) {
      warn "VOL - Channel hanging up...\n";
      my $chan = $manager->getline();
          $chan =~ s/\n//;
      foreach (@channels) {
        warn "VOL - Checking if $chan is like $_-\n";
        if ($chan =~ /Channel: $_-/) {
          my $uid = $manager->getline();
          $uid =~ s/Uniqueid: //;
          delete($activecalls{$uid});
          unless (scalar keys %activecalls) {
                        set_vol($normvol);
                        if(KOPETE_AWAY){
                                warn "AWAY - setting kopete available";
                                system("dcop kopete KopeteIface setAvailable");
                        }
                  }
        }
      }
    }
  #warn "VOL - Calls: ", scalar keys %activecalls, "\n";
  }
  return $normvol;
}