'Called by the XmlStream when the stream has started.
This extends L{Authenticator.streamStarted} to extract further stream
headers from C{rootElement}, optionally wait for stream features being
received and then call C{initializeStream}.'

def streamStarted(self, rootElement):

    Authenticator.streamStarted(self, rootElement)
    self.xmlstream.sid = rootElement.getAttribute('id')
    if rootElement.hasAttribute('from'):
        self.xmlstream.otherEntity = jid.internJID(rootElement['from'])
    if (self.xmlstream.version >= (1, 0)):
        def onFeatures(element):
            features = {}
            for feature in element.elements():
                features[(feature.uri, feature.name)] = feature
            self.xmlstream.features = features
            self.initializeStream()
        self.xmlstream.addOnetimeObserver(('/features[@xmlns="%s"]' % NS_STREAMS), onFeatures)
    else:
        self.initializeStream()
