SendData(string message)
Call this function to send any string data either to specific peer or all peer in the room. Pass "*" to send data to all peers in the room or peerId to specific peer in the room
Parameters
Params | Type | Description |
---|---|---|
to | string | peer ID or "*" for all peers. |
data | string | Any data or message in form of string |
label | string | The label of the data message. |
Example
.csharp
//Send data to all peers in the room
Huddle01Core.Instance.SendData("*",data,label);
//Send data to peer in a room
Huddle01Core.Instance.SendData(<peerId>,data,label);
SendData(List<string> peerIds,string data, string label)
Call this function to send any string data or message to selected peers in the room.
Parameters
Params | Type | Description |
---|---|---|
peerIds | List<string> | List of peerIds |
data | string | Any data or message in form of string |
label | string | The label of the data message. |
Example
.csharp
public void SendData(List<string> peerIds,string data,string label)
{
Huddle01Core.Instance.SendData(peerIds,data,label);
}
HuddleCore.OnMessageReceived
Subscribe to this event to receive message send by any peer in the room.
Parameters
Params | Type | Description |
---|---|---|
message | string | message in form of json which can be Deserialized into `MessageReceivedResponse` |
.csharp
private void OnEnable()
{
Huddle01Core.OnMessageReceived += OnMessageReceived;
}
private void OnDisable()
{
Huddle01Core.OnMessageReceived -= OnMessageReceived;
}
private void OnMessageReceived(string data)
{
Debug.Log($"received data : {data}");
MessageReceivedResponse response = JsonConvert.DeserializeObject<MessageReceivedResponse>(data);
}
[System.Serializable]
public class MessageReceivedResponse
{
[JsonProperty("from")]
public string From;
[JsonProperty("label")]
public string Label;
[JsonProperty("payload")]
public string Payload;
}