|
using System.Collections.Generic;
using Ozeki.VoIP;
using Ozeki.VoIP.PBX;
using Ozeki.VoIP.PBX.Extensions;
using Ozeki.VoIP.PBX.Services;
namespace MyPBX.CallQueue
{
class CallQueueExtension : IExtension
{
IExtensionContainer extensionContainer;
IPBXCallFactory callFactory;
List<CallQueueCallHandler> callHandlers;
ICallManager callManager;
List<string> members;
object sync;
public CallQueueExtension(string extensionId, IExtensionContainer extensionContainer, IPBXCallFactory callFactory, ICallManager callManager, List<string> members)
{
sync = new object();
callHandlers = new List<CallQueueCallHandler>();
Account = new Account(extensionId, extensionId, "ozekiphone.com");
this.extensionContainer = extensionContainer;
this.callFactory = callFactory;
this.callManager = callManager;
this.members = members;
}
public Account Account { get; private set; }
public Ozeki.VoIP.PBX.PhoneCalls.ISIPCall OnCalled(Ozeki.VoIP.PBX.PhoneCalls.RouteInfo callInfo)
{
lock (sync)
{
var call = callFactory.CreateIncomingPBXCall(this, SRTPMode.None);
var callQueueHandler = new CallQueueCallHandler(call, callManager, extensionContainer, members);
callQueueHandler.Completed += CallHandlerCompleted;
callHandlers.Add(callQueueHandler);
if (callHandlers.Count == 1)
{
callQueueHandler.Start();
}
return call;
}
}
void CallHandlerCompleted(object sender, System.EventArgs e)
{
lock (sync)
{
var callHandler = (CallQueueCallHandler)sender;
if (callHandlers[0] == callHandler)
{
callHandlers.Remove(callHandler);
if (callHandlers.Count >= 1)
{
var nextCallHandler = callHandlers[0];
nextCallHandler.Start();
}
}
else
{
callHandlers.Remove(callHandler);
}
}
}
public void SendMessage(Ozeki.VoIP.PBX.Message message)
{
}
public string Type
{
get { return "CallQueue"; }
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.