TsgcTURNServerEvents › OnTURNCreateAllocation

OnTURNCreateAllocation Event

Raised after a new Allocation has been successfully created for a client.

Syntax

property OnTURNCreateAllocation: TsgcTURNAllocationEvent;
// TsgcTURNAllocationEvent = procedure(Sender: TObject; const aSocket: TsgcSocketConnection; const Allocation: TsgcTURNAllocationItem) of object

Default Value

Remarks

Fired once per successful ALLOCATE, right after the Allocation has been added to the server's internal table and the AllocateResponse has been dispatched to the client. Allocation exposes the full context: LocalIP/LocalPort (server-side listening endpoint), ReflexiveIP/ReflexivePort (client's mapped address), RelayIP/RelayPort (the relayed transport address advertised to the client via XOR-RELAYED-ADDRESS), Username/Realm, Lifetime / Expiry and the Permissions / Channels sub-collections. Use it to update operational dashboards, accounting or per-user quotas. The Allocation instance is owned by the server — do not free it; it is passed again to OnTURNDeleteAllocation when the allocation expires. Runs on the listener thread unless NotifyEvents redirects it.

Example

procedure TForm1.OnTURNCreateAllocation(Sender: TObject;
  const aSocket: TsgcSocketConnection; const Allocation: TsgcTURNAllocationItem);
begin
  Memo1.Lines.Add(Format('Allocation created: user=%s relay=%s:%d lifetime=%d',
    [Allocation.Username, Allocation.RelayIP, Allocation.RelayPort,
     Allocation.Lifetime]));
end;

Back to Events