Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
haishi
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
冷斌
haishi
Commits
65e62503
Commit
65e62503
authored
Apr 29, 2020
by
冷斌
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
e627b141
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
184 additions
and
23 deletions
+184
-23
LiveNewIM/s1.js
+165
-16
api/Appapi/Api/Live.php
+19
-7
No files found.
LiveNewIM/s1.js
View file @
65e62503
...
...
@@ -28,7 +28,11 @@ var LivePK={};
var
LivePK_gift
=
{};
/* PK计时器 */
var
LivePK_timer
=
{};
var
LivePH_timer
=
{};
var
LivePKtime_timer
=
{};
var
LivePHtime_timer
=
{};
var
PKTimer
=
{};
var
PHTimer
=
{};
// redis 链接
var
clientRedis
=
redis
.
createClient
(
config
[
'REDISPORT'
],
config
[
'REDISHOST'
]);
clientRedis
.
auth
(
config
[
'REDISPASS'
]);
...
...
@@ -50,8 +54,8 @@ var io = socketio.listen(server,{
var sub = redis.createClient(config['REDISPORT'], config['REDISHOST'], { auth_pass: config['REDISPASS'] });
io.adapter(redisio({ pubClient: pub, subClient: sub })); */
//setInterval(function(){
//global.gc();
////console.log('GC done')
//global.gc();
////console.log('GC done')
//}, 1000*30);
io
.
on
(
'connection'
,
function
(
socket
)
{
...
...
@@ -107,6 +111,7 @@ io.on('connection', function(socket) {
socket
.
join
(
data
.
roomnum
);
sockets
[
userid
]
=
socket
;
socket
.
emit
(
'conn'
,[
'ok'
]);
//socket.emit('conn1',['ok1']);
/* 重连时 处理PK */
if
(
socket
.
roomnum
==
socket
.
uid
){
...
...
@@ -252,6 +257,7 @@ io.on('connection', function(socket) {
var
gifToken
=
dataObj
[
'msg'
][
0
][
'ct'
];
clientRedis
.
get
(
gifToken
,
function
(
error
,
res
){
if
(
!
error
&&
res
!=
null
){
//console.log(res);
var
resObj
=
evalJson
(
res
);
dataObj
[
'msg'
][
0
][
'ct'
]
=
resObj
;
var
pkuid
=
LivePK
[
socket
.
roomnum
];
...
...
@@ -263,7 +269,8 @@ io.on('connection', function(socket) {
if
(
pkuid
&&
pkuid
>
0
){
ifpk
=
'1'
;
var
total
=
Number
(
resObj
.
totalcoin
);
LivePK_gift
[
socket
.
roomnum
]
+=
total
;
//LivePK_gift[socket.roomnum]+=total;
LivePK_gift
[
socket
.
roomnum
]
=
Number
(
LivePK_gift
[
socket
.
roomnum
])
+
total
;
clientRedis
.
hincrby
(
'LivePK_gift'
,
socket
.
roomnum
,
total
);
pkuid1
=
''
+
socket
.
roomnum
;
...
...
@@ -277,7 +284,7 @@ io.on('connection', function(socket) {
dataObj
[
'msg'
][
0
][
'pkuid2'
]
=
pkuid2
;
dataObj
[
'msg'
][
0
][
'pktotal1'
]
=
pktotal1
;
dataObj
[
'msg'
][
0
][
'pktotal2'
]
=
pktotal2
;
//console.log('sendgift'+socket.roomnum);
io
.
sockets
.
in
(
socket
.
roomnum
).
emit
(
'broadcastingListen'
,[
JSON
.
stringify
(
dataObj
)]);
if
(
pkuid
>
0
){
io
.
sockets
.
in
(
pkuid
).
emit
(
'broadcastingListen'
,[
JSON
.
stringify
(
dataObj
)]);
...
...
@@ -548,6 +555,26 @@ io.on('connection', function(socket) {
process_msg
(
io
,
pkuid
,
JSON
.
stringify
(
data_obj_pk
));
}
else
if
(
action
==
'5'
){
if
(
LivePKtime_timer
[
socket
.
uid
]){
clearInterval
(
LivePKtime_timer
[
socket
.
uid
]);
LivePKtime_timer
[
socket
.
uid
]
=
null
;
}
if
(
LivePHtime_timer
[
socket
.
uid
]){
clearInterval
(
LivePHtime_timer
[
socket
.
uid
]);
LivePHtime_timer
[
socket
.
uid
]
=
null
;
}
if
(
LivePKtime_timer
[
pkuid
]){
clearInterval
(
LivePKtime_timer
[
pkuid
]);
LivePKtime_timer
[
pkuid
]
=
null
;
}
if
(
LivePHtime_timer
[
pkuid
]){
clearInterval
(
LivePHtime_timer
[
pkuid
]);
LivePHtime_timer
[
pkuid
]
=
null
;
}
/* 清除连麦信息 */
endLiveConnect
(
io
,
socket
.
uid
);
}
else
{
...
...
@@ -585,6 +612,9 @@ io.on('connection', function(socket) {
clientRedis
.
hset
(
'LivePK_gift'
,
socket
.
uid
,
0
);
clientRedis
.
hset
(
'LivePK_gift'
,
pkuid
,
0
);
var
time
=
Math
.
floor
(
(
new
Date
()).
getTime
()
/
1000
);
var
phtime
=
time
+
7
*
60
;
//PK结束、开始惩罚时间
var
phetime
=
phtime
+
1.5
*
60
;
//惩罚结束时间
/* 发送连麦成功信息 */
/* 当前房间 */
var
data_obj
=
{
...
...
@@ -595,7 +625,9 @@ io.on('connection', function(socket) {
"msgtype"
:
"10"
,
"pkuid"
:
""
+
pkuid
,
"uid"
:
""
+
socket
.
uid
,
"uname"
:
""
+
socket
.
nicename
"uname"
:
""
+
socket
.
nicename
,
"time"
:
""
+
time
,
//当前时间
"pktime"
:
""
+
phtime
//pk结束时间
}
],
"retcode"
:
"000000"
,
...
...
@@ -612,7 +644,9 @@ io.on('connection', function(socket) {
"msgtype"
:
"10"
,
"pkuid"
:
""
+
socket
.
uid
,
"uid"
:
""
+
socket
.
uid
,
"uname"
:
""
+
socket
.
nicename
"uname"
:
""
+
socket
.
nicename
,
"time"
:
""
+
time
,
//当前时间
"pktime"
:
""
+
phtime
//pk结束时间
}
],
"retcode"
:
"000000"
,
...
...
@@ -624,18 +658,112 @@ io.on('connection', function(socket) {
LivePK_timer
[
socket
.
uid
]
=
null
;
var
time
=
Math
.
floor
(
(
new
Date
()).
getTime
()
/
1000
);
clearTimeout
(
LivePH_timer
[
socket
.
uid
]);
LivePH_timer
[
socket
.
uid
]
=
null
;
clearInterval
(
LivePKtime_timer
[
socket
.
uid
]);
LivePKtime_timer
[
socket
.
uid
]
=
null
;
clearInterval
(
LivePHtime_timer
[
socket
.
uid
]);
LivePHtime_timer
[
socket
.
uid
]
=
null
;
//console.log('LivePK_timer_'+socket.uid+'___'+pkuid);
//console.log('LivePK_timer');
//console.log(time);
//当前主播和发起主播的PK时间和惩罚时间
clientRedis
.
hset
(
'LivePK_timer'
,
socket
.
uid
,
time
);
clientRedis
.
hset
(
'LivePK_timer'
,
pkuid
,
time
);
clientRedis
.
hset
(
'LivePH_timer'
,
socket
.
uid
,
phtime
);
clientRedis
.
hset
(
'LivePH_timer'
,
pkuid
,
phtime
);
//惩罚定时器
LivePH_timer
[
socket
.
uid
]
=
setTimeout
(
function
()
{
//定时设置惩罚时间为0
//惩罚结束时清除PK礼物信息1-07修改
LivePK_gift
[
socket
.
uid
]
=
0
;
LivePK_gift
[
pkuid
]
=
0
;
clientRedis
.
hset
(
'LivePK_gift'
,
socket
.
uid
,
0
);
clientRedis
.
hset
(
'LivePK_gift'
,
pkuid
,
0
);
clientRedis
.
hset
(
'LivePH_timer'
,
socket
.
uid
,
0
);
if
(
LivePH_timer
[
socket
.
uid
]){
clearTimeout
(
LivePH_timer
[
socket
.
uid
]);
LivePH_timer
[
socket
.
uid
]
=
null
;
}
},
7.5
*
60
*
1000
);
//pk惩罚结束时间
LivePKtime_timer
[
socket
.
uid
]
=
setInterval
(
function
()
{
//定时发送结果
var
leftTime
=
phtime
-
Math
.
floor
(
(
new
Date
()).
getTime
()
/
1000
);
//计算剩余的毫秒数
var
minutes
=
parseInt
(
leftTime
/
60
%
60
,
10
);
//计算剩余的分钟
var
seconds
=
parseInt
(
leftTime
%
60
,
10
);
//计算剩余的秒数
minutes
=
checkTime1
(
minutes
);
seconds
=
checkTime1
(
seconds
);
if
(
minutes
>=
0
||
seconds
>=
0
)
PKTimer
=
{
'status'
:
'ok'
,
'min'
:
minutes
,
'sec'
:
seconds
};
if
(
minutes
<=
0
&&
seconds
<=
0
)
{
clearInterval
(
LivePKtime_timer
[
socket
.
uid
]);
LivePKtime_timer
[
socket
.
uid
]
=
null
;
PKTimer
=
{
'status'
:
'end'
,
'min'
:
'00'
,
'sec'
:
'00'
};
}
// io.sockets.in(socket.roomnum).emit("pktime", [PKTimer]);
// io.sockets.in(pkuid).emit("pktime", [PKTimer]);
//process_msg(io,socket.roomnum,JSON.stringify(PKTimer));
//process_msg(io,pkuid,JSON.stringify(PKTimer));
//sockets[uid].emit('pktime',[PKTimer]);
},
1000
);
LivePK_timer
[
socket
.
uid
]
=
setTimeout
(
function
()
{
//定时发送结果
LivePHtime_timer
[
socket
.
uid
]
=
setInterval
(
function
()
{
//定时发送结果
var
leftTime
=
phetime
-
Math
.
floor
(
(
new
Date
()).
getTime
()
/
1000
);
//计算剩余的毫秒数
var
minutes
=
parseInt
(
leftTime
/
60
%
60
,
10
);
//计算剩余的分钟
var
seconds
=
parseInt
(
leftTime
%
60
,
10
);
//计算剩余的秒数
minutes
=
checkTime1
(
minutes
);
seconds
=
checkTime1
(
seconds
);
if
(
minutes
>=
0
||
seconds
>=
0
)
PHTimer
=
{
'status'
:
'ok'
,
'min'
:
minutes
,
'sec'
:
seconds
};
if
(
minutes
<=
0
&&
seconds
<=
0
)
{
clearInterval
(
LivePHtime_timer
[
socket
.
uid
]);
LivePHtime_timer
[
socket
.
uid
]
=
null
;
PHTimer
=
{
'status'
:
'end'
,
'min'
:
'00'
,
'sec'
:
'00'
};
}
// io.sockets.in(socket.roomnum).emit("phtime", [PHTimer]);
// io.sockets.in(pkuid).emit("phtime", [PHTimer]);
//io.sockets.in(data['roomnum']).emit("broadcastingListen", ['stopplay']);
//process_msg(io,socket.roomnum,JSON.stringify(PHTimer));
//process_msg(io,pkuid,JSON.stringify(PHTimer));
// sockets[pkuid].emit('phtime',[PHTimer]);
// sockets[uid].emit('phtime',[PHTimer]);
},
1000
);
endLivePk
(
io
,
socket
.
uid
,
0
);
},
7
*
60
*
1000
);
},
5
*
60
*
1000
);
//5*60*1000
}
else
if
(
action
==
'5'
){
if
(
LivePKtime_timer
[
socket
.
uid
]){
clearInterval
(
LivePKtime_timer
[
socket
.
uid
]);
LivePKtime_timer
[
socket
.
uid
]
=
null
;
}
if
(
LivePHtime_timer
[
socket
.
uid
]){
clearInterval
(
LivePHtime_timer
[
socket
.
uid
]);
LivePHtime_timer
[
socket
.
uid
]
=
null
;
}
if
(
LivePKtime_timer
[
pkuid
]){
clearInterval
(
LivePKtime_timer
[
pkuid
]);
LivePKtime_timer
[
pkuid
]
=
null
;
}
if
(
LivePHtime_timer
[
pkuid
]){
clearInterval
(
LivePHtime_timer
[
pkuid
]);
LivePHtime_timer
[
pkuid
]
=
null
;
}
/* 清除PK信息 */
endLivePk
(
io
,
socket
.
uid
,
1
);
}
else
{
...
...
@@ -818,6 +946,7 @@ io.on('connection', function(socket) {
//资源释放
socket
.
on
(
'disconnect'
,
function
()
{
console
.
log
(
'disconnect:'
+
socket
.
uid
+
' '
+
socket
.
token
+
' '
+
socket
.
roomnum
);
/* numscount--;
if(numscount<0){
numscount=0;
...
...
@@ -1057,7 +1186,16 @@ function endLivePk(io,uid,type){
clearTimeout
(
LivePK_timer
[
pkuid
]);
LivePK_timer
[
pkuid
]
=
null
;
}
//清除计时
// if(LivePKtime_timer[uid]){
// clearInterval(LivePKtime_timer[uid]);
// LivePKtime_timer[uid]=null;
// }
// if(LivePKtime_timer[pkuid]){
// clearInterval(LivePKtime_timer[pkuid]);
// LivePKtime_timer[pkuid]=null;
// }
//clearInterval(LivePKtime_timer[socket.uid]);
if
(
type
==
1
){
win_uid
=
pkuid
;
}
else
if
(
end_gift_uid
>
end_gift_pkuid
){
...
...
@@ -1070,8 +1208,8 @@ function endLivePk(io,uid,type){
LivePK
[
uid
]
=
0
;
LivePK
[
pkuid
]
=
0
;
LivePK_gift
[
uid
]
=
0
;
LivePK_gift
[
pkuid
]
=
0
;
//
LivePK_gift[uid]=0;
//
LivePK_gift[pkuid]=0;
// console.log('endLivePk');
// console.log(type);
...
...
@@ -1085,9 +1223,11 @@ function endLivePk(io,uid,type){
clientRedis
.
hset
(
'LivePK'
,
uid
,
0
);
clientRedis
.
hset
(
'LivePK'
,
pkuid
,
0
);
clientRedis
.
hset
(
'LivePK_gift'
,
uid
,
0
);
clientRedis
.
hset
(
'LivePK_gift'
,
pkuid
,
0
);
// clientRedis.hset('LivePK_gift',uid,0);
// clientRedis.hset('LivePK_gift',pkuid,0);
var
time
=
Math
.
floor
(
(
new
Date
()).
getTime
()
/
1000
);
var
phetime
=
time
+
1.5
*
60
;
//惩罚结束时间
//var phetime = phtime+0.5*60;//惩罚结束时间
var
data_obj
=
{
"msg"
:[
{
...
...
@@ -1096,7 +1236,9 @@ function endLivePk(io,uid,type){
"msgtype"
:
"10"
,
"win_uid"
:
""
+
win_uid
,
"uid"
:
""
+
uid
,
"uname"
:
""
"uname"
:
""
,
"time"
:
""
+
time
,
"phetime"
:
""
+
phetime
}
],
"retcode"
:
"000000"
,
...
...
@@ -1130,3 +1272,10 @@ function setSign(obj) {//排序的函数
var
sign
=
md5
(
str
);
return
sign
;
}
//将0-9的数字前面加上0,例1变为01,计时用
function
checkTime1
(
i
)
{
if
(
i
<
10
)
{
i
=
"0"
+
i
;
}
return
i
;
}
api/Appapi/Api/Live.php
View file @
65e62503
...
...
@@ -1059,12 +1059,13 @@ class Api_Live extends PhalApi_Api {
/* 主播连麦 */
$pkinfo
=
array
(
'pkuid'
=>
'0'
,
'pkpull'
=>
'0'
,
'ifpk'
=>
'0'
,
'pk_time'
=>
'0'
,
'pk_gift_liveuid'
=>
'0'
,
'pk_gift_pkuid'
=>
'0'
,
'pkuid'
=>
'0'
,
'pkpull'
=>
'0'
,
'ifpk'
=>
'0'
,
'pk_time'
=>
'0'
,
'ph_time'
=>
'0'
,
'pk_gift_liveuid'
=>
'0'
,
'pk_gift_pkuid'
=>
'0'
,
);
$pkuid
=
DI
()
->
redis
->
hGet
(
'LiveConnect'
,
$liveuid
);
// file_put_contents('./LiveConnect.txt',date('Y-m-d H:i:s').' 提交参数信息 pkuid:'.json_encode($pkuid)."\r\n",FILE_APPEND);
...
...
@@ -1074,6 +1075,17 @@ class Api_Live extends PhalApi_Api {
$pkpull
=
DI
()
->
redis
->
hGet
(
'LiveConnect_pull'
,
$pkuid
);
// file_put_contents('./LiveConnect.txt',date('Y-m-d H:i:s').' 提交参数信息 pkpull:'.json_encode($pkpull)."\r\n",FILE_APPEND);
$pkinfo
[
'pkpull'
]
=
$this
->
getPullWithSign
(
$pkpull
);
$ph_time
=
DI
()
->
redis
->
hGet
(
'LivePH_timer'
,
$liveuid
);
$nowtime
=
time
();
if
(
!
$ph_time
)
{
//开始惩罚时间
$ph_time
=
DI
()
->
redis
->
hGet
(
'LivePH_timer'
,
$pkuid
);
}
if
(
$ph_time
&&
$ph_time
>
0
&&
$ph_time
<
$nowtime
)
{
$chb
=
2.5
*
60
-
(
$nowtime
-
$ph_time
);
$pkinfo
[
'ph_time'
]
=
(
string
)
$chb
;
//惩罚剩余时间
}
$ifpk
=
DI
()
->
redis
->
hGet
(
'LivePK'
,
$liveuid
);
if
(
$ifpk
){
$pkinfo
[
'ifpk'
]
=
'1'
;
...
...
@@ -1081,7 +1093,7 @@ class Api_Live extends PhalApi_Api {
if
(
!
$pk_time
){
$pk_time
=
DI
()
->
redis
->
hGet
(
'LivePK_timer'
,
$pkuid
);
}
$nowtime
=
time
();
//
$nowtime=time();
if
(
$pk_time
&&
$pk_time
>
0
&&
$pk_time
<
$nowtime
){
$cha
=
7
*
60
-
(
$nowtime
-
$pk_time
);
$pkinfo
[
'pk_time'
]
=
(
string
)
$cha
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment