def _handle_create(self, e): '''Handle channel create events by building local `Session` and `Call` objects for state tracking. ''' uuid = e.getHeader('Unique-ID') self.log.debug("channel created for session '{}'".format(uuid)) # Record the newly activated session # TODO: pass con as weakref? con = self._tx_con if not self._shared else None sess = Session(event=e, con=con) sess.cid = self.get_id(e, 'default') # note the start time and current load # TODO: move this to Session __init__?? sess.create_time = get_event_time(e) # Use our special Xheader to try and associate sessions into calls # (assumes that x-headers are forwarded by the proxy/B2BUA) call_uuid = e.getHeader('variable_{}'.format(self.call_corr_xheader)) # If that fails then try using the freeswitch 'variable_call_uuid' # (only works if bridging takes place locally) if call_uuid is None: call_uuid = e.getHeader(self.call_corr_var) # could be 'None' if not call_uuid: self.log.warn("Unable to associate session '{}' into calls" .format(sess.uuid)) # associate sessions into a call # (i.e. set the relevant sessions to reference each other) if call_uuid in self.calls: call = self.calls[call_uuid] self.log.debug("session '{}' is bridged to call '{}'".format( uuid, call.uuid)) # append this session to the call's set call.append(sess) else: # this sess is not yet tracked so use its id as the 'call' id call = Call(call_uuid, sess) self.calls[call_uuid] = call self.log.debug("call created for session '{}'".format(call_uuid)) sess.call = call self.sessions[uuid] = sess return True, sess
def _handle_create(self, e): '''Handle channel create events by building local `Session` and `Call` objects for state tracking. ''' uuid = e.getHeader('Unique-ID') self.log.debug("channel created for session '{}'".format(uuid)) # Record the newly activated session # TODO: pass con as weakref? con = self._tx_con if not self._shared else None sess = Session(event=e, con=con) sess.cid = self.get_id(e, 'default') # note the start time and current load # TODO: move this to Session __init__?? sess.create_time = get_event_time(e) # Use our special Xheader to try and associate sessions into calls # (assumes that x-headers are forwarded by the proxy/B2BUA) call_uuid = e.getHeader('variable_{}'.format(self.call_corr_xheader)) # If that fails then try using the freeswitch 'variable_call_uuid' # (only works if bridging takes place locally) if call_uuid is None: call_uuid = e.getHeader(self.call_corr_var) # could be 'None' if not call_uuid: self.log.warn("Unable to associate session '{}' into calls" .format(sess.uuid)) # associate sessions into a call # (i.e. set the relevant sessions to reference each other) if call_uuid in self.calls: call = self.calls[call_uuid] self.log.debug("session '{}' is bridged to call '{}'".format( uuid, call.uuid)) # append this session to the call's set call.sessions.append(sess) else: # this sess is not yet tracked so use its id as the 'call' id call = Call(call_uuid, sess) self.calls[call_uuid] = call self.log.debug("call created for session '{}'".format(call_uuid)) sess.call = call self.sessions[uuid] = sess return True, sess