streamCreated not fired for existing participants

I’m not receiving a streamCreated event for participants already connected so only older participants can see newer ones and not vice versa. I’m on versions 2.12.0 both on browser and server.

Has anyone experienced similar? Any workarounds?

My react code below

handleJoin = () => {
// this will render the divs and then connect video to those divs
this.setState({ joined: true }, () => {
  this.connectVideo()
})
  }

  connectVideo = () => {
this.OV = new OpenVidu();
this.OV_session = this.OV.initSession();

axios.post(`/rooms/${this.props.currentRoom.id}/video_token`).then(response => {
  const { token } = response.data

  this.OV_session.on('connectionCreated', event => {
    console.log('found connection', { event })
  })

  this.OV_session.connect(token)
  .then(() => {
    console.log('success')
    this.startStreams()
    this.startPublish()
  })
  .catch((error) => {
    console.log('Error connecting to OpenVidu session', { error })
  })
})
  }

  startPublish = () => {
this.OV_publisher = this.OV.initPublisher(
  undefined,
  {
    audioSource: undefined, // The source of audio. If undefined default audio input
    videoSource: undefined, // The source of video. If undefined default video input
    publishAudio: true,     // Whether you want to start the publishing with audio unmuted or muted
    publishVideo: true,     // Whether you want to start the publishing with video enabled or disabled
    resolution: '640x480',  // The resolution of your video
    frameRate: 30,          // The frame rate of your video
    insertMode: 'APPEND',   // How the video will be inserted according to targetElement
    mirror: false           // Whether to mirror your local video or not
  },
  (error) => {                // Function to be executed when the method finishes
    if (error) {
      console.error('Error while initializing publisher: ', error);
    } else {
      console.log('Publisher successfully initialized');
    }
  }
);

this.OV_session.publish(this.OV_publisher)
this.OV_publisher.addVideoElement(this.publisherRef);
  }

  startStreams = () => {
this.OV_session.on('streamCreated', event => {
  console.log('streamCreated', { event })
  this.OV_session.subscribe(event.stream, 'remote-streams-v2', {insertMode: 'APPEND'});
});
  }
1 Like

Hi,

Be careful. You must set streamCreated event before calling Session.connect, just as you do with connectionCreated event. That’s why new users are not receiveing old user’s streams: the streamCreated event is being fired before you add the event listener.

Session.connect documentation explains all of this: https://docs.openvidu.io/en/latest/api/openvidu-browser/classes/session.html#connect

1 Like

this url is not currect , can you write currect url ???
thanks

Hello @pabloFuente. I didn’t find any info about the order of events handling in the connect docs. Also faced this issue in openvidu-browser 2.19
Is the same for session.streamDestroyed?
Could you add this detail in the docs? I think it’s important