Skip to content

Commit becbe6d

Browse files
committed
bug修复
1 parent 905b644 commit becbe6d

File tree

9 files changed

+210
-242
lines changed

9 files changed

+210
-242
lines changed

.idea/workspace.xml

Lines changed: 79 additions & 156 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/danbai/ys/entity/User.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,16 @@ public String getHeadurl() {
139139
public void setHeadurl(String headurl) {
140140
this.headurl = headurl;
141141
}
142+
143+
@Override
144+
public String toString() {
145+
return "User{" +
146+
"id=" + id +
147+
", username='" + username + '\'' +
148+
", userType=" + userType +
149+
", password='" + password + '\'' +
150+
", email='" + email + '\'' +
151+
", headurl='" + headurl + '\'' +
152+
'}';
153+
}
142154
}

src/main/java/com/danbai/ys/mapper/UserMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
import org.springframework.stereotype.Repository;
88

99
@Repository
10-
@CacheNamespace(implementation = RedisCache.class)
10+
1111
public interface UserMapper extends MyMapper<User> {
1212
}

src/main/java/com/danbai/ys/utils/EmailUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class EmailUtil {
2121
private static final String PROTOCOL = "smtp";
2222
private static final int PORT = 465;
2323
private static final String FROM = "[email protected]";
24-
private static final String PWD = "";
24+
private static final String PWD = "DBYSdbys225";
2525

2626
private static JavaMailSenderImpl javaMailSender;
2727

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/**
2+
* @author DanBai
3+
* @create 2020-03-20 20:53
4+
* @desc md5
5+
**/
6+
package com.danbai.ys.utils;
7+
8+
import java.math.BigInteger;
9+
import java.security.MessageDigest;
10+
11+
public class Md5 {
12+
/**
13+
* 对字符串md5加密
14+
*
15+
* @param str 传入要加密的字符串
16+
* @return MD5加密后的字符串(小写+字母)
17+
*/
18+
public static String getMD5LowerCase(String str) {
19+
try {
20+
// 生成一个MD5加密计算摘要
21+
MessageDigest md = MessageDigest.getInstance("MD5");
22+
// 计算md5函数
23+
md.update(str.getBytes());
24+
// digest()最后确定返回md5 hash值,返回值为8为字符串。因为md5 hash值是16位的hex值,实际上就是8位的字符
25+
// BigInteger函数则将8位的字符串转换成16位hex值,用字符串来表示;得到字符串形式的hash值
26+
return new BigInteger(1, md.digest()).toString(16);
27+
} catch (Exception e) {
28+
e.printStackTrace();
29+
return null;
30+
}
31+
}
32+
33+
/**
34+
* 对字符串md5加密
35+
*
36+
* @param str 传入要加密的字符串
37+
* @return MD5加密后的字符串(大写+数字)
38+
*/
39+
40+
public static String getMD5UpperCase(String s) {
41+
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
42+
'A', 'B', 'C', 'D', 'E', 'F' };
43+
try {
44+
byte[] btInput = s.getBytes();
45+
// 获得MD5摘要算法的 MessageDigest 对象
46+
MessageDigest mdInst = MessageDigest.getInstance("MD5");
47+
// 使用指定的字节更新摘要
48+
mdInst.update(btInput);
49+
// 获得密文
50+
byte[] md = mdInst.digest();
51+
// 把密文转换成十六进制的字符串形式
52+
int j = md.length;
53+
char str[] = new char[j * 2];
54+
int k = 0;
55+
for (int i = 0; i < j; i++) {
56+
byte byte0 = md[i];
57+
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
58+
str[k++] = hexDigits[byte0 & 0xf];
59+
}
60+
return new String(str);
61+
} catch (Exception e) {
62+
e.printStackTrace();
63+
return null;
64+
}
65+
}
66+
}

src/main/java/com/danbai/ys/websocket/CinemaSocketManagement.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.alibaba.fastjson.JSONObject;
1010
import com.danbai.ys.async.CinemaSocketAsync;
1111
import com.danbai.ys.entity.CinemaRoom;
12+
import com.danbai.ys.utils.Md5;
1213
import com.danbai.ys.utils.SpringUtil;
1314

1415
import io.agora.media.RtcTokenBuilder;
@@ -48,7 +49,7 @@ public static void joinRoom(String socketId, int roomId, String pass) {
4849
RtcTokenBuilder token = new RtcTokenBuilder();
4950
int timestamp = (int)(System.currentTimeMillis() / 1000 + 3600);
5051
String result = token.buildTokenWithUid(RtcTokenBuilderSample.appId, RtcTokenBuilderSample.appCertificate,
51-
cinemaRoom.getName()+cinemaRoom.getId(), Integer.parseInt(socketId,16), RtcTokenBuilder.Role.Role_Publisher, timestamp);
52+
Md5.getMD5LowerCase(cinemaRoom.getName()+cinemaRoom.getId()), Integer.parseInt(socketId,16), RtcTokenBuilder.Role.Role_Publisher, timestamp);
5253
jsonObject.put("token",result);
5354
jsonObject.put("id",roomId);
5455
jsonObject.put("name",cinemaRoom.getName());

src/main/java/io/agora/sample/RtcTokenBuilderSample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
public class RtcTokenBuilderSample {
77
public static String appId = "02e8df44f24e4da5b2e17ef1d8b755bd";
8-
public static String appCertificate = "";
8+
public static String appCertificate = "c128d51ba98148d5bba2a65f82c83d35";
99
static String channelName = "7d72365eb983485397e3e3f9d460bdda";
1010
static String userAccount = "2082341273";
1111
static int uid = 2082341273;

src/main/resources/templates/include/include.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<li><a href="/type/zy?page=1">综艺</a></li>
6060
<li><a href="/type/dm?page=1">动漫</a></li>
6161
<li><a href="http://dbys.vip/type/tv">直播</a></li>
62-
<li><a href="http://dbys.vip/yiqikan">一起看(需先登录)</a></li>
62+
<li><a href="https://dbys.vip/yiqikan">一起看(需先登录)</a></li>
6363
</ul>
6464
<div class="pull-right">
6565
<ul class="nav navbar-nav" th:if="${session.user}==null">

src/main/resources/templates/yiqikan/index.html

Lines changed: 47 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -107,31 +107,15 @@ <h3 id="fangjianInfo"></h3>
107107
</div>
108108
</div>
109109
<div class="tab-pane fade" id="yuyin">
110-
<form id="form" class="row col l12 s12">
111-
<div class="row container col l12 s12">
112-
<div class="col" style="min-width: 433px; max-width: 443px">
113-
<div class="card" style="margin-top: 0px; margin-bottom: 0px;">
114-
<div class="row card-content" style="margin-bottom: 0px;">
115-
<div class="row" style="margin: 0">
116-
<div class="col s12">
117-
<button class="btn btn-raised btn-primary waves-effect waves-light" id="join">加入</button>
118-
<button class="btn btn-raised btn-primary waves-effect waves-light" id="leave">断开</button>
119-
</div>
120-
</div>
121-
</div>
122-
</div>
123-
</div>
124-
<div class="col s7">
110+
<button class="btn btn-raised btn-primary waves-effect waves-light" id="join">加入</button>
111+
<button class="btn btn-raised btn-primary waves-effect waves-light" id="leave">断开</button>
125112
<div class="video-grid" id="video">
126113
<div class="video-view">
127114
<div id="local_stream" class="video-placeholder"></div>
128115
<div id="local_video_info" class="video-profile hide"></div>
129116
<div id="video_autoplay_local" class="autoplay-fallback hide"></div>
130117
</div>
131-
</div>
132-
</div>
133-
</div>
134-
</form>
118+
135119
</div>
136120
</div>
137121
</div>
@@ -145,7 +129,7 @@ <h3 id="fangjianInfo"></h3>
145129
<script src="https://cdn.jsdelivr.net/npm/p2p-dplayer@latest"></script>
146130
<script src="https://cdn.p00q.cn/ys/js/AgoraRTCSDK-3.0.1.js"></script>
147131
<script src="https://cdn.p00q.cn/ys/js/materialize.min.js"></script>
148-
132+
<script src="https://cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script>
149133
<script th:inline="javascript">
150134
/*<![CDATA[*/
151135
var username = /*[[${session.user.username}]]*/ null;
@@ -274,7 +258,7 @@ <h3 id="fangjianInfo"></h3>
274258
$("#ysSouBt").click(function () {
275259
gjc = $("#ysSouInput").val();
276260
$.ajax({
277-
url: 'https://dbys.vip/api/v1/ys/search/' + gjc,
261+
url: '../api/v1/ys/search/' + gjc,
278262
type: 'get',
279263
dataType: 'json',
280264
success: function (data) {
@@ -291,7 +275,7 @@ <h3 id="fangjianInfo"></h3>
291275
$('#yss').hide();
292276
$('#jis').show();
293277
$.ajax({
294-
url: 'https://dbys.vip/api/v1/ys/' + id,
278+
url: '../api/v1/ys/' + id,
295279
type: 'get',
296280
dataType: 'json',
297281
success: function (data) {
@@ -353,7 +337,7 @@ <h3 id="fangjianInfo"></h3>
353337
$("#fangjian").show();
354338
ws.send(toJsonStr({ type: "roomInfo" }));
355339
options.uid=data.uid;
356-
options.channel=data.name+data.id;
340+
options.channel=md5(data.name+data.id);
357341
options.token=data.token;
358342
} else {
359343
Notiflix.Notify.Failure('加入失败');
@@ -471,6 +455,7 @@ <h3 id="fangjianInfo"></h3>
471455
var roomTimerId = setInterval(function () {
472456
if ($("#shouye").is(":hidden")) {
473457
ws.send(toJsonStr({ type: "roomInfo" }));
458+
474459
}
475460
}, 5000);
476461

@@ -488,16 +473,6 @@ <h3 id="fangjianInfo"></h3>
488473
return true;
489474
}
490475

491-
function serializeformData() {
492-
var formData = $("#form").serializeArray();
493-
var obj = {}
494-
for (var item of formData) {
495-
var key = item.name;
496-
var val = item.value;
497-
obj[key] = val;
498-
}
499-
return obj;
500-
}
501476

502477
function addView (id, show) {
503478
if (!$("#" + id)[0]) {
@@ -528,50 +503,6 @@ <h3 id="fangjianInfo"></h3>
528503
}
529504
}
530505

531-
function getDevices (next) {
532-
AgoraRTC.getDevices(function (items) {
533-
items.filter(function (item) {
534-
return ['audioinput', 'videoinput'].indexOf(item.kind) !== -1
535-
})
536-
.map(function (item) {
537-
return {
538-
name: item.label,
539-
value: item.deviceId,
540-
kind: item.kind,
541-
}
542-
});
543-
var videos = [];
544-
var audios = [];
545-
for (var i = 0; i < items.length; i++) {
546-
var item = items[i];
547-
if ('videoinput' == item.kind) {
548-
var name = item.label;
549-
var value = item.deviceId;
550-
if (!name) {
551-
name = "camera-" + videos.length;
552-
}
553-
videos.push({
554-
name: name,
555-
value: value,
556-
kind: item.kind
557-
});
558-
}
559-
if ('audioinput' == item.kind) {
560-
var name = item.label;
561-
var value = item.deviceId;
562-
if (!name) {
563-
name = "microphone-" + audios.length;
564-
}
565-
audios.push({
566-
name: name,
567-
value: value,
568-
kind: item.kind
569-
});
570-
}
571-
}
572-
next({videos: videos, audios: audios});
573-
});
574-
}
575506

576507
var rtc = {
577508
client: null,
@@ -750,7 +681,42 @@ <h3 id="fangjianInfo"></h3>
750681

751682
rtc.published = true
752683
}
684+
function leave (rtc) {
685+
if (!rtc.client) {
753686

687+
return;
688+
}
689+
if (!rtc.joined) {
690+
return;
691+
}
692+
/**
693+
* Leaves an AgoraRTC Channel
694+
* This method enables a user to leave a channel.
695+
**/
696+
rtc.client.leave(function () {
697+
// stop stream
698+
rtc.localStream.stop();
699+
// close stream
700+
rtc.localStream.close();
701+
while (rtc.remoteStreams.length > 0) {
702+
var stream = rtc.remoteStreams.shift();
703+
var id = stream.getId();
704+
stream.stop();
705+
removeView(id);
706+
}
707+
rtc.localStream = null;
708+
rtc.remoteStreams = [];
709+
rtc.client = null;
710+
console.log("client leaves channel success");
711+
rtc.published = false;
712+
rtc.joined = false;
713+
Toast.notice("leave success");
714+
}, function (err) {
715+
console.log("channel leave failed");
716+
Toast.error("leave success");
717+
console.error(err);
718+
})
719+
}
754720
$(function () {
755721

756722
$("#join").on("click", function (e) {
@@ -759,11 +725,11 @@ <h3 id="fangjianInfo"></h3>
759725
joinyuyin(rtc, options);
760726
})
761727

762-
$("#publish").on("click", function (e) {
763-
console.log("publish")
728+
$("#leave").on("click", function (e) {
729+
console.log("leave")
764730
e.preventDefault();
765-
publish(rtc);
766-
});
731+
leave(rtc);
732+
})
767733
})
768734
</script>
769735
<style>

0 commit comments

Comments
 (0)