TsgcTURNServer › Eventos › OnTURNCreateAllocation
Se genera después de que se haya creado correctamente una nueva Asignación para un cliente.
property OnTURNCreateAllocation: TsgcTURNAllocationEvent;
// TsgcTURNAllocationEvent = procedure(Sender: TObject; const aSocket: TsgcSocketConnection; const Allocation: TsgcTURNAllocationItem) of object
—
Se activa una vez por cada ALLOCATE exitoso, justo después de que la asignación se haya añadido a la tabla interna del servidor y se haya enviado AllocateResponse al cliente. Allocation expone el contexto completo: LocalIP/LocalPort (endpoint de escucha en el servidor), ReflexiveIP/ReflexivePort (dirección mapeada del cliente), RelayIP/RelayPort (la dirección de transporte retransmitida anunciada al cliente mediante XOR-RELAYED-ADDRESS), Username/Realm, Lifetime / Expiry y las subcolecciones Permissions / Channels. Úselo para actualizar paneles operativos, contabilidad o cuotas por usuario. La instancia de Allocation es propiedad del servidor: no la libere; se pasa de nuevo a OnTURNDeleteAllocation cuando la asignación expira. Se ejecuta en el hilo de escucha a menos que NotifyEvents lo redirija.
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;