# openvidu-insecure-js This is the simplest demo you can try to get started with OpenVidu. It has the minimum set of features to make a video-call. You will only need a few minutes to get your first application working. ## Understanding this example
element for the user's nickname just below its video appendUserData(event.element, subscriber.stream.connection); }); }); // On every Stream destroyed... session.on('streamDestroyed', function (event) { // Delete the HTML element with the user's nickname. HTML videos are automatically removed from DOM removeUserData(event.stream.connection); }); ``` Here we subscribe to the events that interest us. In this case, we want to receive all videos published to the video-call, as well as displaying every user's nickname nex to its video. To achieve this: - `streamCreated`: for each new Stream received by OpenVidu, we immediately subscribe to it so we can see its video. A new HTML video element will be appended to element with id 'subscriber'. - `videoElementCreated`: event triggered by Subscriber object (returned by the previous `Session.subscribe` method). This allows us to add the participant nickname to the new video previously added in `streamCreated` event. Auxiliary method `appendUserData` is responsible for appending a new paragraph element just below the `event.element` video, containing `subscriber.stream.connection.data` field (which has the user's nickname). - `streamDestroyed`: for each Stream that has been destroyed (which means a user has left the video-call), we remove the paragraph element with the user's nickname that we added in the previous event (`appendUserData` method created the element with an _id_ containing `event.stream.connection.connectionId` unique value, so we can now identify the right element to be removed). The video element is automatically deleted by default, so we don't need to do anything else. - Finally connect to the session and publish your webcam: ```javascript // --- 3) Connect to the session --- // 'token' param irrelevant when using insecure version of OpenVidu. Second param will be received by every user // in Stream.connection.data property, which will be appended to DOM as the user's nickname session.connect(token, '{"clientData": "' + token + '"}', function (error) { // If the connection is successful, initialize a publisher and publish to the session if (!error) { // --- 4) Get your own camera stream with the desired resolution --- // Both audio and video will be active. HTML video element will be appended to element with 'publisher' id var publisher = OV.initPublisher('publisher', { audio: true, video: true, quality: 'MEDIUM' }); // --- 5) Publish your stream --- session.publish(publisher); } else { console.log('There was an error connecting to the session:', error.code, error.message); } }); ``` `token` param is irrelevant when using insecure version of OpenVidu. Remember `videoElementCreated` event, when we added the user's nickname to the HTML? Well, second parameter is the actual value you will receive in `Stream.connection.data` property. So in this case it is a JSON formatted string with a "clientData" tag with "token" value, which is retrieved from HTML input `` (filled by the user). In the callback of `Session.connect` method, we check the connection has been succesful (`error` value must be _null_) and right after that we get a `Publisher` object with both audio and video activated and MEDIUM quality. This process will end with the addition of a new HTML video element showing your camera, as a child of element with _id_ 'publisher'. We then just have to publish this object through `Session.publish` method, and the rest of users will begin receiving our webcam.