All TURN operations revolve around allocations and all TURN messages are associated with an Allocation. An allocation consists of:
When a TURN client sends an Allocate request, this TURN message is processed by server and tries to create a new Relayed Transport Address. By default, if there is any available UDP port, it will create a new Relayed Address, but you can use OnTURNBeforeAllocate event to reject a new Allocation request.
procedure OnTURNBeforeAllocate(Sender: TObject; const aSocket: TsgcSocketConnection;
const aIP: string; aPort: Word; var Reject: Boolean);
begin
if not (your own rules) then
Reject := false;
end;
If the process continues, the server creates a new allocation and the event OnTURNCreateAllocation is called. This event provides information about the Allocation through the class TsgcTURNAllocationItem.
procedure OnTURNCreateAllocation(Sender: TObject; const aSocket: TsgcSocketConnection;
const Allocation: TsgcTURNAllocationItem);
begin
DoLog('New Allocation: ' + Allocation.RelayIP + ':' + IntToStr(Allocation.RelayPort));
end;
When the Allocation expires or is deleted receiving a Refresh Request from client with a lifetime of zero, the event OnTURNDeleteAllocation event is fired.
procedure OnTURNDeleteAllocation(Sender: TObject; const aSocket: TsgcSocketConnection;
const Allocation: TsgcTURNAllocationItem);
begin
DoLog('Allocation Deleted: ' + Allocation.RelayIP + ':' + IntToStr(Allocation.RelayPort));
end;