视讯通话疑难排解

时间:2019-05-07 06:31:10

标签: webrtc asterisk sipjs

用星号服务器配置sip.js时遇到问题。 当我从一台计算机到另一台计算机进行视频通话时,无论环境如何,我的声音只会传到一侧。并且视频不传输,只有1个停止帧。我不是星号或sip.js方面的专家,但是我按照说明进行了所有操作,而且我不明白可能是什么问题?

这是我的pjsip.conf文件:

[transport-wss-nat]
type=transport
protocol=wss
bind=0.0.0.0
local_net=192.168.0.1/24
domain=example.com
external_media_address=example.com
external_signaling_address=example.com

[manager-aor](!)
type=aor
max_contacts=1
remove_existing=yes

[videomanager-endpoint](!)
type=endpoint
transport=transport-wss-nat
dtls_auto_generate_cert=yes
webrtc=yes
context=call-out
disallow=all
allow=h264,opus,ulaw
tos_video=af41
;cos_video=4

[100](manager-aor)
[100]
type=auth
auth_type=userpass
username=100
password=secret
[100](videomanager-endpoint)
aors=100
auth=100

[101](manager-aor)
[101]
type=auth
auth_type=userpass
username=101
password=secret
[101](videomanager-endpoint)
aors=101
auth=101

简单的js脚本:

let userAgent   = null;
let session     = null;
const host      = 'example.com';


function registerAgent(login, password) {
    userAgent = new SIP.UA({
        uri: login + '@' + host,
        transportOptions: {
            wsServers: ['wss://' + host + ':8089/ws']
        },
        log: {
            builtinEnabled: false
        },
        authorizationUser: login,
        password: password
    });
    userAgent.on('invite', function (invite) {
        console.log('Invite call');
        session = invite;
    })
}

function makeCall(number) {
    session = userAgent.invite(number + '@' + host);
    attachMedia();
}

function receiveCall() {
    session.accept();
    attachMedia();
}

function attachMedia() {
    let remoteVideo = document.getElementById('remote_video');
    let remoteStream = null;
    let localVideo = document.getElementById('local_video');

    session.on('SessionDescriptionHandler-created', function (sdh) {
        sdh.on('userMedia', function (stream) {
            localVideo.srcObject = new MediaStream(stream);
            localVideo.play();
        });
    });

    session.on('trackAdded', function() {
        // We need to check the peer connection to determine which track was added
        let pc = session.sessionDescriptionHandler.peerConnection;

        // Gets remote tracks
        let receivers = pc.getReceivers();
        if (receivers.length && null === remoteStream) { // If we don't have receivers, don't do anything
            remoteStream = new MediaStream();
            receivers.forEach(function (receiver) {
                if (null !== receiver.track) {
                    remoteStream.addTrack(receiver.track);
                }
            });
            remoteVideo.srcObject = remoteStream;
            remoteVideo.play();
        }
    });
}

function endCall() {
    if (null !== session) {
        session.terminate();
    }

    session = null;
}

0 个答案:

没有答案