Tutorial step 4:
Step 4: Who am I?
Each webRTC client is identified by a user name, wrtc.addressName. If you do not set any user name the default value is guest_ followed by a random number, but then it is difficult to see who is who. You need to set your user name.
If your user name contains a @ it is considered to be a SIP address. If you then provide a password wrtc_kit will attempt to log you in on that SIP server.
We add fields there the user can enter her username and an optional password for authentication:
<!DOCTYPE html>
<html><head>
<script type="module">
import { wrtcObject} from "/luci-static/resources/wrtc_kit_m.js";
const wrtc = new wrtcObject(function() {
this.wsServer = "50.11.69.17";
});
function ChangeName() {
wrtc.changeCredentials({addressName: document.getElementById('myname').value,
sipPassword: document.getElementById('mypwd').value});
};
document.getElementById('okbtn').addEventListener('click', ChangeName);
</script>
</head><body>
<div>
Name:<input type="text" id="myname"><br/>
Pwd :<input type="password" id="mypwd"><br/>
<button id="okbtn">OK</button><br/>
</div>
<video id="localVideo" width="200px" autoplay="autoplay" muted="true"></video>
<video id="remoteVideo" width="300px" autoplay="autoplay"></video>
</body></html>
I'm sure you will create much nicer login fields on your web page, but for this simple example this is adequate. Users can now enter their name, and if needed SIP password to log in to a SIP account. wrtc_kit will then take care of the SIP authentication. If your user name contains a @ it is considered to be a SIP address and the IXNX server will contact the SIP server of the domain after the @ character and attempt to log you in using digest authentication. Read more about SIP authentication here.
As you can see we are using wrtc.changeCredentials() to set our user name and SIP password. You can provide more data to it, such as display name etc, read more here.