C# Class ChatApp, webrtcnetwork

Contains a complete chat example. It can either run in the editor using the old unity network or in the browser as WebGL/HTML5 using WebRtc. The chat app will report during start which system it uses. The user can enter a room name and click the "Open room" button to start a server and wait for incomming connections or use the "Join room" button to join an already existing room. Note: Unity network uses random numbers / guid to idendify a server. The room name entered by the user will be ignored. As the system implements a server/client style connection all messages will first be sent to the server and the server delivers it to each client. The server side ConnectionId is used to idendify a user.
Inheritance: MonoBehaviour
ファイルを表示 Open project: devluz/webrtcnetwork Class Usage Examples

Public Properties

Property Type Description
uJoin Button
uMessageField InputField,
uOpenRoom Button
uOutput MessageList,
uRoomName InputField,
uSend Button
uShutdown Button

Public Methods

Method Description
Exit ( ) : void

Called if the Exit button is pressed. Quits the scene and shuts everything down.

Join ( ) : void

Join button pressed. Tries to join a room.

OpenRoom ( ) : void

Open room button pressed. Opens a room / starts a server

SendButtonPressed ( ) : void

This is called if the send button

Shutdown ( ) : void

Shutdown button pressed. Shuts the network down.

Private Methods

Method Description
Append ( string text ) : void

Adds a new message to the message view

FixedUpdate ( ) : void
HandleIncommingMessage ( NetworkEvent &evt ) : void
HandleNetwork ( ) : void
OnGUI ( ) : void
SendString ( string msg, bool reliable = true ) : void

Sends a string as UTF8 byte array to all connections

SetGuiState ( bool isDisconnected ) : void

Changes the gui depending on if the user is connected or disconnected

Start ( ) : void

Method Details

Exit() public method

Called if the Exit button is pressed. Quits the scene and shuts everything down.
public Exit ( ) : void
return void

Join() public method

Join button pressed. Tries to join a room.
public Join ( ) : void
return void

OpenRoom() public method

Open room button pressed. Opens a room / starts a server
public OpenRoom ( ) : void
return void

SendButtonPressed() public method

This is called if the send button
public SendButtonPressed ( ) : void
return void

Shutdown() public method

Shutdown button pressed. Shuts the network down.
public Shutdown ( ) : void
return void

Property Details

uJoin public_oe property

Join button to connect to a server.
public Button uJoin
return Button

uMessageField public_oe property

Input field to enter a new message.
public InputField, uMessageField
return InputField,

uOpenRoom public_oe property

Open room button to start a server.
public Button uOpenRoom
return Button

uOutput public_oe property

Output message list to show incomming and sent messages + output messages of the system itself.
public MessageList, uOutput
return MessageList,

uRoomName public_oe property

Input field used to enter the room name.
public InputField, uRoomName
return InputField,

uSend public_oe property

Send button.
public Button uSend
return Button

uShutdown public_oe property

Shutdown button. Disconnects all connections + shuts down the server if started.
public Button uShutdown
return Button