1
Vote

MessageReceived event is not always raised

description

If OscServer receives an OSC Packet that contains an OSC Message, then the MessageReceived event is correctly raised. But if OscServer receives an OSC Packet that contains an OSC Bundle, then the MessageReceived event is only raised if there is a BundleReceived event handler.
 
Here's my fixed version of Bespoke.Common.Osc.OscServer's OnBundleReceived method:
/// <summary>
/// Raises the <see cref="BundleReceived"/> event.
/// </summary>
/// <param name="bundle">The packet to include in the event arguments.</param>
private void OnBundleReceived(OscBundle bundle)
{
if (BundleReceived != null)
    BundleReceived(this, new OscBundleReceivedEventArgs(bundle));
 
foreach (object value in bundle.Data)
{
    if (value is OscBundle)
    {
        // Raise events for nested bundles
        OnBundleReceived((OscBundle)value);
    }
    else if (value is OscMessage)
    {
        // Raised events for contained messages
        OscMessage message = (OscMessage)value;
        if (mFilterRegisteredMethods)
        {
            if (mRegisteredMethods.Contains(message.Address))
            {
                OnMessageReceived(message);
            }
        }
        else
        {
            OnMessageReceived(message);
        }
    }
}
}

comments