# janus 安装

  1. 安装docker
  2. docker load -i /janus/my_janus.tar # my_janus.tar下载地址 (opens new window)
  3. docker images
  4. docker run -d -p 7088:7088 -p 7089:7089 -p 8088:8088 -p 8089:8089 -p 8188:8188 -p 8189:8189 --restart=always my_janus
  5. docker ps -al
  6. docker start container_id //container_id 见下图

端口 Port Description

  1. 8088 RESTful API
  2. 8188 WebSocket API
  3. 8089 Restful on SSL
  4. 8189 Websocket on SSL
  5. 7088 RESTful Admin API
  6. 7188 Admin API on SSL

连接示例 需要下载2个js

  1. Janus.js (opens new window)
  2. adapter.min.js (opens new window)
 Janus.init();
        const janus = new Janus({
            server: "http://81.71.4.244:8088/janus",
            success: function(e) {
                janus.attach({
                    plugin: "janus.plugin.videocall",
                    opaqueId: 'o665p2sdo', // 初始化用户名
                    /*初始化成功设置用户名*/
                    success: function(pluginHandle) {
                       
                    },
                    // 监听接收信息
                    onmessage: function(msg, jsep) {
                        th.onmessage(msg, jsep)
                    },
                    // 显示本地流
                    onlocalstream: function(stream) {
                        Janus.attachMediaStream(th.$refs.myvideo, stream)
                        th.$refs.myvideo.play()
                    },
                    // 远程流
                    onremotestream: function(stream) {
                        const videoTracks = stream.getVideoTracks();
                        if (videoTracks === null || videoTracks === undefined || videoTracks.length === 0) {
                            th.pluginHandle.send({
                                "message": {
                                    "request": "set",
                                    "audio": true
                                }
                            });
                            console.log('对方没有视频头');
                        }
                        Janus.attachMediaStream(th.$refs.friendvideo, stream)
                        th.$refs.friendvideo.play()
                    },
                    // 关闭的回调
                    oncleanup: function() {

                    },
                })
            },
            error: function(e) {
                console.log(e);
                console.log('error');
            },
            destroyed: function() {
                console.log('destroyed');
            }
        })
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49