Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
kaisa
/
SopWeb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5986b19e
authored
Nov 19, 2025
by
kaisa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:更新
parent
3048b056
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
90 deletions
src/utils/ws/pkSocket.js
src/utils/ws/pkSocket.js
deleted
100644 → 0
View file @
3048b056
import
{
usePkStore
}
from
'@/stores/pkStore'
;
const
pkStore
=
usePkStore
();
function
url_get_params
(
url_path
)
{
let
url
=
url_path
;
let
theRequest
=
new
Object
();
if
(
url
.
indexOf
(
"?"
)
!=
-
1
)
{
let
str
=
url
.
substr
(
url
.
indexOf
(
"?"
)
+
1
);
strs
=
str
.
split
(
"&"
);
for
(
let
i
=
0
;
i
<
strs
.
length
;
i
++
)
{
theRequest
[
strs
[
i
].
split
(
"="
)[
0
]]
=
unescape
(
strs
[
i
].
split
(
"="
)[
1
]);
}
}
return
theRequest
;
}
let
wsTimer
=
null
;
let
wsReconnect
=
null
;
let
mUrlParam
=
url_get_params
(
location
.
href
);
pkStore
.
setMurlParam
(
mUrlParam
);
console
.
log
(
mUrlParam
,
'mUrlParam'
);
let
ws
=
null
;
export
function
WebSocketGo
()
{
/* 測試: ws://47.75.50.13:5300/ws */
/* 正式: wss://firefly-cloud-websocket.yabolive.net/ws */
ws
=
new
WebSocket
(
`
${
import
.
meta
.
env
.
VITE_APP_WS_URL
}
?type=4&uid=`
+
mUrlParam
.
uid
+
"&token=debug"
+
"&roomid="
+
mUrlParam
.
roomId
+
"&lang="
+
mUrlParam
.
lang
);
console
.
log
(
"建立链接"
);
pkStore
.
setWsLocation
(
"WS建立连接中..."
)
ws
.
onopen
=
function
()
{
clearInterval
(
wsReconnect
);
clearInterval
(
wsTimer
);
wsTimer
=
setInterval
(
function
()
{
heartbeat
();
},
4500
);
};
ws
.
onmessage
=
function
(
event
)
{
let
msg
=
JSON
.
parse
(
event
.
data
);
console
.
log
(
"推流"
,
msg
);
// 存储游戏推流数据
if
(
msg
.
content
)
{
const
parseData
=
JSON
.
parse
(
msg
.
content
);
if
(
parseData
.
wsdata
)
{
pkStore
.
setGameData
(
JSON
.
parse
(
msg
.
content
).
wsdata
);
}
}
};
ws
.
onclose
=
function
(
error
)
{
clearInterval
(
wsReconnect
);
wsReconnect
=
setInterval
(
function
()
{
console
.
log
(
"断了"
,
error
);
pkStore
.
setWsLocation
(
"WS断开连接..."
)
WebSocketGo
();
},
3000
);
};
function
heartbeat
()
{
if
(
ws
.
readyState
==
WebSocket
.
OPEN
)
{
pkStore
.
setWsLocation
(
"WS发送心跳..."
)
var
msg
=
new
WsMsg
(
1000
,
"ping"
,
0
,
mUrlParam
.
uid
);
ws
.
send
(
JSON
.
stringify
(
msg
));
}
}
function
WsMsg
(
cid
,
content
,
extend
,
uid
)
{
this
.
time
=
new
Date
().
getTime
();
this
.
msgid
=
Math
.
random
().
toString
(
36
).
slice
(
-
8
);
this
.
cid
=
cid
;
this
.
content
=
content
;
this
.
extend
=
extend
;
this
.
uid
=
uid
;
}
}
export
function
closeWebSocket
()
{
if
(
ws
)
{
clearInterval
(
wsTimer
);
clearInterval
(
wsReconnect
);
ws
.
close
();
ws
=
null
;
}
}
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