Rantanen / node-mumble

Mumble client in Node.js
MIT License
155 stars 48 forks source link

channelByName finds only one channel #51

Closed soanaphikeste closed 9 years ago

soanaphikeste commented 9 years ago

When there are multiple channels with the same name, channelByName will only return one of them.

For example this is a valid channel structure (at least the official client allows it to be created):

-Root
    -Test1
        - A
    - Test2
        - A

Then calling myMumbleConnection.channelByName("A") will return /Root/Test 1/A, but not /Root/Test 2/A.

Rantanen commented 9 years ago

This is by design. While not optimal, it's far more confusing for a function to suddenly change from returning a single value to returning an array based on server admin adding/renaming channels.

Added channelByPath() to MumbleClient. You can use this with:

// Get the root channel
var root = client.channelByPath( '/' );

// Get the Root > Test2 > A channel
var test2a = client.channelByPath( '/Test2/A' );

If you need something else, you can always build your own lookup routines on top of the client.rootChannel and Channel.children collection.

soanaphikeste commented 9 years ago

Thank you :)

Prior99 commented 9 years ago

I don't know. I think it is a better idea to always return an array, if there is only one channel with the specified name, return an array with only one item. But returning only one channel when there are multiple channels without having defined behaviour which one will be returned sounds like bad design.

Rantanen commented 9 years ago

Yeah. I'm guessing the channelByPath fixed this. If not, there's always the Channel.children collection. Closing this.