Skip to content

chore: expose websockets #2201

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Additional documentation and release notes are available at [Multiplayer Documen

## [Unreleased]

### Added

- Added WebSocket support when using UTP 2.0 with `UseWebSockets` property in the `UnityTransport` component of the `NetworkManager` allowing to pick WebSockets for communication. When building for WebGL, this selection happens automatically. (#2201)

### Changed

- The debug simulator in `UnityTransport` is now non-deterministic. Its random number generator used to be seeded with a constant value, leading to the same pattern of packet drops, delays, and jitter in every run. (#2196)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ private enum State
[SerializeField]
private ProtocolType m_ProtocolType;

#if UTP_TRANSPORT_2_0_ABOVE
[Tooltip("Whether or not to use WebSockets as Network Interface")]
[SerializeField]
private bool m_UseWebSockets = false;

public bool UseWebSockets
{
set => m_UseWebSockets = value;
get => m_UseWebSockets;
}
#endif

[Tooltip("The maximum amount of packets that can be in the internal send/receive queues. Basically this is how many packets can be sent/received in a single update/frame.")]
[SerializeField]
private int m_MaxPacketQueueSize = InitialMaxPacketQueueSize;
Expand Down Expand Up @@ -1365,7 +1377,23 @@ public void CreateDriver(UnityTransport transport, out NetworkDriver driver,
#endif
heartbeatTimeoutMS: transport.m_HeartbeatTimeoutMS);

#if UTP_TRANSPORT_2_0_ABOVE
if (m_UseWebSockets)
{
driver = NetworkDriver.Create(new WebSocketNetworkInterface(), m_NetworkSettings);
}
else
{
#if UNITY_WEBGL
Debug.LogWarning($"WebSockets were used even though they're not selected in NetworkManager. You should check {nameof(UseWebSockets)}', on the Unity Transport component, to silence this warning.");
driver = NetworkDriver.Create(new WebSocketNetworkInterface(), m_NetworkSettings);
#else
driver = NetworkDriver.Create(new UDPNetworkInterface(), m_NetworkSettings);
#endif
}
#else
driver = NetworkDriver.Create(m_NetworkSettings);
#endif

#if MULTIPLAYER_TOOLS_1_0_0_PRE_7
#if UTP_TRANSPORT_2_0_ABOVE
Expand Down