Placeholder-Software / Dissonance

Unity Voice Chat Asset
71 stars 5 forks source link

[feature] Create new rooms during runtime #66

Closed jakemoves closed 6 years ago

jakemoves commented 6 years ago

Is it currently possible to define / create new rooms during runtime? If so, how? If not... it would be very useful, but maybe it's not architecturally possible.

martindevans commented 6 years ago

There are two ways to create a new room at runtime.

The best way of doing it (because it presents a better interface) is to directly use the Channel API to open and close audio channels. This is how the trigger components work internally.

DissonanceComms comms;

// Begin listening to a room
var listen = comms.Rooms.Join("Some Room Name");

// Begin talking to a room
var transmit = comms.RoomChannels.Open("Some Room Name");

// Stop listening
comms.Rooms.Leave(listen);

// Stop talking
comms.RoomChannels.Close(transmit);

You could also create a new pair of VoiceBroadcastTrigger/VoiceReceiptTrigger components and configure them as you like. For example:

var c = SomeGameObject.AddComponent<VoiceBroadcastTrigger>();
c.RoomName = "Some Room Name";
c.ChannelType = CommTriggerTarget.Room;

I'll close this issue since I've answered the question, but feel free to ask followup questions if it's not clear :)

jakemoves commented 6 years ago

Thank you for the speedy reply!

Would you expect either of these to work with text chat messages directed at a particular Room?

On Nov 13, 2017, at 9:08 AM, Martin Evans notifications@github.com wrote:

There's two ways to create a new room at runtime.

The best way of doing it (because it presents a better interface) is to directly use the Channel API to open and close audio channels. This is how the trigger components work internally.

DissonanceComms comms;

// Begin listening to a room var listen = comms.Rooms.Join("Some Room Name");

// Begin talking to a room var transmit = comms.RoomChannels.Open("Some Room Name");

// Stop listening comms.Rooms.Leave(listen);

// Stop talking comms.RoomChannels.Close(transmit); You could also create a new pair of VoiceBroadcastTrigger/VoiceReceiptTrigger components and configure them as you like. For example:

var c = SomeGameObject.AddComponent(); c.RoomName = "Some Room Name"; c.ChannelType = CommTriggerTarget.Room; I'll close this issue since I've answered the question, but feel free to ask followup questions if it's not clear :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

martindevans commented 6 years ago

Absolutely. Ultimately text chat messages use the same internal rooms system as voice messages so if you're listening to a room you should receive both text and voice messages directed to that room.

i.e.

// Peer 1
DissonanceComms comms;
var listen = comms.Rooms.Join("A Room");
// Peer 2
DissonanceComms comms;
comms.Text.Send("A Room", "A Message");

In the above example peer 1 will receive the message "A Message" because he's listening to "A Room".

martindevans commented 6 years ago

In my first reply I linked you to a general tutorial on "Script controlled speech". There's a more specific "Channel API" tutorial here