Skip to content

Commit 25895e9

Browse files
authored
Merge pull request #194 from AgoraIO/dev/add-vue-tutorial
Dev/add vue tutorial
2 parents 0325ea1 + 929c5d0 commit 25895e9

File tree

4 files changed

+89
-23
lines changed

4 files changed

+89
-23
lines changed

One-to-One-Video/Agora-Web-Tutorial-1to1-Vue/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
*English | [中文](README.zh.md)*
2+
3+
This code example shows how to quickly integrate basic one-to-one/one-to-many video calls
4+
5+
Functions include:
6+
1. Join the channel
7+
2. Leave the channel
8+
Among them, Appid, Channel must be filled, Token is optional
9+
Video supports one to one, one to many calls
10+
11+
To build and run the sample application, get an App ID:
12+
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.
13+
2. Navigate in the Dashboard tree on the left to **Projects** > **Project List**.
14+
3. Save the **App ID** from the Dashboard for later use.
15+
4. Generate a temp **Access Token** (valid for 24 hours) from dashboard page with given channel name, save for later use.
16+
17+
Start project
118
# basic-video-call
219

320
## Project setup
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
*[English](README.md) | 中文*
2+
3+
本项目代码示例了如何快速集成 基础一对一/一对多 视频通话
4+
功能包含:
5+
1. 加入频道
6+
2. 离开频道
7+
其中,Appid, Channel 必填,Token 为可选
8+
视频支持一对一,一对多 通话
9+
10+
如何获取appID ?
11+
1.[agora.io](https://dashboard.agora.io/signin/)创建一个开发者账号
12+
2. 前往后台页面,点击左部导航栏的 **项目 > 项目列表** 菜单
13+
3. 复制后台的 **App ID** 并备注,稍后启动应用时会用到它
14+
4. 在项目页面生成临时 **Access Token** (24小时内有效)并备注,注意生成的Token只能适用于对应的频道名。
15+
16+
开始运行项目
17+
# basic-video-call
18+
19+
## Project setup
20+
```
21+
npm install
22+
```
23+
24+
### Compiles and hot-reloads for development
25+
```
26+
npm run dev
27+
```
28+
29+
### Compiles and minifies for production
30+
```
31+
npm run build
32+
```
33+
34+
### Lints and fixes files
35+
```
36+
npm run lint
37+
```
38+
39+
### Customize configuration
40+
See [Configuration Reference](https://cli.vuejs.org/config/).

One-to-One-Video/Agora-Web-Tutorial-1to1-Vue/src/agora-rtc-client.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default class RTCClient {
3535
console.error("client join failed", err)
3636
})
3737
}, (err) => {
38-
reject()
38+
reject(err)
3939
console.error(err)
4040
})
4141
console.log("[agora-vue] appId", option.appid)
@@ -54,14 +54,14 @@ export default class RTCClient {
5454
// Initialize the local stream
5555
this.localStream.init(() => {
5656
console.log("init local stream success")
57-
resolve()
57+
resolve(this.localStream)
5858
// Publish the local stream
5959
this.client.publish(this.localStream, (err) => {
6060
console.log("publish failed")
6161
console.error(err)
6262
})
6363
}, (err) => {
64-
reject()
64+
reject(err)
6565
console.error("init local stream failed ", err)
6666
})
6767
})
@@ -109,7 +109,7 @@ export default class RTCClient {
109109
resolve()
110110
console.log("client leaves channel success");
111111
}, (err) => {
112-
reject()
112+
reject(err)
113113
console.log("channel leave failed");
114114
console.error(err);
115115
})

One-to-One-Video/Agora-Web-Tutorial-1to1-Vue/src/components/Home.vue

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@
55
</div>
66
<div class='agora-box'>
77
<div class="agora-input">
8-
<div class="text-agora">* Appid</div>
9-
<el-input v-model="option.appid" placeholder="Appid" clearable style="width: 320px"></el-input>
8+
<div class="agora-text">* Appid</div>
9+
<el-input v-model="option.appid" placeholder="Appid" clearable></el-input>
1010
</div>
1111
<div class="agora-input">
12-
<div class="text-agora">Token</div>
13-
<el-input v-model="option.token" placeholder="Token" clearable style="width: 320px"></el-input>
12+
<div class="agora-text">Token</div>
13+
<el-input v-model="option.token" placeholder="Token" clearable></el-input>
1414
</div>
1515
<div class="agora-input">
16-
<div class="text-agora">* Channel Name</div>
17-
<el-input v-model="option.channel" placeholder="Channel Name" clearable style="width: 320px"></el-input>
16+
<div class="agora-text">* Channel Name</div>
17+
<el-input v-model="option.channel" placeholder="Channel Name" clearable></el-input>
1818
</div>
1919
<div class="agora-button">
20-
<el-row>
21-
<el-button type="primary" @click="joinEvent" :disabled='showJoin' style="width: 90px; margin: 10px">join</el-button>
22-
<el-button type="primary" @click='leaveEvent' plain :disabled='!showJoin' style="width: 90px; margin: 10px">leave</el-button>
23-
</el-row>
20+
<el-button type="primary" @click="joinEvent" :disabled='disableJoin'>join</el-button>
21+
<el-button type="primary" @click='leaveEvent' plain :disabled='!disableJoin'>leave</el-button>
2422
</div>
2523
</div>
2624
<div class="agora-view">
@@ -51,7 +49,7 @@ export default {
5149
uid: null,
5250
channel: '',
5351
},
54-
showJoin: false,
52+
disableJoin: false,
5553
localStream: null,
5654
remoteStreams: [],
5755
}
@@ -75,12 +73,12 @@ export default {
7573
message: 'Join Success',
7674
type: 'success'
7775
});
78-
this.rtc.publishStream().then(() => {
76+
this.rtc.publishStream().then((stream) => {
7977
this.$message({
8078
message: 'Publish Success',
8179
type: 'success'
8280
});
83-
this.localStream = this.rtc.localStream
81+
this.localStream = stream
8482
}).catch((err) => {
8583
this.$message.error('Publish Failure');
8684
log('publish local error', err)
@@ -89,10 +87,10 @@ export default {
8987
this.$message.error('Join Failure');
9088
log('join channel error', err)
9189
})
92-
this.showJoin = true
90+
this.disableJoin = true
9391
},
9492
leaveEvent () {
95-
this.showJoin = false
93+
this.disableJoin = false
9694
this.rtc.leaveChannel().then(() => {
9795
this.$message({
9896
message: 'Leave Success',
@@ -136,6 +134,15 @@ export default {
136134
log('[agora] [stream-removed] stream-removed', stream.getId())
137135
this.remoteStreams = this.remoteStreams.filter((it) => it.getId() !== stream.getId())
138136
})
137+
138+
rtc.on('peer-online', (evt) => {
139+
this.$message(`Peer ${evt.uid} is online`)
140+
})
141+
142+
rtc.on('peer-leave', (evt) => {
143+
this.$message(`Peer ${evt.uid} already leave`)
144+
this.remoteStreams = this.remoteStreams.filter((it) => it.getId() !== evt.uid)
145+
})
139146
}
140147
}
141148
</script>
@@ -154,6 +161,7 @@ export default {
154161
}
155162
.agora-view {
156163
display: flex;
164+
flex-wrap: wrap;
157165
}
158166
.agora-video {
159167
width: 320px;
@@ -162,20 +170,21 @@ export default {
162170
}
163171
.agora-input {
164172
margin: 20px;
173+
width: 320px;
165174
}
166175
.agora-text {
167176
margin: 5px;
168177
font-size: 16px;
169178
font-weight: bold;
170179
}
171180
.agora-button {
172-
margin-left: 10px;
181+
display: flex;
182+
width: 160px;
183+
justify-content: space-between;
184+
margin: 20px;
173185
}
174186
.agora-video {
175187
width: 320px;
176188
height: 240px;
177189
}
178-
.text-agora {
179-
font-weight: bold;
180-
}
181190
</style>

0 commit comments

Comments
 (0)