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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FrameIT
Unity Webview
Commits
52ace640
Verified
Commit
52ace640
authored
1 year ago
by
Björn Eßwein
Browse files
Options
Downloads
Patches
Plain Diff
made sendWsMessage callable without coroutine
parent
9b78d579
No related branches found
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
+33
-15
33 additions, 15 deletions
Runtime/ChromeDevtools/BrowserTab.cs
with
33 additions
and
15 deletions
Runtime/ChromeDevtools/BrowserTab.cs
+
33
−
15
View file @
52ace640
...
@@ -9,6 +9,7 @@ using System.IO;
...
@@ -9,6 +9,7 @@ using System.IO;
using
System.Net.WebSockets
;
using
System.Net.WebSockets
;
using
System.Text
;
using
System.Text
;
using
System.Threading
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
UnityEngine
;
using
UnityEngine
;
namespace
ChromeDevTools
namespace
ChromeDevTools
...
@@ -45,6 +46,7 @@ namespace ChromeDevTools
...
@@ -45,6 +46,7 @@ namespace ChromeDevTools
/// <summary>
/// <summary>
/// Coroutine wrapper for _SendWsMessagel
/// json serializes and sends a command over the devtools websocket
/// json serializes and sends a command over the devtools websocket
/// </summary>
/// </summary>
/// <typeparam name="T">IDevtoolsCommand</typeparam>
/// <typeparam name="T">IDevtoolsCommand</typeparam>
...
@@ -58,6 +60,25 @@ namespace ChromeDevTools
...
@@ -58,6 +60,25 @@ namespace ChromeDevTools
yield
return
new
WaitUntil
(()
=>
ws
.
State
==
WebSocketState
.
Open
);
yield
return
new
WaitUntil
(()
=>
ws
.
State
==
WebSocketState
.
Open
);
}
}
var
sendTask
=
_SendWsMessage
(
command
,
callback
);
// wait until the command has been send
yield
return
new
WaitUntil
(()
=>
sendTask
.
IsCompleted
);
}
/// <summary>
/// json serializes and sends a command over the devtools websocket
/// </summary>
/// <typeparam name="T">IDevtoolsCommand</typeparam>
/// <param name="command"></param>
/// <returns>Task that resoves then the command is send</returns>
private
async
Task
_SendWsMessage
<
T
>(
T
command
,
System
.
Action
<
IDevtoolsResponse
>
callback
)
where
T
:
IDevtoolsCommand
{
// wait if the websocket is not yet open
if
(
ws
.
State
!=
WebSocketState
.
Open
)
{
throw
new
InvalidOperationException
(
"Websocket is not open"
);
}
// apply the message wrapper
// apply the message wrapper
var
wrappedCommand
=
new
DevtoolsCommandWrapper
<
T
>(
command
);
var
wrappedCommand
=
new
DevtoolsCommandWrapper
<
T
>(
command
);
...
@@ -76,11 +97,8 @@ namespace ChromeDevTools
...
@@ -76,11 +97,8 @@ namespace ChromeDevTools
// json serialize the command and send it
// json serialize the command and send it
var
json
=
JsonConvert
.
SerializeObject
(
wrappedCommand
,
Browser
.
serializerSettings
);
var
json
=
JsonConvert
.
SerializeObject
(
wrappedCommand
,
Browser
.
serializerSettings
);
UnityEngine
.
Debug
.
Log
(
$"ws send: '
{
json
}
'"
);
Debug
.
Log
(
$"ws send: '
{
json
}
'"
);
var
sendTask
=
ws
.
SendAsync
(
Encoding
.
UTF8
.
GetBytes
(
json
),
WebSocketMessageType
.
Text
,
true
,
Browser
.
cancellationTokenSource
.
Token
);
await
ws
.
SendAsync
(
Encoding
.
UTF8
.
GetBytes
(
json
),
WebSocketMessageType
.
Text
,
true
,
Browser
.
cancellationTokenSource
.
Token
);
// wait until the command has been send
yield
return
new
WaitUntil
(()
=>
sendTask
.
IsCompleted
);
}
}
/// <summary>
/// <summary>
...
@@ -180,7 +198,7 @@ namespace ChromeDevTools
...
@@ -180,7 +198,7 @@ namespace ChromeDevTools
{
{
Debug
.
Log
(
$"BrowserTab close called for: '
{
pageTarget
.
Url
}
'"
);
Debug
.
Log
(
$"BrowserTab close called for: '
{
pageTarget
.
Url
}
'"
);
//TODO: fix SendWsMessage without coroutine
//TODO: fix SendWsMessage without coroutine
SendWsMessage
(
new
closeTarget
(
pageTarget
.
Id
),
delegate
_
=
_
SendWsMessage
(
new
closeTarget
(
pageTarget
.
Id
),
delegate
{
{
ws
.
CloseAsync
(
WebSocketCloseStatus
.
NormalClosure
,
"tab closed"
,
CancellationToken
.
None
)
ws
.
CloseAsync
(
WebSocketCloseStatus
.
NormalClosure
,
"tab closed"
,
CancellationToken
.
None
)
.
ContinueWith
(
delegate
.
ContinueWith
(
delegate
...
...
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