     @emit 'broadcast_actual_changed', name
     for clientID, session of sessions
       if session.streamName == "broadcast" && session.stream != stream
-        session.offsetTimestamp = session.lastTimestamp - stream_ts
-        session.stream = stream
+        session.offsetTimestamp[avType] = session.lastTimestamp[avType] - stream_ts[avType]
+        
+        if (avType == 'audio')
+          session.audio_stream = stream
+        
+        if (avType == 'video')
+          session.stream = stream
+          session.isWaitingForKeyFrame = true
+       
         session.stream_switched = true
-        console.log "switched stream", session.offsetTimestamp
+        console.log "switched stream", avType, session.offsetTimestamp[avType]
     
 
   on: (event, listener) ->

        console.log "metadata re-sent"

      for rtmpMessage in msgs
        session.lastTimestamp = rtmpMessage.timestamp = session.offsetTimestamp + session.getScaledTimestamp(rtmpMessage.originalTimestamp) % TIMESTAMP_ROUNDOFF 

      if msgs.length > 1
        buf = createRTMPAggregateMessage msgs, session.chunkSize

      consumeNextRTMPMessage()

class RTMPServer
  setBroadcastStream: (name, avType='video') ->
    console.log "setBroadcastStream", name
    broadcasted_stream = name
    stream = getStreamByName(name)
    stream_ts = { 'audio': 0, 'video': 0};
    for clientID, session of sessions
      if session.stream == stream
        stream_ts = session.lastTimestamp
