How to Create an HTML5 and WebGL Client¶
Unity supports the WebGL platform as a target, which allows you to run your Unity application on a web browser using HTML5 technology and WebGL graphics rendering subsystem. Beginning with Strix Unity SDK version 1.5.0, you can build your STRIX client for WebGL platforms.
Configuring the servers¶
You need to use a WebSocket protocol to run your STRIX client on WebGL platforms. Make sure to configure your master and room servers to use a WebSocket connection. You can use either a regular WebSocket (ws) or secure WebSocket (wss) connection depending on your needs.
On Strix Cloud, regular WebSocket is not available, and you will always choose “WSS” (secure WebSocket) from the Protocol dropdown on the Create Cluster or Configure Server popup.
Note
The Protocol dropdown is initially hidden on the Create Cluster popup, and you need to click on the Show more options to see it.
See Strix Cloud User’s Guide for details.
No other settings are required to use WebSocket on Strix Cloud.
Connecting via WebSocket¶
Use an overload of StrixNetwork.ConnectMasterServer
method
with three arguments (i.e., the one without the port
argument)
to connect to the master server using WebSocket.
The host
string should be either of the following patterns:
ws://master-hostname[:port][/path]
(for a regular WebSocket connection)wss://master-hostname[:port][/path]
(for a secure WebSocket connection)
If you use Strix Cloud, the port is always 9122 and no path is used.
You will only need to check the Master Hostname shown on your Application Dashboard
to construct your host
string.
If your master hostname is 000000000000000000000000.game.strixcloud.net
,
the host
string will be as follows:
wss://000000000000000000000000.game.strixcloud.net:9122
Example:
string masterHostUrl = "wss://000000000000000000000000.game.strixcloud.net:9122";
StrixNetwork.instance.ConnectMasterServer(masterHostUrl, successHandler, failureHandler);
When connecting to a room server,
the master server tells your client the protocol to be used,
and the SDK uses it automatically.
You usually don’t need to worry about the use of WebSocket
on a room server connection.
However, if you are to connect to a room server manually,
you should use the RoomInfo.protocol
as the protocol for the connection.
Note
You should always specify ws://
or wss://
in the host
parameter
of StrixNetwork.ConnectMasterServer
if you intend to build your game for WebGL platforms.
If you omit the protocol in the host
parameter,
i.e., if you specify a string that comprises the master hostname alone like
"000000000000000000000000.game.strixcloud.net"
,
the default protocol depends on the platform the script is running on.
Your program built for WebGL will try to connect to the master server using WebSocket
when you start it in a web browser.
However, when you run your program in the play mode in your Unity Editor,
the protocol defaults to TCP,
and you can’t connect to your master server that is configured to use WebSocket.
By specifying wss://000000000000000000000000.game.strixcloud.net:9122
,
ConnectMasterServer
always connects using secure WebSocket,
including in the play mode.
Cross-platform matchmaking¶
You can release your game for both WebGL platforms and other platforms, allowing cross-platform matchmaking.
You should connect to the master server using the same host
string
that begins either ws://
or wss://
in all platform versions.
Packaging for WebGL platforms¶
When you build your game for WebGL platforms, you should follow Unity’s ordinary packaging process for WebGL support. That is, you need to choose WebGL as the Platform on the Build Settings dialog box and leave other settings as their defaults.
No special settings are required to use Strix Unity SDK on WebGL platforms.
Other considerations¶
You need Strix Unity SDK version 1.5.0 or later to use it with the WebGL platforms. Earlier versions don’t support WebSocket, and they don’t work with WebGL platforms.
Make sure to set Strix server version of you Application to 1.3.0 or later to use Strix Cloud for WebGL platforms. The Strix server version dropdown is on the Options page of your Application Dashboard on Strix Cloud. (See Strix Cloud User’s Guide.)
Unity officially supports WebGL platforms, but there are some WebGL-specific limitations and restrictions on some Unity features. You should consult an appropriate Unity documentation for its WebGL support. In particular, Unity documentation says that Unity WebGL doesn’t support mobile devices.
Note
Strix Unity SDK provides cross-platform interoperability between WebGL PC clients and native mobile clients, for example, so you can release your game that way.
You need a web server from which users’ web browsers download your WebGL client. Strix Cloud doesn’t provide one, so you need a separate website.