This is my echo test, it works perfectly.
On this Janus server we run multiple applications, implementing several different plugins, so I know the server is set up correctly.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>My Echo Test</title>
<link rel="icon" href="data:;base64,iVBORwOKGO=" />
<style>
video {width:320px; height:240px;}
</style>
</head>
<body>
<p><a href=".">back</a></p>
<button id="goButton">go</button>
<video id="localVideo" muted autoplay playsinline></video>
<video id="remoteVideo" muted autoplay playsinline></video>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/webrtc-adapter/8.2.2/adapter.min.js" ></script>
<script type="text/javascript" src="janus.js" ></script>
<script type="text/javascript">
'use strict';
const goButton = document.getElementById('goButton');
const localVideo = document.getElementById('localVideo');
const remoteVideo = document.getElementById('remoteVideo');
var janus;
var echoTest;
const localStream = new MediaStream();
const remoteStream = new MediaStream();
goButton.addEventListener('click', function(event){
Janus.init({
debug: true,
callback: () => janusOnInit(),
});
});
function janusOnInit() {
if(!Janus.isWebrtcSupported()) {
alert("No WebRTC support... ");
return;
}
janus = new Janus({
server: "wss://MYJANUSSERVER",
iceServers: [{urls: "turn:MYTURNSERVER"}],
apisecret: "MYAPISECRET",
success: () => janusOnSuccess(),
error: function(error) {
alert(error);
janus.destroy();
},
destroyed: function() {}
});
}
function janusOnSuccess() {
console.log('janus server connected');
janus.attach({
plugin: 'janus.plugin.echotest',
success: (pluginHandle) => echoTestOnSuccess(pluginHandle),
error: function(error) {
Janus.error(error);
alert(error);
janus.destroy();
},
onmessage: (message, jsep) => echoTestOnMessage(message, jsep),
onlocaltrack: (track, on) => echoTestOnLocalTrack(track, on),
onremotetrack: (track, mid, on, metadata) => echoTestOnRemoteTrack(track, mid, on, metadata)
});
}
function echoTestOnSuccess(pluginHandle) {
console.log('plugin attached');
echoTest = pluginHandle;
let body = { audio: true, video: true };
echoTest.send({ message: body });
echoTest.createOffer({
tracks: [
{ type: 'audio', capture: true, recv: true },
{ type: 'video', capture: true, recv: true },
{ type: 'data' },
],
success: function(jsep) {
echoTest.send({ message: body, jsep: jsep });
},
error: function(error) {
alert("WebRTC error... " + error.message);
}
});
}
function echoTestOnMessage(message, jsep){
if(jsep) {
echoTest.handleRemoteJsep({ jsep: jsep });
}
}
function echoTestOnLocalTrack(track, on) {
console.log("Local track " + (on ? "added" : "removed") + ":", track);
if (on) {
localStream.addTrack(track);
localVideo.srcObject = localStream;
}
}
function echoTestOnRemoteTrack(track, mid, on, metadata) {
console.log("Remote track " + (on ? "added" : "removed") + ":", track);
if (on) {
remoteStream.addTrack(track);
remoteVideo.srcObject = remoteStream;
}
}
</script>
</body>
</html>