362 lines
15 KiB
HTML
362 lines
15 KiB
HTML
<!-- Demo version: 2017.08.06 -->
|
|
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<meta charset="utf-8">
|
|
<link rel="stylesheet" href="https://cdn.webrtc-experiment.com/style.css">
|
|
|
|
<title>TextChat Translation using RTCMultiConnection</title>
|
|
|
|
<meta name="description" content="Many-to-Many TextChat Translation using RTCMultiConnection" />
|
|
<meta name="keywords" content="WebRTC,RTCMultiConnection,Demos,Experiments,Samples,Examples" />
|
|
|
|
<style>
|
|
video {
|
|
object-fit: fill;
|
|
width: 30%;
|
|
}
|
|
button,
|
|
input,
|
|
select {
|
|
font-weight: normal;
|
|
padding: 2px 4px;
|
|
text-decoration: none;
|
|
display: inline-block;
|
|
text-shadow: none;
|
|
font-size: 16px;
|
|
outline: none;
|
|
}
|
|
|
|
.make-center {
|
|
text-align: center;
|
|
padding: 5px 10px;
|
|
}
|
|
|
|
select {
|
|
height: 25px;
|
|
vertical-align: middle;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<article>
|
|
|
|
<header style="text-align: center;">
|
|
<h1>TextChat Translation using RTCMultiConnection</h1>
|
|
<p>
|
|
<a href="https://rtcmulticonnection.herokuapp.com/">HOME</a>
|
|
<span> © </span>
|
|
<a href="http://www.MuazKhan.com/" target="_blank">Muaz Khan</a> .
|
|
<a href="http://twitter.com/WebRTCWeb" target="_blank" title="Twitter profile for WebRTC Experiments">@WebRTCWeb</a> .
|
|
<a href="https://github.com/muaz-khan?tab=repositories" target="_blank" title="Github Profile">Github</a> .
|
|
<a href="https://github.com/muaz-khan/RTCMultiConnection/issues?state=open" target="_blank">Latest issues</a> .
|
|
<a href="https://github.com/muaz-khan/RTCMultiConnection/commits/master" target="_blank">What's New?</a>
|
|
</p>
|
|
</header>
|
|
|
|
|
|
<div class="github-stargazers"></div>
|
|
|
|
<section class="experiment">
|
|
<div class="make-center">
|
|
<input type="text" id="room-id" value="abcdef">
|
|
<button id="open-room">Open Room</button>
|
|
<button id="join-room">Join Room</button>
|
|
<button id="open-or-join-room">Auto Open Or Join Room</button>
|
|
|
|
<br><br>
|
|
<input type="text" id="input-text-chat" placeholder="Enter Text Chat" disabled>
|
|
|
|
<select id="select-your-langauge">
|
|
<option>en (English)</option>
|
|
<option>ar (العربية)</option>
|
|
<option>de (Deutsch)</option>
|
|
<option>fr (Français)</option>
|
|
<option>hi (हिंदी)</option>
|
|
<option>pt (Português)</option>
|
|
<option>ru (Русский)</option>
|
|
<option>es (Español)</option>
|
|
<option>tr (Türk)</option>
|
|
<option>nl (Nederlands)</option>
|
|
<option>it (Italiano)</option>
|
|
<option>pl (Polski)</option>
|
|
<option>ro (Român)</option>
|
|
<option>sv (Svensk)</option>
|
|
<option>vi (Việt)</option>
|
|
<option>th (ภาษาไทย)</option>
|
|
<option>zh-CN (中文简体)</option>
|
|
<option>zh-TW (中國傳統)</option>
|
|
<option>ko (한국의)</option>
|
|
<option>ja (日本人)</option>
|
|
<option>el (ελληνικά)</option>
|
|
<option>ts (தமிழ்)</option>
|
|
<option>hy (հայերեն)</option>
|
|
<option>bs (Bosanski)</option>
|
|
<option>ca (Català)</option>
|
|
<option>hr (Hrvatski)</option>
|
|
<option>dq (Dansk)</option>
|
|
<option>eo (Esperanto)</option>
|
|
<option>fi (Suomalainen)</option>
|
|
<option>ht (Haian kreyòl)</option>
|
|
<option>hu (Magyar)</option>
|
|
<option>is (Icelandic)</option>
|
|
<option>id (Indonesia)</option>
|
|
<option>la (Latinum)</option>
|
|
<option>lv (Latvijas)</option>
|
|
<option>mk (Македонски)</option>
|
|
<option>no (Norsk)</option>
|
|
<option>sr (Српски)</option>
|
|
<option>sk (Slovenský)</option>
|
|
<option>sw (Kiswahili)</option>
|
|
<option>cy (Cymraeg)</option>
|
|
</select>
|
|
|
|
<div id="room-urls" style="text-align: center;display: none;background: #F1EDED;margin: 15px -10px;border: 1px solid rgb(189, 189, 189);border-left: 0;border-right: 0;"></div>
|
|
</div>
|
|
|
|
<div id="chat-container">
|
|
<div class="chat-output"></div>
|
|
</div>
|
|
</section>
|
|
|
|
<script src="/include/videocall/dist/RTCMultiConnection.min.js"></script>
|
|
<script src="/include/videocall/demos/node_modules/webrtc-adapter/out/adapter.js"></script>
|
|
<script src="/include/videocall/demos/socket.io.js"></script>
|
|
|
|
<script src="/include/videocall/demos/node_modules/fbr/FileBufferReader.js"></script>
|
|
|
|
<script>
|
|
// ......................................................
|
|
// .......................UI Code........................
|
|
// ......................................................
|
|
|
|
document.getElementById('open-room').onclick = function() {
|
|
disableInputButtons();
|
|
connection.open(document.getElementById('room-id').value, function() {
|
|
showRoomURL(connection.sessionid);
|
|
});
|
|
};
|
|
|
|
document.getElementById('join-room').onclick = function() {
|
|
disableInputButtons();
|
|
connection.join(document.getElementById('room-id').value);
|
|
};
|
|
|
|
document.getElementById('open-or-join-room').onclick = function() {
|
|
disableInputButtons();
|
|
connection.openOrJoin(document.getElementById('room-id').value, function(isRoomExists, roomid) {
|
|
if(!isRoomExists) {
|
|
showRoomURL(roomid);
|
|
}
|
|
});
|
|
};
|
|
|
|
// ......................................................
|
|
// .....................TextChat Code....................
|
|
// ......................................................
|
|
|
|
document.getElementById('input-text-chat').onkeyup = function(e) {
|
|
if (e.keyCode != 13) return;
|
|
|
|
// removing trailing/leading whitespace
|
|
this.value = this.value.replace(/^\s+|\s+$/g, '');
|
|
if (!this.value.length) return;
|
|
|
|
connection.send(this.value);
|
|
appendDIV(this.value);
|
|
this.value = '';
|
|
};
|
|
|
|
var chatContainer = document.querySelector('.chat-output');
|
|
|
|
function appendDIV(event) {
|
|
console.log('appendDIV', event);
|
|
|
|
if(event.data) {
|
|
connection.Translator.TranslateText(event.data, function(convertedText) {
|
|
appendDIV(convertedText);
|
|
});
|
|
return;
|
|
}
|
|
|
|
var div = document.createElement('div');
|
|
div.innerHTML = event.data || event;
|
|
chatContainer.insertBefore(div, chatContainer.firstChild);
|
|
div.tabIndex = 0;
|
|
div.focus();
|
|
|
|
document.getElementById('input-text-chat').focus();
|
|
}
|
|
|
|
// ......................................................
|
|
// ..................RTCMultiConnection Code.............
|
|
// ......................................................
|
|
|
|
var connection = new RTCMultiConnection();
|
|
|
|
// by default, socket.io server is assumed to be deployed on your own URL
|
|
connection.socketURL = 'https://cs3198.mojohost.com:9001/';
|
|
|
|
// comment-out below line if you do not have your own socket.io server
|
|
// connection.socketURL = 'https://rtcmulticonnection.herokuapp.com:443/';
|
|
|
|
connection.socketMessageEvent = 'textchat-translation-demo';
|
|
|
|
connection.session = {
|
|
data: true
|
|
};
|
|
|
|
connection.sdpConstraints.mandatory = {
|
|
OfferToReceiveAudio: false,
|
|
OfferToReceiveVideo: false
|
|
};
|
|
|
|
connection.onmessage = appendDIV;
|
|
|
|
connection.onopen = function() {
|
|
document.getElementById('input-text-chat').disabled = false;
|
|
};
|
|
|
|
function disableInputButtons() {
|
|
document.getElementById('open-or-join-room').disabled = true;
|
|
document.getElementById('open-room').disabled = true;
|
|
document.getElementById('join-room').disabled = true;
|
|
document.getElementById('room-id').disabled = true;
|
|
}
|
|
|
|
// ......................................................
|
|
// ......................Handling Room-ID................
|
|
// ......................................................
|
|
|
|
function showRoomURL(roomid) {
|
|
var roomHashURL = '#' + roomid;
|
|
var roomQueryStringURL = '?roomid=' + roomid;
|
|
|
|
var html = '<h2>Unique URL for your room:</h2><br>';
|
|
|
|
html += 'Hash URL: <a href="' + roomHashURL + '" target="_blank">' + roomHashURL + '</a>';
|
|
html += '<br>';
|
|
html += 'QueryString URL: <a href="' + roomQueryStringURL + '" target="_blank">' + roomQueryStringURL + '</a>';
|
|
|
|
var roomURLsDiv = document.getElementById('room-urls');
|
|
roomURLsDiv.innerHTML = html;
|
|
|
|
roomURLsDiv.style.display = 'block';
|
|
}
|
|
|
|
(function() {
|
|
var params = {},
|
|
r = /([^&=]+)=?([^&]*)/g;
|
|
|
|
function d(s) {
|
|
return decodeURIComponent(s.replace(/\+/g, ' '));
|
|
}
|
|
var match, search = window.location.search;
|
|
while (match = r.exec(search.substring(1)))
|
|
params[d(match[1])] = d(match[2]);
|
|
window.params = params;
|
|
})();
|
|
|
|
var roomid = '';
|
|
if (localStorage.getItem(connection.socketMessageEvent)) {
|
|
roomid = localStorage.getItem(connection.socketMessageEvent);
|
|
} else {
|
|
roomid = connection.token();
|
|
}
|
|
document.getElementById('room-id').value = roomid;
|
|
document.getElementById('room-id').onkeyup = function() {
|
|
localStorage.setItem(connection.socketMessageEvent, this.value);
|
|
};
|
|
|
|
var hashString = location.hash.replace('#', '');
|
|
if(hashString.length && hashString.indexOf('comment-') == 0) {
|
|
hashString = '';
|
|
}
|
|
|
|
var roomid = params.roomid;
|
|
if(!roomid && hashString.length) {
|
|
roomid = hashString;
|
|
}
|
|
|
|
if(roomid && roomid.length) {
|
|
document.getElementById('room-id').value = roomid;
|
|
localStorage.setItem(connection.socketMessageEvent, roomid);
|
|
|
|
// auto-join-room
|
|
(function reCheckRoomPresence() {
|
|
connection.checkPresence(roomid, function(isRoomExists) {
|
|
if(isRoomExists) {
|
|
connection.join(roomid);
|
|
return;
|
|
}
|
|
|
|
setTimeout(reCheckRoomPresence, 5000);
|
|
});
|
|
})();
|
|
|
|
disableInputButtons();
|
|
}
|
|
|
|
// Translation Handler
|
|
connection.googKey = 'AIzaSyCgB5hmFY74WYB-EoWkhr9cAGr6TiTHrEE';
|
|
connection.autoTranslateText = false;
|
|
|
|
var selectYourLanguage = document.getElementById('select-your-langauge');
|
|
connection.language = selectYourLanguage.value.split(' (')[0];
|
|
selectYourLanguage.onchange = function() {
|
|
connection.language = this.value.split(' (')[0];
|
|
};
|
|
|
|
connection.Translator.getListOfLanguages(function(languages) {
|
|
selectYourLanguage.innerHTML = '';
|
|
languages.forEach(function(language) {
|
|
var option = document.createElement('option');
|
|
option.innerHTMl = language.language;
|
|
selectYourLanguage.appendChild(option);
|
|
});
|
|
});
|
|
</script>
|
|
|
|
<section class="experiment own-widgets latest-commits">
|
|
<h2 class="header" id="updates" style="color: red;padding-bottom: .1em;"><a href="https://github.com/muaz-khan/RTCMultiConnection/commits/master">Latest Updates</a></h2>
|
|
<div id="github-commits"></div>
|
|
</section>
|
|
|
|
<section class="experiment own-widgets">
|
|
<h2 class="header" id="updates" style="color: red;padding-bottom: .1em;"><a href="https://github.com/muaz-khan/RTCMultiConnection/issues">Latest Issues</a></h2>
|
|
<div id="github-issues"></div>
|
|
</section>
|
|
|
|
<section class="experiment">
|
|
<h2 class="header" id="feedback">Feedback</h2>
|
|
<div>
|
|
<textarea id="message" style="height: 8em; margin: .2em; width: 98%; border: 1px solid rgb(189, 189, 189); outline: none; resize: vertical;" placeholder="Have any message? Suggestions or something went wrong?"></textarea>
|
|
</div>
|
|
<button id="send-message" style="font-size: 1em;">Send Message</button><small style="margin-left:1em;">Enter your email too; if you want "direct" reply!</small>
|
|
</section>
|
|
|
|
<a href="https://github.com/muaz-khan/RTCMultiConnection" class="fork-left"></a>
|
|
|
|
<script>
|
|
window.useThisGithubPath = 'muaz-khan/RTCMultiConnection';
|
|
</script>
|
|
<script src="https://cdn.webrtc-experiment.com/commits.js" async></script>
|
|
|
|
</article>
|
|
|
|
<footer>
|
|
<p>
|
|
<a href="https://www.webrtc-experiment.com">WebRTC Experiments</a> © <a href="https://plus.google.com/+MuazKhan" rel="author" target="_blank">Muaz Khan</a>
|
|
<a href="mailto:muazkh@gmail.com" target="_blank">muazkh@gmail.com</a>
|
|
<a href="https://github.com/muaz-khan" target="_blank">Github</a>
|
|
</p>
|
|
</footer>
|
|
|
|
</body>
|
|
|
|
</html>
|