Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
L
luna
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
luna
Commits
3614e587
Commit
3614e587
authored
Jul 18, 2019
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Update] 添加ping机制
parent
5aac324e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
3 deletions
+13
-3
neffos.ts
src/app/utils/neffos.ts
+0
-0
socket.ts
src/app/utils/socket.ts
+13
-3
No files found.
src/app/utils/neffos.ts
0 → 100755
View file @
3614e587
This diff is collapsed.
Click to expand it.
src/app/utils/socket.ts
View file @
3614e587
...
...
@@ -22,16 +22,24 @@ export class Socket {
}
}
export
async
function
getWsSock
(
url
:
string
,
namespace
:
string
):
Promise
<
Socket
>
{
const
emitter
=
new
EventEmitter
();
const
events
=
{};
const
events
=
{
};
let
interval
;
events
[
namespace
]
=
{
_OnNamespaceConnected
:
function
(
ns
,
msg
)
{
emitter
.
emit
(
'connect'
,
ns
);
interval
=
setInterval
(()
=>
ns
.
emit
(
'ping'
,
''
),
10000
);
},
_OnNamespaceDisconnect
:
function
(
ns
,
msg
)
{
emitter
.
emit
(
'disconnect'
,
ns
);
if
(
interval
)
{
clearInterval
(
interval
);
}
},
_OnRoomJoined
:
function
(
ns
,
msg
)
{
...
...
@@ -44,9 +52,11 @@ export async function getWsSock(url: string, namespace: string): Promise<Socket>
_OnAnyEvent
:
function
(
ns
,
msg
)
{
emitter
.
emit
(
msg
.
Event
,
msg
);
}
},
};
const
options
=
{
reconnect
:
5000
,
};
const
options
=
{
reconnect
:
5000
};
const
conn
=
<
neffos
.
Conn
>
await
neffos
.
dial
(
url
,
events
,
options
);
const
nsConn
=
<
neffos
.
NSConn
>
await
conn
.
connect
(
namespace
);
const
sock
=
new
Socket
(
nsConn
,
emitter
);
...
...
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