display: flex;
}
.text_chat textarea{
width: 350px;
height: 350px;
}
.send{
margin-top: 20px;
}
Connect Sig Server
Leave
Local:
Remote:
Chat:
Send
- js
‘use strict’
var localVideo = document.querySelector(‘video#localvideo’);
var remoteVideo = document.querySelector(‘video#remotevideo’);
var btnConn = document.querySelector(‘button#connserver’);
var btnLeave = document.querySelector(‘button#leave’);
// 文本聊天
var chat = document.querySelector(‘textarea#chat’);
var send_txt = document.querySelector(‘textarea#sendtext’);
var btnSend = document.querySelector(‘button#send’);
var localStream = null;
var roomid = ‘555555’;
var socket =null;
var state = ‘init’;
var pc = null;
var dc = null;
var pcConfig={
‘iceServers’:[{
‘urls’:‘turn:121.41.76.43:3478’,
‘credential’:‘123456’,
‘username’:‘huang’
}]
}
function sendMessage(roomid,data){
if(socket){
socket.emit(‘message’,roomid,data);
}
}
function getAnswer(desc){
pc.setLocalDescription(desc);
sendMessage(roomid,desc);
}
function handleAnswerError(err){
console.error(‘Failed to get Answer!’,err);
}
function getOffer(desc){
pc.setLocalDescription(desc);
sendMessage(roomid,desc)
}
function handleOfferError(err){
console.error(‘Failed to get Offer!’,err);
}
//接收远端流通道
function call(){
if(state === ‘joined_conn’){
if(pc){
var options = {
offerToReceiveAudio:1,
offerToReceiveVideo:1
}
pc.createOffer(options)
.then(getOffer)
.catch(handleOfferError);