Janus源码分析(5)——echotest分析

1、运行效果图

Echo测试演示的是发送给服务器网关的音频和视频,服务器会回传给你,效果如下图所示:
在这里插入图片描述

2、代码分析

2.1 代码结构

在这里插入图片描述

2.2 源码分析

2.2.1 创建线程

在janus = new Janus()时,调用Janus(gatewayCallbacks)在其中有函数createSession,并且传入下面的回调函数:
在这里插入图片描述

createSession创建请求,成功建立一次httpAPICall,输出Created handle: 1747107217737787

Janus.httpAPICall(server, {
   
   
    verb: 'POST',
    withCredentials: withCredentials,
    body: request,
    success: function(json) {
   
   
    Janus.debug(json);
    if(json["janus"] !== "success") {
   
   
        Janus.error("Ooops: " + json["error"].code + " " + json["error"].reason);   // FIXME
        callbacks.error(json["error"].reason);
        return;
    }
    Janus.sessions[sessionId] = that;
    eventHandler();
    callbacks.success();
},

成功回调eventHandler以及echoest的sucesss

2.2.2 创建插件

echoest的sucesss函数如下:
定义了插值对象及对应的回调函数。

janus.attach(
{
   
   
   ......
}
this.attach = function(callbacks) {
   
    createHandle(callbacks)}

实际调用createHandle,并把对应的回调plugin,succecss等传入,如下图。
在这里插入图片描述

在函数function createHandle(callbacks) 中,定义了插件的各个函数,并且回调echotest.js中的janus.attach中的success函数,并且输出Plugin attached! (janus.plugin.echotest, id=1747107217737787),其函数的主要作用是传入对应的回调函数,并且定义一个插件及其许多许应的函数,并且与服务器进行通信:

pluginHandles[handleId] = pluginHandle;
callbacks.success(pluginHandle);

echotest = pluginHandle;定义为插件,其中定义许多函数。包括:

var pluginHandle =
{
   
   
        session : that,
        plugin : plugin,
        id : handleId,
        token : handleToken,
        detached : false,
        webrtcStuff : {
   
   }
        getId : function() {
   
    return handleId; },
        getPlugin : function() {
   
    return plugin; }
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值