Class Utils
public static class Utils
- Inheritance
-
Utils
- Inherited Members
Methods
AttachCode(SignalMessage, string)
Attach a matchmaking code to a message (stored in sessionId).
public static void AttachCode(SignalMessage msg, string code)
Parameters
msgSignalMessagecodestring
BuildWireSignal(SignalMessage, string)
Build the wire format for signaling used by this project: "WIT_RTC_SIGNAL|{scope}|{json}".
public static string BuildWireSignal(SignalMessage msg, string scope)
Parameters
msgSignalMessagescopestring
Returns
BuildWireSignalWithCode(SignalMessage, string, string)
Build a wire signal including scope and code for easy routing. Wire: WIT_RTC_SIGNAL|{scope}|{code}|{json}
public static string BuildWireSignalWithCode(SignalMessage msg, string scope, string code)
Parameters
msgSignalMessagescopestringcodestring
Returns
CreateDataChannelInit(bool)
Create a DataChannel init object for reliable/unreliable channels.
public static Unity.WebRTC.RTCDataChannelInit CreateDataChannelInit(bool reliable)
Parameters
reliablebool
Returns
- RTCDataChannelInit
CreateIceSignal(string, string, int, string, string)
Create a SignalMessage for an ICE candidate.
public static SignalMessage CreateIceSignal(string candidate, string sdpMid, int sdpMLineIndex, string fromId = null, string toId = null)
Parameters
Returns
CreateRtcConfig(string[], string[], string, string)
Create an RTCConfiguration with optional STUN and TURN servers. Example: new[] { "stun:stun.l.google.com:19302" }
public static Unity.WebRTC.RTCConfiguration CreateRtcConfig(string[] stunUrls = null, string[] turnUrls = null, string turnUsername = null, string turnCredential = null)
Parameters
Returns
- RTCConfiguration
CreateSdpSignal(string, string, string, string)
Create a SignalMessage for an SDP offer/answer.
public static SignalMessage CreateSdpSignal(string sdp, string type, string fromId = null, string toId = null)
Parameters
Returns
DeserializeSignal(string)
Deserialize a SignalMessage from JSON. Returns null if parse fails.
public static SignalMessage DeserializeSignal(string json)
Parameters
jsonstring
Returns
GenerateCode(int)
Generate a short alphanumeric matchmaking code (e.g., 6 chars).
public static string GenerateCode(int length = 6)
Parameters
lengthint
Returns
MatchesCode(SignalMessage, string)
Check if a message matches the provided code.
public static bool MatchesCode(SignalMessage msg, string code)
Parameters
msgSignalMessagecodestring
Returns
RegisterDataChannelEvents(RTCDataChannel, UnityAction<RTCDataChannel>, UnityAction<RTCDataChannel>, UnityAction<RTCDataChannel, byte[]>)
public static void RegisterDataChannelEvents(RTCDataChannel channel, UnityAction<Unity.WebRTC.RTCDataChannel> onOpen = null, UnityAction<Unity.WebRTC.RTCDataChannel> onClose = null, UnityAction<Unity.WebRTC.RTCDataChannel, byte[]> onMessage = null)
Parameters
channelRTCDataChannelonOpenUnityAction<RTCDataChannel>onCloseUnityAction<RTCDataChannel>onMessageUnityAction<RTCDataChannel, byte[]>
SerializeSignal(SignalMessage)
Serialize a SignalMessage to JSON.
public static string SerializeSignal(SignalMessage msg)
Parameters
msgSignalMessage
Returns
SetLocalDescriptionCoroutine(RTCPeerConnection, RTCSessionDescription, Action<string>)
Coroutine helper to set local description on a peer connection and yield until complete. On error, optional onError is invoked with message.
public static IEnumerator SetLocalDescriptionCoroutine(Unity.WebRTC.RTCPeerConnection pc, Unity.WebRTC.RTCSessionDescription desc, Action<string> onError = null)
Parameters
Returns
SetRemoteDescriptionCoroutine(RTCPeerConnection, RTCSessionDescription, Action<string>)
Coroutine helper to set remote description on a peer connection and yield until complete.
public static IEnumerator SetRemoteDescriptionCoroutine(Unity.WebRTC.RTCPeerConnection pc, Unity.WebRTC.RTCSessionDescription desc, Action<string> onError = null)
Parameters
Returns
TryParseWireSignal(string, out string, out SignalMessage)
Try to parse the wire format built with BuildWireSignal.
public static bool TryParseWireSignal(string wire, out string scope, out SignalMessage msg)
Parameters
wirestringscopestringmsgSignalMessage
Returns
TryParseWireSignalWithCode(string, out string, out string, out SignalMessage)
Try parse wire signal with scope and code.
public static bool TryParseWireSignalWithCode(string wire, out string scope, out string code, out SignalMessage msg)
Parameters
wirestringscopestringcodestringmsgSignalMessage