张跃

初版

No preview for this file type
1 +/scripts
...\ No newline at end of file ...\ No newline at end of file
1 +module.exports = {
2 + 'env': {
3 + 'browser': true,
4 + 'es6': true,
5 + 'node': true,
6 + 'jquery': true,
7 + },
8 + 'extends': 'eslint:recommended',
9 + 'globals': {
10 + 'Atomics': 'readonly',
11 + 'SharedArrayBuffer': 'readonly',
12 + 'AgoraRTC': 'readonly',
13 + 'AgoraRTS': 'readonly',
14 + },
15 + 'parserOptions': {
16 + 'ecmaVersion': 2018,
17 + 'sourceType': 'module'
18 + },
19 + 'rules': {
20 + 'indent': [
21 + 'warn',
22 + 2
23 + ],
24 + 'linebreak-style': [
25 + 'warn',
26 + 'unix'
27 + ],
28 +
29 + 'no-unused-vars': 0,
30 + }
31 +}
...\ No newline at end of file ...\ No newline at end of file
1 +build
2 +dist
3 +package-lock.json
4 +node_modules
1 +# 默认忽略的文件
2 +/shelf/
3 +/workspace.xml
4 +# 基于编辑器的 HTTP 客户端请求
5 +/httpRequests/
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<module type="WEB_MODULE" version="4">
3 + <component name="NewModuleRootManager">
4 + <content url="file://$MODULE_DIR$">
5 + <excludeFolder url="file://$MODULE_DIR$/temp" />
6 + <excludeFolder url="file://$MODULE_DIR$/.tmp" />
7 + <excludeFolder url="file://$MODULE_DIR$/tmp" />
8 + </content>
9 + <orderEntry type="inheritedJdk" />
10 + <orderEntry type="sourceFolder" forTests="false" />
11 + </component>
12 +</module>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="ProjectDictionaryState">
4 + <dictionary name="zhangyue" />
5 + </component>
6 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +<component name="InspectionProjectProfileManager">
2 + <profile version="1.0">
3 + <option name="myName" value="Project Default" />
4 + <inspection_tool class="Eslint" enabled="true" level="WARNING" enabled_by_default="true" />
5 + </profile>
6 +</component>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="ProjectModuleManager">
4 + <modules>
5 + <module fileurl="file://$PROJECT_DIR$/.idea/Agora-Web-RTS-Tutorial-1to1-Webpack.iml" filepath="$PROJECT_DIR$/.idea/Agora-Web-RTS-Tutorial-1to1-Webpack.iml" />
6 + </modules>
7 + </component>
8 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +<?xml version="1.0" encoding="UTF-8"?>
2 +<project version="4">
3 + <component name="VcsDirectoryMappings">
4 + <mapping directory="$PROJECT_DIR$" vcs="Git" />
5 + </component>
6 +</project>
...\ No newline at end of file ...\ No newline at end of file
1 +# Web Tutorial For Webpack - 1to1
2 +
3 +*English | [中文](README.zh.md)*
4 +
5 +This tutorial shows you how to quickly create an basic video communication using the Agora sample app.
6 +
7 +## Prerequisites
8 +
9 +- nodejs LTS
10 +- A web browser
11 +
12 +## Quick Start
13 +
14 +This section shows you how to prepare, and run the sample application.
15 +
16 +### Obtain an App ID
17 +
18 +To build and run the sample application, get an App ID:
19 +1. Create a developer account at [agora.io](https://dashboard.agora.io/signin/). Once you finish the signup process, you will be redirected to the Dashboard.
20 +2. Navigate in the Dashboard tree on the left to **Projects** > **Project List**.
21 +3. Save the **App ID** from the Dashboard for later use.
22 +4. Generate a temp **Access Token** (valid for 24 hours) from dashboard page with given channel name, save for later use.
23 +
24 +> To ensure communication security, Agora uses tokens (dynamic keys) to authenticate users joining a channel.
25 +>
26 +> Temporary tokens are for demonstration and testing purposes only and remain valid for 24 hours. In a production environment, you need to deploy your own server for generating tokens. See [Generate a Token](https://docs.agora.io/en/Interactive Broadcast/token_server)for details.
27 +
28 +### Install dependencies and integrate the Agora Video SDK
29 +
30 +1. Using the Terminal app, enter the `install` command in your project directory. This command installs libraries that are required to run the sample application.
31 + ``` bash
32 + # install dependencies
33 + npm install
34 + ```
35 +2. Please download from [agora.io](https://docs.agora.io/en/) **AgoraRTC.js**, **AgoraRTS.js**, **AgoraRTS.asm**, **AgoraRTS.wasm** to `static` folder.
36 +3. Start the application by entering the `run dev` or `run build` command.
37 + The `run dev` command is for development purposes.
38 + ``` bash
39 + # serve with hot reload at localhost:8080
40 + npm run dev
41 + ```
42 + The `run build` command is for production purposes and minifies code.
43 + ``` bash
44 + # build for production with minification
45 + npm run build
46 + ```
47 +4. Your default browser should open and display the sample application, as shown here.
48 + **Note:** In some cases, you may need to open a browser and enter `http://localhost:8080` as the URL.
49 +
50 +## Contact Us
51 +
52 +- For potential issues, take a look at our [FAQ](https://docs.agora.io/en/faq) first
53 +- Dive into [Agora SDK Samples](https://github.com/AgoraIO) to see more tutorials
54 +- Take a look at [Agora Use Case](https://github.com/AgoraIO-usecase) for more complicated real use case
55 +- Repositories managed by developer communities can be found at [Agora Community](https://github.com/AgoraIO-Community)
56 +- You can find full API documentation at [Document Center](https://docs.agora.io/en/)
57 +- If you encounter problems during integration, you can ask question in [Stack Overflow](https://stackoverflow.com/questions/tagged/agora.io)
58 +- You can file bugs about this sample at [issue](https://github.com/AgoraIO/Basic-Video-Call/issues)
59 +
60 +## License
61 +
62 +The MIT License (MIT)
1 +Meta:
2 + name: Web RTS Tutorial For Webpack - 1to1
3 + lang: en
4 + description: |
5 + This tutorial shows you how to quickly create an basic video communication using the Agora sample app.
6 +Prerequisites:
7 + - nodejs LTS
8 + - A web browser
9 +
10 +QuickStart:
11 + description:
12 + This section shows you how to prepare, and run the sample application.
13 + sections:
14 + - title: Obtain an App ID
15 + content: |
16 + $_{APPID}
17 + - title: Install dependencies and integrate the Agora Video SDK
18 + content: |
19 + 1. Using the Terminal app, enter the `install` command in your project directory. This command installs libraries that are required to run the sample application.
20 + ``` bash
21 + # install dependencies
22 + npm install
23 + ```
24 + 2. Please download from [agora.io](https://docs.agora.io/en/) **AgoraRTC.js**, **AgoraRTS.js**, **AgoraRTS.asm**, **AgoraRTS.wasm** to `static` folder.
25 + 3. Start the application by entering the `run dev` or `run build` command.
26 + The `run dev` command is for development purposes.
27 + ``` bash
28 + # serve with hot reload at localhost:8080
29 + npm run dev
30 + ```
31 + The `run build` command is for production purposes and minifies code.
32 + ``` bash
33 + # build for production with minification
34 + npm run build
35 + ```
36 + 4. Your default browser should open and display the sample application, as shown here.
37 + **Note:** In some cases, you may need to open a browser and enter `http://localhost:8080` as the URL.
38 +Resources:
39 + document: https://docs.agora.io/en/
40 + issue: https://github.com/AgoraIO/Basic-Video-Call/issues
41 +
42 +License:
43 + type: MIT
...\ No newline at end of file ...\ No newline at end of file
1 +# Web RTS Tutorial For Webpack - 1to1
2 +
3 +*[English](README.md) | 中文*
4 +
5 +这个开源示例项目演示了如何快速集成 Agora 视频 SDK,实现多人视频通话。
6 +
7 +在这个示例项目中包含了以下功能:
8 +
9 +- 加入通话和离开通话:
10 +- 选择摄像头和麦克风设备:
11 +
12 +## 环境准备
13 +
14 +- nodejs LTS
15 +- 浏览器
16 +
17 +## 运行示例程序
18 +
19 +This section shows you how to prepare, and run the sample application.
20 +
21 +### 创建Agora账号并获取AppId
22 +
23 +在编译和启动实例程序前,您需要首先获取一个可用的App ID:
24 +1.[agora.io](https://dashboard.agora.io/signin/)创建一个开发者账号
25 +2. 前往后台页面,点击左部导航栏的 **项目 > 项目列表** 菜单
26 +3. 复制后台的 **App ID** 并备注,稍后启动应用时会用到它
27 +4. 在项目页面生成临时 **Access Token** (24小时内有效)并备注,注意生成的Token只能适用于对应的频道名。
28 +
29 +> 为提高项目的安全性,Agora 使用 Token(动态密钥)对即将加入频道的用户进行鉴权。
30 +>
31 +> 临时 Token 仅作为演示和测试用途。在生产环境中,你需要自行部署服务器签发 Token,详见[生成 Token](https://docs.agora.io/cn/Interactive Broadcast/token_server)。
32 +
33 +### 集成 Agora 视频 SDK
34 +
35 +1. 在Terminal中,在您的项目根目录输入`install`命令以安装项目依赖
36 + ```shell
37 + # install dependencies
38 + npm install
39 + ```
40 +2. 请到官网[agora.io](https://docs.agora.io/cn/),下载这些文件 **AgoraRTC.js**, **AgoraRTS.js**, **AgoraRTS.asm**, **AgoraRTS.wasm**`static`目录。
41 +3. 输入`run dev`命令以启动Web程序
42 + ```shell
43 + # serve with hot reload at localhost:8080
44 + npm run dev
45 + ```
46 + 输入`npm run build`会压缩静态资源文件,可作为生产环境打包发布。
47 + ``` bash
48 + # build for production with minification
49 + npm run build
50 + ```
51 +4. 你的浏览器默认会打开示例应用程序。
52 + **注意** 如果没有自动打开,请在浏览器里手动输入URL `http://localhost:8080`
53 +
54 +## 联系我们
55 +
56 +- 如果你遇到了困难,可以先参阅 [常见问题](https://docs.agora.io/cn/faq)
57 +- 如果你想了解更多官方示例,可以参考 [官方SDK示例](https://github.com/AgoraIO)
58 +- 如果你想了解声网SDK在复杂场景下的应用,可以参考 [官方场景案例](https://github.com/AgoraIO-usecase)
59 +- 如果你想了解声网的一些社区开发者维护的项目,可以查看 [社区](https://github.com/AgoraIO-Community)
60 +- 完整的 API 文档见 [文档中心](https://docs.agora.io/cn/)
61 +- 若遇到问题需要开发者帮助,你可以到 [开发者社区](https://rtcdeveloper.com/) 提问
62 +- 如果需要售后技术支持, 你可以在 [Agora Dashboard](https://dashboard.agora.io) 提交工单
63 +- 如果发现了示例代码的 bug,欢迎提交 [issue](https://github.com/AgoraIO/Basic-Video-Call/issues)
64 +
65 +## 代码许可
66 +
67 +The MIT License (MIT)
1 +Meta:
2 + name: Web RTS Tutorial For Webpack - 1to1
3 + lang: cn
4 + description: |
5 + 这个开源示例项目演示了如何快速集成 Agora 视频 SDK,实现多人视频通话。
6 +
7 + 在这个示例项目中包含了以下功能:
8 +
9 + - 加入通话和离开通话:
10 + - 选择摄像头和麦克风设备:
11 +
12 +Prerequisites:
13 + - nodejs LTS
14 + - 浏览器
15 +
16 +QuickStart:
17 + description:
18 + This section shows you how to prepare, and run the sample application.
19 + sections:
20 + - title: 创建Agora账号并获取AppId
21 + content: |
22 + $_{APPID}
23 + - title: 集成 Agora 视频 SDK
24 + content: |
25 + 1. 在Terminal中,在您的项目根目录输入`install`命令以安装项目依赖
26 + ```shell
27 + # install dependencies
28 + npm install
29 + ```
30 + 2. 请到官网[agora.io](https://docs.agora.io/cn/),下载这些文件 **AgoraRTC.js**, **AgoraRTS.js**, **AgoraRTS.asm**, **AgoraRTS.wasm** 到`static`目录。
31 + 3. 输入`run dev`命令以启动Web程序
32 + ```shell
33 + # serve with hot reload at localhost:8080
34 + npm run dev
35 + ```
36 + 输入`npm run build`会压缩静态资源文件,可作为生产环境打包发布。
37 + ``` bash
38 + # build for production with minification
39 + npm run build
40 + ```
41 + 4. 你的浏览器默认会打开示例应用程序。
42 + **注意** 如果没有自动打开,请在浏览器里手动输入URL `http://localhost:8080`。
43 +Resources:
44 + document: https://docs.agora.io/cn/
45 + issue: https://github.com/AgoraIO/Basic-Video-Call/issues
46 +
47 +License:
48 + type: MIT
1 +<!DOCTYPE html>
2 +<html lang="en">
3 +
4 +<head>
5 + <meta charset="UTF-8">
6 + <meta http-equiv="X-UA-Compatible" content="ie=edge">
7 + <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
8 + <title>开放日</title>
9 +</head>
10 +
11 +<body class="agora-theme">
12 + <script type="text/javascript" src="AgoraRTC.js"></script>
13 + <script type="text/javascript" src="AgoraRTS.js"></script>
14 + <div class="video-flex-container" id="video">
15 +
16 + </div>
17 +</body>
18 +
19 +</html>
...\ No newline at end of file ...\ No newline at end of file
1 +{
2 + "name": "RTS-Tutorial",
3 + "version": "2.9.0",
4 + "description": "Agora-Web-RTS-Tutorial - One-to-One Video",
5 + "keywords": [
6 + "realtime-communication",
7 + "agora-rtc-sdk",
8 + "webrtc",
9 + "agora-example",
10 + "webpack",
11 + "javascript"
12 + ],
13 + "main": "index.js",
14 + "scripts": {
15 + "dev": "cross-env NODE_ENV=development webpack-dev-server --config ./scripts --mode development",
16 + "build": "cross-env NODE_ENV=production webpack --config ./scripts --mode production",
17 + "lint-fix": "eslint --fix src/ "
18 + },
19 + "dependencies": {
20 + "axios": "^0.23.0",
21 + "jquery": "^3.4.1",
22 + "materialize-css": "^1.0.0",
23 + "qrcode": "^1.4.1",
24 + "sockjs-client": "^1.5.2",
25 + "webstomp-client": "^1.2.6"
26 + },
27 + "devDependencies": {
28 + "@babel/core": "^7.4.5",
29 + "@babel/preset-env": "^7.4.5",
30 + "babel-loader": "^8.0.6",
31 + "clean-webpack-plugin": "^2.0.1",
32 + "copy-webpack-plugin": "^5.0.4",
33 + "cross-env": "^5.2.0",
34 + "css-loader": "^2.1.1",
35 + "ejs-render-loader": "^1.0.0",
36 + "babel-eslint": "10.0.2",
37 + "eslint": "^6.8.0",
38 + "eslint-config-standard": "^14.1.1",
39 + "eslint-loader": "^3.0.3",
40 + "eslint-plugin-import": "^2.20.1",
41 + "eslint-plugin-node": "^11.0.0",
42 + "eslint-plugin-promise": "^4.2.1",
43 + "eslint-plugin-standard": "^4.0.1",
44 + "file-loader": "^3.0.1",
45 + "friendly-errors-webpack-plugin": "^1.7.0",
46 + "html-webpack-plugin": "^3.2.0",
47 + "mini-css-extract-plugin": "^0.5.0",
48 + "style-loader": "^0.23.1",
49 + "webpack": "^4.29.6",
50 + "webpack-cli": "^3.3.0",
51 + "webpack-dev-server": "^3.2.1"
52 + },
53 + "author": "agora",
54 + "license": "ISC"
55 +}
1 +const path = require("path");
2 +const loaders = require("./loaders");
3 +const plugins = require("./plugins");
4 +
5 +const NODE_ENV = process.env.NODE_ENV
6 +
7 +const distPath = NODE_ENV == 'development' ? '../dist' : '../build'
8 +
9 +module.exports = {
10 + entry: {
11 + index: "./src/index.js",
12 + },
13 + devtool: "inline-source-map",
14 + module: loaders,
15 + plugins,
16 + resolve: {
17 + extensions: [ ".js", ".wasm" ],
18 + },
19 + output: {
20 + filename: "[name].[hash].js",
21 + path: path.resolve(__dirname, distPath),
22 + },
23 + optimization: {
24 + minimize: false,
25 + },
26 + devServer: {
27 + overlay: {
28 + warnings: true,
29 + errors: true,
30 + },
31 + hot: true,
32 + contentBase: path.join(__dirname, "./"),
33 + compress: true,
34 + progress: true,
35 + open: true,
36 + proxy: {
37 + '/openday-boot': {
38 + target: 'https://openday.console.etoneiot.tech', // 请求本地 需要openday-boot后台项目
39 + ws: true,
40 + changeOrigin: true
41 + }
42 + }
43 + },
44 +};
1 +const path = require("path");
2 +
3 +const env = process.env;
4 +const MiniCssExtractPlugin = require("mini-css-extract-plugin");
5 +
6 +const styleLoader = env.NODE_ENV !== 'production' ? "style-loader" : MiniCssExtractPlugin.loader;
7 +
8 +const babelLoader = {
9 + test: /\.m?js$/,
10 + exclude: /(node_modules)/,
11 + use: {
12 + loader: 'babel-loader',
13 + options: {
14 + presets: ['@babel/preset-env']
15 + }
16 + }
17 +};
18 +
19 +const cssLoader = {
20 + test: /\.css$/,
21 + use: [
22 + styleLoader,
23 + "css-loader",
24 + ],
25 +};
26 +
27 +const eslintLoader = {
28 + test: /\.js$/,
29 + include: /src/,
30 + use: {
31 + loader: 'eslint-loader'
32 + }
33 +};
34 +
35 +const fileLoader = {
36 + test: /\.(png|svg|jpg|gif)$/,
37 + use: "file-loader",
38 +};
39 +
40 +const fontLoader = {
41 + test: /\.(woff|woff2|eot|ttf|otf)$/,
42 + use: "file-loader",
43 +};
44 +
45 +module.exports = {
46 + rules: [
47 + cssLoader,
48 + fileLoader,
49 + fontLoader,
50 + babelLoader,
51 + eslintLoader,
52 + ],
53 +};
1 +const HtmlWebpackPlugin = require("html-webpack-plugin");
2 +const CleanWebpackPlugin = require("clean-webpack-plugin");
3 +const FriendlyErrorsPlugin = require("friendly-errors-webpack-plugin");
4 +const MiniCssExtractPlugin = require("mini-css-extract-plugin");
5 +const CopyPlugin = require('copy-webpack-plugin');
6 +const path = require("path");
7 +const resolve = path.resolve;
8 +const webpack = require('webpack');
9 +const NODE_ENV = process.env.NODE_ENV;
10 +const copyPath = NODE_ENV == 'development' ? '../dist' : '../build';
11 +
12 +const plugins = [
13 + new HtmlWebpackPlugin({
14 + filename: "index.html",
15 + template: path.resolve(__dirname, "../index.html"),
16 + }),
17 + new CleanWebpackPlugin(),
18 + new FriendlyErrorsPlugin({
19 + compilationSuccessInfo: {
20 + messages: ["You application is running here http://localhost:8080"],
21 + notes: ["Some additionnal notes to be displayed upon successful compilation"],
22 + },
23 + onErrors: function(severity, errors) {},
24 + clearConsole: true,
25 + additionalFormatters: [],
26 + additionalTransformers: [],
27 + }),
28 + new MiniCssExtractPlugin({
29 + filename: "[name].[hash].css",
30 + chunkFilename: "[id].css"
31 + }),
32 + new CopyPlugin([
33 + { from: resolve(__dirname, '../static'), to: resolve(__dirname, copyPath) },
34 + ]),
35 + new webpack.ProvidePlugin({
36 + $: "jquery",
37 + jQuery: "jquery",
38 + Popper: 'popper.js/dist/umd/popper',
39 + })
40 +];
41 +
42 +module.exports = plugins;
1 +html, body,#video{
2 + width: 100%;
3 + height: 100%;
4 +}
5 +.video-view, .video-placeholder {
6 + height: 100%;
7 +}
...\ No newline at end of file ...\ No newline at end of file
1 +export function addView (id) {
2 + if (!$('#' + id)[0]) {
3 + $('<div/>', {
4 + id: 'remote_video_panel_' + id,
5 + class: 'video-view',
6 + }).appendTo('#video')
7 +
8 + $('<div/>', {
9 + id: 'remote_video_' + id,
10 + class: 'video-placeholder',
11 + }).appendTo('#remote_video_panel_' + id)
12 + }
13 +}
14 +
15 +export function removeView (id) {
16 + if ($('#remote_video_panel_' + id)[0]) {
17 + $('#remote_video_panel_'+id).remove()
18 + }
19 +}
1 +import RTCClient from './rtc-client';
2 +import axios from "axios";
3 +import stomp from "./stomp";
4 +
5 +import './assets/style.css'
6 +
7 +if (!AgoraRTS.checkSystemRequirements()) {
8 + alert('Your web browser not support AgoraRTS!')
9 +} else {
10 + console.log('check success')
11 +}
12 +
13 +
14 +
15 +$(() => {
16 + let rtc = new RTCClient()
17 +
18 + let subscribes = [];
19 + let sessionId = '';
20 + let loading = false;
21 + let token = '';
22 + let noticeInfo = {};
23 +
24 + function createWatch() {
25 + subscribes = [];
26 + subscribes.push({
27 + topic: '/broadcast/live',
28 + callback: (data) => {
29 + if (data.body) {
30 + let msg = JSON.parse(data.body)
31 + if (msg.type === 'changeSid') {
32 + sessionId = msg.content;
33 + console.log(msg.content);
34 + rtc.join(sessionId).then(() => {
35 + console.log('加入')
36 + })
37 + }
38 + if (msg.type === 'overLive') {
39 + sessionId = '';
40 + rtc.leave();
41 + getNotice();
42 + }
43 + }
44 + },
45 + });
46 + init();
47 + }
48 +
49 + function init() {
50 + if (subscribes.length > 0) {
51 + stomp.disconnect();
52 + stomp.connect(subscribes);
53 + }
54 + }
55 +
56 + createWatch();
57 +
58 + axios.post('https://openday.console.etoneiot.tech/openday-boot/sys/mLogin', {
59 + username: 'admin',
60 + password: 'admin123'
61 + }).then(r => {
62 + if (r.data.code === 200) {
63 + token = r.data.result.token;
64 + getNotice();
65 + }
66 + })
67 +
68 + function getNotice() {
69 + axios.get('https://openday.console.etoneiot.tech/openday-boot/openday/notice', {
70 + headers: {
71 + 'X-Access-Token': token
72 + }
73 + }).then(r => {
74 + if (r.data.code === 200) {
75 + noticeInfo = r.data.result;
76 + sessionId = r.data.result.sessionId;
77 + rtc.join(sessionId).then(() => {
78 + console.log('加入')
79 + })
80 + } else {
81 + noticeInfo = {};
82 + sessionId = '';
83 + }
84 + })
85 + }
86 +
87 +})
...\ No newline at end of file ...\ No newline at end of file
1 +import { addView, removeView} from './common'
2 +
3 +console.log('agora sdk version: ' + AgoraRTC.VERSION + ' compatible: ' + AgoraRTC.checkSystemRequirements())
4 +
5 +export default class RTCClient {
6 + constructor () {
7 + this._client = null
8 + this._joined = false
9 + this._published = false
10 + this._localStream = null
11 + this._remoteStreams = []
12 + this._rtsStreamProfile = {}
13 + this._params = {}
14 +
15 + this._showProfile = false
16 + }
17 +
18 + handleEvents() {
19 + this._client.on('error', (err) => {
20 + console.log(err)
21 + })
22 +
23 + // Occurs when the peer user leaves the channel; for example, the peer user calls Client.leave.
24 + this._client.on('peer-leave', (evt) => {
25 + const id = evt.uid
26 + if (id != this._params.uid) {
27 + removeView(id)
28 + }
29 + // Toast.notice('peer leave')
30 + console.log('peer-leave', id)
31 + })
32 +
33 + // Occurs when the remote stream is added.
34 + this._client.on('stream-added', (evt) => {
35 + const remoteStream = evt.stream
36 + const id = remoteStream.getId()
37 + // Toast.info('stream-added uid: ' + id)
38 + if (id !== this._params.uid && remoteStream.hasVideo()) {
39 + this._client.subscribe(remoteStream, (err) => {
40 + console.log('stream subscribe failed', err)
41 + })
42 + }
43 + console.log('stream-added remote-uid: ', id)
44 + })
45 + // Occurs when a user subscribes to a remote stream.
46 + this._client.on('stream-subscribed', (evt) => {
47 + const remoteStream = evt.stream
48 + const id = remoteStream.getId()
49 + this._remoteStreams.push(remoteStream)
50 + addView(id)
51 + remoteStream.play('remote_video_' + id, {fit: 'cover'})
52 + // Toast.info('stream-subscribed remote-uid: ' + id)
53 + console.log('stream-subscribed remote-uid: ', id)
54 + })
55 + // Occurs when the remote stream is removed; for example, a peer user calls Client.unpublish.
56 + this._client.on('stream-removed', (evt) => {
57 + const remoteStream = evt.stream
58 + const id = remoteStream.getId()
59 + // Toast.info('stream-removed uid: ' + id)
60 + remoteStream.stop()
61 + this._remoteStreams = this._remoteStreams.filter((stream) => {
62 + return stream.getId() !== id
63 + })
64 + removeView(id)
65 + console.log('stream-removed remote-uid: ', id)
66 + })
67 +
68 +
69 + }
70 +
71 + join (sid) {
72 + this.leave();
73 + return new Promise((resolve, reject) => {
74 +
75 +
76 + this._client = AgoraRTC.createClient({mode: 'live', codec: 'h264'})
77 + AgoraRTS.init(AgoraRTC, {
78 + wasmDecoderPath: 'AgoraRTS.wasm',
79 + asmDecoderPath: 'AgoraRTS.asm',
80 + bufferDelay: 3000,
81 + maxBufferDelay: 10000,
82 + }).catch(e => {
83 + if (e === 'LOAD_DECODER_FAILED') {
84 + console.log('Codec load failed!')
85 + }
86 + })
87 + AgoraRTS.proxy(this._client)
88 + this._params = {
89 + sid
90 + }
91 +
92 + // handle AgoraRTC client event
93 + this.handleEvents()
94 +
95 + // init client
96 + this._client.init('ac385634df8f4f62b4357ab35c54e88e', () => {
97 + console.log('init success')
98 +
99 +
100 + this._client.join(null, sid, null, (uid) => {
101 + this._params.uid = uid
102 + // Toast.notice('join channel: ' + sid + ' success, uid: ' + uid)
103 + console.log('join channel: ' + sid + ' success, uid: ' + uid)
104 + this._joined = true
105 +
106 + // start stream interval stats
107 + }, function(err) {
108 + // Toast.error('client join failed, please open console see more detail')
109 + console.error('client join failed', err)
110 + })
111 + }, (err) => {
112 + // Toast.error('client init failed, please open console see more detail')
113 + console.error(err)
114 + })
115 + })
116 + }
117 +
118 + leave () {
119 + if (!this._client) {
120 + // Toast.error('Please Join First!')
121 + return
122 + }
123 + if (!this._joined) {
124 + // Toast.error('You are not in channel')
125 + return
126 + }
127 + // leave channel
128 + this._client.leave(() => {
129 +
130 + // stop stream
131 + while (this._remoteStreams.length > 0) {
132 + const stream = this._remoteStreams.shift()
133 + const id = stream.getId()
134 + stream.stop()
135 + removeView(id)
136 + }
137 + this._localStream = null
138 + this._remoteStreams = []
139 + this._client = null
140 + console.log('client leaves channel success')
141 + this._published = false
142 + this._joined = false
143 + // Toast.notice('leave success')
144 + }, (err) => {
145 + console.log('channel leave failed')
146 + // Toast.error('leave success')
147 + console.error(err)
148 + })
149 + }
150 +
151 +}
152 +
1 +import SockJS from 'sockjs-client'
2 +import Stomp from 'webstomp-client'
3 +
4 +let stompClient = null
5 +const getStompClient = function () {
6 + if (stompClient === null) {
7 + let socket = new SockJS('https://openday.console.etoneiot.tech/openday-boot/realtime')
8 + stompClient = Stomp.over(socket)
9 + stompClient.hasDebug = false
10 + }
11 + return stompClient
12 +}
13 +/**
14 + * 连接服务
15 + * @param [{ topic: String, callback: Function}]
16 + */
17 +const connect = function (params) {
18 + let client = getStompClient()
19 + if (client.connected) {
20 + return
21 + }
22 + let onConnected = function (frame) {
23 + for (const param of params) {
24 + if (!param.type) {
25 + param.type = 'subscribe'
26 + }
27 + if (param.type === 'subscribe') {
28 + client.subscribe(param.topic, param.callback)
29 + }
30 + if (param.type === 'send') {
31 + if (!param.payload) {
32 + param.payload = ""
33 + }
34 + client.send(param.topic, param.payload)
35 + }
36 + if (param.type === 'callback' && param.callback) {
37 + param.callback(client)
38 + }
39 + }
40 + }
41 + client.connect({}, onConnected, (frame) => {
42 + //自动重连
43 + setTimeout(() => {
44 + let socket = new SockJS('/openday-boot/realtime')
45 + stompClient = Stomp.over(socket)
46 + stompClient.hasDebug = false
47 + connect(params)
48 + }, 2000)
49 + })
50 +}
51 +const disconnect = function () {
52 + if (stompClient && stompClient.connected) {
53 + stompClient.disconnect()
54 + stompClient = null
55 + }
56 +}
57 +const sendMessage = function (topic, message) {
58 + if (stompClient && stompClient.connected) {
59 + let msg = message
60 + if (typeof msg !== 'string') {
61 + msg = JSON.stringify(msg)
62 + }
63 + stompClient.send(topic, msg)
64 + } else {
65 + throw 'stomp client is null or disconnected'
66 + }
67 +}
68 +
69 +export default {
70 + connect,
71 + disconnect,
72 + sendMessage
73 +}
74 +
No preview for this file type
File mode changed
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
This diff could not be displayed because it is too large.
No preview for this file type