TsgcWSPServer_WebRTCMethods › WriteData

WriteData Method

Sends a text payload to a single connected peer identified by its connection GUID.

Syntax

function WriteData(aGuid, aMessage: string): Boolean;

Parameters

NameTypeDescription
aGuidstringGUID of the target connection (the value of TsgcWSConnection.Guid captured in OnConnect or returned to the peer at handshake time).
aMessagestringText payload to deliver; wrapped in the signalling envelope with an empty Method and Channel before being sent out.

Return Value

True if a live connection with that GUID was found and the frame was queued for delivery; False when no such peer is connected. (Boolean)

Remarks

Low-level unicast primitive: targets a specific peer by GUID regardless of channel subscriptions, which makes it the right call for acknowledgments, server-initiated invitations or direct administrative messages. The payload is wrapped in a signalling envelope so the JavaScript shim can deliver it to the browser's application callback; it does not itself carry an SDP offer/answer or ICE candidate — those relays are triggered automatically by the peer-to-peer sgc@webrtc flow when clients negotiate.

Example


// greet the peer that just joined with a welcome payload
procedure TForm1.WebRTCConnect(Connection: TsgcWSConnection);
begin
  WebRTCSrv.WriteData(Connection.Guid, '{"type":"welcome"}');
end;

Back to Methods