This commit is contained in:
yumoqing 2024-08-30 16:48:43 +08:00
parent ccefdc130a
commit 6fa7be2466

View File

@ -153,14 +153,14 @@ bricks.RTCClient = class extends bricks.VBox {
type:'login', type:'login',
info:this.info info:this.info
} }
this.socket.send(JSON.stringify(d)); this.socket_send(JSON.stringify(d));
} }
signaling_logout(){ signaling_logout(){
var d= { var d= {
type:'logout', type:'logout',
info:this.info info:this.info
} }
this.socket.send(JSON.stringify(d)); this.socket_send(JSON.stringify(d));
} }
// 获取本地媒体流 // 获取本地媒体流
async getLocalStream() { async getLocalStream() {
@ -183,13 +183,13 @@ bricks.RTCClient = class extends bricks.VBox {
} }
this.peer_info = peer_info; this.peer_info = peer_info;
this.role = 'requester'; this.role = 'requester';
this.socket.send(JSON.stringify(d)); this.socket_send(JSON.stringify(d));
} }
async send_offer(){ async send_offer(){
var offer = await this.pc.createOffer(); var offer = await this.pc.createOffer();
await this.pc.setLocalDescription(offer); await this.pc.setLocalDescription(offer);
console.log('########send_offer =', offer, this.pc.localDescription); console.log('########send_offer =', offer, this.pc.localDescription);
this.socket.send(JSON.stringify({ this.socket_send(JSON.stringify({
type:'offer', type:'offer',
offer:this.pc.localDescription, offer:this.pc.localDescription,
to:this.peer_info to:this.peer_info
@ -199,7 +199,7 @@ bricks.RTCClient = class extends bricks.VBox {
if (event.candidate) { if (event.candidate) {
var candidate = event.candidate; var candidate = event.candidate;
console.log('send_candidate(), candidate=', candidate); console.log('send_candidate(), candidate=', candidate);
this.socket.send(JSON.stringify({ this.socket_send(JSON.stringify({
type: 'iceCandidate', type: 'iceCandidate',
to:peer_info, to:peer_info,
candidate: candidate candidate: candidate
@ -220,7 +220,7 @@ bricks.RTCClient = class extends bricks.VBox {
this.peer_info = peer_info this.peer_info = peer_info
this.role = 'responser' this.role = 'responser'
await this.createPeerConnection(this.peer_info); await this.createPeerConnection(this.peer_info);
this.socket.send(JSON.stringify({ this.socket_send(JSON.stringify({
type: 'callAccepted', type: 'callAccepted',
to: peer_info to: peer_info
})); }));
@ -231,7 +231,7 @@ bricks.RTCClient = class extends bricks.VBox {
this.pc.ontrack = null; this.pc.ontrack = null;
this.pc.close(); this.pc.close();
if (! active){ if (! active){
this.socket.send(JSON.stringify({ this.socket_send(JSON.stringify({
type:'disconnect', type:'disconnect',
to:this.peer_info to:this.peer_info
})); }));
@ -251,11 +251,19 @@ bricks.RTCClient = class extends bricks.VBox {
this.peer_w.set_text(''); this.peer_w.set_text('');
} }
call_rejected(peer_info){ call_rejected(peer_info){
this.socket.send(JSON.stringify({ this.socket_send(JSON.stringify({
type: 'callRejected', type: 'callRejected',
to: peer_info to: peer_info
})); }));
} }
socket_send(s){
try {
this.socket.send(s);
} catch (e){
this.init_websocket();
this.socket.send(s);
}
}
async signaling_message_handle(event){ async signaling_message_handle(event){
var datapkg = JSON.parse(event.data); var datapkg = JSON.parse(event.data);
var d = datapkg.data; var d = datapkg.data;
@ -279,7 +287,7 @@ bricks.RTCClient = class extends bricks.VBox {
var answer = await this.pc.createAnswer(); var answer = await this.pc.createAnswer();
await this.pc.setLocalDescription(answer); await this.pc.setLocalDescription(answer);
console.log('###### send_answer=', answer, 'desc=', this.pc.localDescription); console.log('###### send_answer=', answer, 'desc=', this.pc.localDescription);
this.socket.send(JSON.stringify({ this.socket_send(JSON.stringify({
type:'answer', type:'answer',
answer:this.pc.localDescription, answer:this.pc.localDescription,
to:this.peer_info to:this.peer_info