Web Sockets
Gameface has built-in web socket support, which allows your interface to receive data from a server without rerouting the connection through JavaScript Binding.
The Web Socket API is described in Include/Cohtml/Socket.h
and consists of the classes cohtml::ISocketListener
, cohtml::IViewListener::OnCreateWebSocket
and cohtml::IClientSideSocket
.
To integrate WebSockets with your Gameface interface, you must first have a WebSocket library implemented with your engine. In order to create WebSocket your ViewListener must implement properly cohtml::IViewListener::OnCreateWebSocket
Gameface supports sending and receiving string or binary data over WebSocket.
WebSocket.send(data)
JS API is implemented for strings and binary types (Blob
, ArrayBuffer
, ArrayBufferView
).
Blob
objects over WebSocket.To use binary messages, the cohtml::websocket::OpCode
should be used properly according to the cohtml::ISocketListener
and cohtml::IClientSideSocket
API.
On the JS side, the binaryType property can be used to control the type of received binary data.
Example implementation
WebSocketHub.cpp
– an example implementation of the web socket API can be found in the Modules/WebSockets
directory of your distribution package.