Skip to main content

FM WebSocket 4.0

Description

Minimal setup guide for Internet Live Stream via FMWebsocketManager.


Basic Setup

FM WebSocket 4.0 supports “Room System” with customised room name. All the data are streaming through the self-host node.js server. (server script included in the package)

This package includes example script of a very light-weight node.js server, which you may host it on any Cloud Virtual Machine(linux, windows or mac)

There are two parts in this tutorial setup.

Part A: node.js server

Part B: Unity3D FMWebSocketManager


Part A: Node.js server

Our example server is located in our plugin root folder

/FMWebSocket/TestServer_v6.x.x/Resources/FMWebSocket
  1. Install npm + node.js Download and install necessary items
https://nodejs.org/en/download/
  1. Install express https://expressjs.com/en/starter/installing.html
cmd/terminal: npm init
cmd/terminal: Enter…
cmd/terminal: npm install express –save
  1. Install ws module
cmd/terminal: npm install ws
  1. Finish & Test on localhost

You may follow this step-by-step tutorial, the commands are compatible in Mac/Windows/Linux https://youtu.be/Zjm5KGHyceU


Part B: Unity3D FMWebSocketManager Setup


Setup for Sender Scene(Sender)

  1. Create a new GameObject in your scene, and name it FMWebSocketManager.
  2. Add Component FMWebSocketManager.cs
  3. Choose NetworkType: Room
  4. enabled Auto Init is recommended, which will automatically start the connection in runtime.
  5. you may also connect them manually as alternative via script. fmetp-stream-fmwebsocket4-s1

//All node.js server examples are included in "/FMWebSocket/TestServer_v4.x.x"

//---------------- For NetworkType: Room ----------------
//Connect as "Room" network type, Create or Join Room with customised name
FMWebSocketManager.instance.Action_JoinOrCreateRoom("MyRoomTest");
//Close connection from node.js Server
FMWebSocketManager.instance.Action_Close();
//Request for Network identify "RoomMaster"
FMWebSocketManager.instance.Action_RequestRoomMaster();

//Send to all Room Clients including yourself
FMWebSocketManager.instance.SendToAll(byte[] _byteData);
FMWebSocketManager.instance.SendToAll(string _stringData);
//Send to Room Master
FMWebSocketManager.instance.SendToServer(byte[] _byteData);
FMWebSocketManager.instance.SendToServer(string _stringData);
//Send to Others
FMWebSocketManager.instance.SendToOthers(byte[] _byteData);
FMWebSocketManager.instance.SendToOthers(string _stringData);
//Send to Target WISD in the same room
FMWebSocketManager.instance.SendToTarget(byte[] _byteData, string _wsid);
FMWebSocketManager.instance.SendToTarget(string _stringData, string _wsid);
//---------------- For NetworkType: Room ----------------

//---------------- For NetworkType: WebSocket only ----------------
//Connect as "WebSocket" network type, WebSocket Mode is only for standard websocket connection
FMWebSocketManager.instance.Action_InitAsWebSocket();
FMWebSocketManager.instance.WebSocketSend(byte[] _byteData);
FMWebSocketManager.instance.WebSocketSend(string _stringData);
//---------------- For NetworkType: WebSocket only ----------------