GB28181流媒体服务搭建:https://www.liveqing.com/docs/download/LiveGBS.html
代码示例
在vue中,利用websocket进行高性能的GB28181语音对讲前端代码
......
talkStart(e) {
if(!this.ws) {
var ws = new WebSocket(this.wsTalkURL());
ws.onopen = evt => {
console.log("ws talk open");
this.ws = ws;
}
ws.onclose = evt => {
console.log("ws talk close");
}
ws.onerror = evt => {
console.log("ws talk error", evt);
}
}
var $target = $(e.currentTarget);
if(this.recorder) {
$target.addClass("active");
this.recorder.start();
return;
}
LiveRecorder.get((rec, err) => {
if(err) {
alert(err);
return
}
// this.$refs["player"].setMuted(true);
$target.addClass("active");
this.recorder = rec;
this.recorder.start();
}, {
sampleBits: 16,
sampleRate: 8000,
pcmCallback: pcm => {
// binary to base64 string
var reader = new window.FileReader();
reader.onloadend = () => {
var base64 = reader.result;
var base64 = base64.split(',')[1];
if(this.ws) {
this.ws.send(base64);
}
}
reader.readAsDataURL(pcm);
}
})
},
talkStop() {
if(this.recorder) {
this.recorder.stop();
// this.recorder = null;
$(this.$el).find(".fa-microphone.active").removeClass("active");
// this.$refs["player"].setMuted(false);
}
if(this.ws) {
this.ws.close();
this.ws = null;
}
},
......