Hi,
Currently we don’t have an API dedicated for counting the number of active viewers. It is included in future roadmap however. For now you can use the events you mentioned (outStreamCreated/outStreamClosed) for RTMP and (streamingSessionStarted/streamingSessionEnded) for HLS.
The outStreamCreated/outStreamClosed event does not accurately represent an active viewer however, but that’s the closest you can get.