Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
N
Neos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Neos
Commits
6d6df46d
Commit
6d6df46d
authored
Oct 17, 2022
by
Chunchi Che
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add socket middleware
parent
55a8cd22
Pipeline
#17244
passed with stage
in 1 minute and 16 seconds
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
61 additions
and
4 deletions
+61
-4
src/main.tsx
src/main.tsx
+1
-1
src/middleware/socket.ts
src/middleware/socket.ts
+57
-0
src/ui/App.tsx
src/ui/App.tsx
+3
-3
No files found.
src/main.tsx
View file @
6d6df46d
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
ReactDOM
from
"
react-dom/client
"
;
import
ReactDOM
from
"
react-dom/client
"
;
import
App
from
"
./App
"
;
import
App
from
"
./
ui/
App
"
;
import
{
BrowserRouter
}
from
"
react-router-dom
"
;
import
{
BrowserRouter
}
from
"
react-router-dom
"
;
import
{
Provider
}
from
"
react-redux
"
;
import
{
Provider
}
from
"
react-redux
"
;
import
{
store
}
from
"
./store
"
;
import
{
store
}
from
"
./store
"
;
...
...
src/middleware/socket.ts
0 → 100644
View file @
6d6df46d
import
{
ygopro
}
from
"
../api/idl/ocgcore
"
;
export
enum
socketCmd
{
CONNECT
,
DISCONNECT
,
SEND
,
}
export
interface
socketAction
{
cmd
:
socketCmd
;
ip
?:
string
;
payload
?:
ygopro
.
YgoCtosMsg
;
}
let
ws
:
WebSocket
|
null
=
null
;
export
default
function
(
action
:
socketAction
)
{
switch
(
action
.
cmd
)
{
case
socketCmd
.
CONNECT
:
{
const
ip
=
action
.
ip
;
if
(
ip
)
{
ws
=
new
WebSocket
(
"
ws://
"
+
ip
);
ws
.
onopen
=
()
=>
{
console
.
log
(
"
WebSocket open.
"
);
};
ws
.
onclose
=
()
=>
{
console
.
log
(
"
WebSocket closed.
"
);
ws
=
null
;
};
ws
.
onmessage
=
(
e
)
=>
{
const
pb
=
ygopro
.
YgoStocMsg
.
deserializeBinary
(
e
.
data
);
// todo
};
}
break
;
}
case
socketCmd
.
DISCONNECT
:
{
if
(
ws
)
{
ws
.
close
();
}
break
;
}
case
socketCmd
.
SEND
:
{
const
pb
=
action
.
payload
;
if
(
ws
&&
pb
)
{
ws
.
send
(
pb
.
serialize
());
}
break
;
}
default
:
{
console
.
log
(
"
Unhandled socket command:
"
+
action
.
cmd
);
break
;
}
}
}
src/App.tsx
→
src/
ui/
App.tsx
View file @
6d6df46d
import
React
from
"
react
"
;
import
React
from
"
react
"
;
import
JoinRoom
from
"
./
ui/
JoinRoom
"
;
import
JoinRoom
from
"
./JoinRoom
"
;
import
WaitRoom
from
"
./
ui//
WaitRoom
"
;
import
WaitRoom
from
"
./WaitRoom
"
;
import
ThreeJs
from
"
./ThreeJs
"
;
import
ThreeJs
from
"
.
.
/ThreeJs
"
;
import
{
Routes
,
Route
}
from
"
react-router-dom
"
;
import
{
Routes
,
Route
}
from
"
react-router-dom
"
;
function
App
()
{
function
App
()
{
...
...
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