Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
Unity Webview
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FrameIT
Unity Webview
Commits
b2a5aec0
Verified
Commit
b2a5aec0
authored
1 year ago
by
Björn Eßwein
Browse files
Options
Downloads
Patches
Plain Diff
read the whole websoket message in one async call
parent
ed530a89
Branches
dependabot/nuget/source/Sample/Newtonsoft.Json-13.0.1
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
Runtime/ChromeDevtools/BrowserTab.cs
+35
-30
35 additions, 30 deletions
Runtime/ChromeDevtools/BrowserTab.cs
with
35 additions
and
30 deletions
Runtime/ChromeDevtools/BrowserTab.cs
+
35
−
30
View file @
b2a5aec0
...
@@ -39,7 +39,7 @@ namespace ChromeDevTools
...
@@ -39,7 +39,7 @@ namespace ChromeDevTools
// open remote devtools websocket connection
// open remote devtools websocket connection
/**
/**
* Note: Forebg
w
l compatibility you need to use the JavaScript plugin, see also https://docs.unity3d.com/Manual/webgl-networking.html#UsingWebSockets
* Note: For
w
ebgl compatibility you need to use the JavaScript plugin, see also https://docs.unity3d.com/Manual/webgl-networking.html#UsingWebSockets
*/
*/
ws
.
ConnectAsync
(
new
Uri
(
pageTarget
.
WebSocketDebuggerUrl
),
Browser
.
cancellationTokenSource
.
Token
);
ws
.
ConnectAsync
(
new
Uri
(
pageTarget
.
WebSocketDebuggerUrl
),
Browser
.
cancellationTokenSource
.
Token
);
}
}
...
@@ -116,8 +116,8 @@ namespace ChromeDevTools
...
@@ -116,8 +116,8 @@ namespace ChromeDevTools
// start the message receive loop (it will exit when the coroutine is stopped)
// start the message receive loop (it will exit when the coroutine is stopped)
while
(
true
)
while
(
true
)
{
{
string
msgString
;
async
Task
<
string
>
read
()
{
// create a MemoryStream to reconstruct the message
// create a MemoryStream to reconstruct the message
using
(
var
ms
=
new
MemoryStream
())
using
(
var
ms
=
new
MemoryStream
())
{
{
...
@@ -129,28 +129,33 @@ namespace ChromeDevTools
...
@@ -129,28 +129,33 @@ namespace ChromeDevTools
do
do
{
{
var
messageBuffer
=
WebSocket
.
CreateClientBuffer
(
1024
,
16
);
var
messageBuffer
=
WebSocket
.
CreateClientBuffer
(
1024
,
16
);
var
reseiveTask
=
ws
.
ReceiveAsync
(
messageBuffer
,
Browser
.
cancellationTokenSource
.
Token
);
result
=
await
ws
.
ReceiveAsync
(
messageBuffer
,
Browser
.
cancellationTokenSource
.
Token
);
// yield the coroutine until the async Task "reseiveTask" is completed
yield
return
new
WaitUntil
(()
=>
reseiveTask
.
IsCompleted
);
result
=
reseiveTask
.
Result
;
// write the messageBuffer to the MemoryStream
// write the messageBuffer to the MemoryStream
ms
.
Write
(
messageBuffer
.
Array
,
messageBuffer
.
Offset
,
result
.
Count
);
ms
.
Write
(
messageBuffer
.
Array
,
messageBuffer
.
Offset
,
result
.
Count
);
}
}
while
(!
result
.
EndOfMessage
);
while
(!
result
.
EndOfMessage
);
// If the webSocket message type isn't text ignore this message
// If the webSocket message type isn't text ignore this message
if
(!(
result
.
MessageType
==
WebSocketMessageType
.
Text
))
if
(!(
result
.
MessageType
==
WebSocketMessageType
.
Text
))
{
{
Debug
.
LogError
(
$"Unexpected WebSocketMessageType:
{
result
.
MessageType
}
"
);
Debug
.
LogError
(
$"Unexpected WebSocketMessageType:
{
result
.
MessageType
}
"
);
continue
;
return
await
read
()
;
}
}
// convert the message stream to string
// convert the message stream to string
msgString
=
Encoding
.
UTF8
.
GetString
(
ms
.
ToArray
());
return
Encoding
.
UTF8
.
GetString
(
ms
.
ToArray
());
Debug
.
Log
(
$"ws reseived: '
{
msgString
}
'"
);
}
}
}
var
readTask
=
read
();
// yield the coroutine until the async Task "reseiveTask" is completed
yield
return
new
WaitUntil
(()
=>
readTask
.
IsCompleted
);
string
msgString
=
readTask
.
Result
;
Debug
.
Log
(
$"ws reseived: '
{
msgString
}
'"
);
// deserialize the devtools response wrapper
// deserialize the devtools response wrapper
var
response
=
JsonConvert
.
DeserializeObject
<
DevtoolsResponseWrapper
>(
msgString
,
Browser
.
serializerSettings
);
var
response
=
JsonConvert
.
DeserializeObject
<
DevtoolsResponseWrapper
>(
msgString
,
Browser
.
serializerSettings
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment