纯前端集成视频会议和聊天室

本文介绍了如何使用环信平台进行服务搭建,包括在环信控制台创建应用和IM用户,创建聊天室,并获取必要的AppKey和聊天室ID。接着,文章将展示如何在前端引用SDK来实现视频会议和聊天室的功能。
摘要由CSDN通过智能技术生成

准备:利用环信平台搭建服务

进入 https://console.easemob.com/user/login,创建自己的应用和IM用户,并创建聊天室

复制自己的应用AppKey,以及聊天室id

引用sdk

 <script src="./WebIMConfig.js"></script>
    <script src="./sdk/websdk3.1.4.js"></script>
    <script src="./sdk/EMedia_x1v1.js"></script>
    <script src="./sdk/EMedia_sdk-dev.js"></script>
var conn = {};
console.log(WebIM, window.WebIM);
WebIM.config = config;  // 这里一定要配置自己的聊天室id和群组id,后面会取
WebIM.Emoji=config.emoji;
conn = WebIM.conn = new WebIM.connection({
    appKey: WebIM.config.appkey,
    isHttpDNS: WebIM.config.isHttpDNS,
    isMultiLoginSessions: WebIM.config.isMultiLoginSessions,
    host: WebIM.config.Host,
    https: WebIM.config.https,
    url: WebIM.config.xmppURL,
    apiUrl: WebIM.config.apiURL,
    isAutoLogin: false,
    heartBeatWait: WebIM.config.heartBeatWait,
    autoReconnectNumMax: WebIM.config.autoReconnectNumMax,
    autoReconnectInterval: WebIM.config.autoReconnectInterval,
    isStropheLog: WebIM.config.isStropheLog,
    delivery: WebIM.config.delivery
});

conn.listen({
    onOpened: function (message) {          //连接成功回调
        var myDate = new Date().toLocaleString();
        console.log("%c [opened] 连接已成功建立", "color: green");
        console.log(myDate);
        // rek();
        console.log(myDate + "登陆成功");
        $("#user_main").html(host_user);
        joinRoom(cType);
    },
    onClosed: function (message) {
        layerOpen("登录异常!")
        console.log("onclose:" + message);
        console.log(message);
    },         //连接关闭回调
    onTextMessage: function (message) {
        console.log('onTextMessage: ', message);
        if(message.type==="chatroom" &&message.to===WebIM.config.roomId){   //
            insertChatMessageDOM(message.sourceMsg,message.from,false);
        }
        if (message.ext.conferenceId != undefined) {
            emedia.mgr.exitConference();
            var truthBeTold = window.confirm((message.from + "邀请您加入会议"));
            if (truthBeTold) {
            setTimeout(function () {
                    emedia.mgr.joinConference(message.ext.conferenceId, message.ext.password, "进入会议").then(function () {
                        console.log("********加入会议成功*******");
                  /*    $("#cofferId").html(message.ext.conferenceId);
                      $("#cofferIdPass").html(message.ext.password);*/

                        let videoId ="video_main";
                        var videoCreate = document.getElementById(videoId);
                        var constaints = { audio: true, video: true };
                        emedia.mgr
                            .publish(constaints, videoCreate, "加入会议成功后 发布视频流")
                            .then(function (pushedStream) {
                                //stream 对象
                            })
                            .catch(function (error) {
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值