Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
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
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
c0ec257e
Commit
c0ec257e
authored
Jun 05, 2023
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate port-finder.js to TypeScript
parent
b069ee7f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
19 deletions
+21
-19
port-finder.ts
src/shared/messaging/port-finder.ts
+21
-19
No files found.
src/shared/messaging/port-finder.
j
s
→
src/shared/messaging/port-finder.
t
s
View file @
c0ec257e
import
type
{
Destroyable
}
from
'../../types/annotator'
;
import
{
ListenerCollection
}
from
'../listener-collection'
;
import
{
ListenerCollection
}
from
'../listener-collection'
;
import
{
generateHexString
}
from
'../random'
;
import
{
generateHexString
}
from
'../random'
;
import
{
isMessageEqual
}
from
'./port-util'
;
import
{
isMessageEqual
}
from
'./port-util'
;
import
type
{
Frame
}
from
'./port-util'
;
/** Timeout for waiting for the host frame to respond to a port request. */
/** Timeout for waiting for the host frame to respond to a port request. */
export
const
MAX_WAIT_FOR_PORT
=
1000
*
20
;
export
const
MAX_WAIT_FOR_PORT
=
1000
*
20
;
...
@@ -8,28 +10,29 @@ export const MAX_WAIT_FOR_PORT = 1000 * 20;
...
@@ -8,28 +10,29 @@ export const MAX_WAIT_FOR_PORT = 1000 * 20;
/** Polling interval for requests to the host frame for a port. */
/** Polling interval for requests to the host frame for a port. */
export
const
POLLING_INTERVAL_FOR_PORT
=
250
;
export
const
POLLING_INTERVAL_FOR_PORT
=
250
;
/**
export
type
Options
=
{
* @typedef {import('../../types/annotator').Destroyable} Destroyable
/** The role of this frame. */
* @typedef {import('./port-util').Message} Message
source
:
Exclude
<
Frame
,
'host'
>
;
* @typedef {import('./port-util').Frame} Frame
*/
/** Identifier for this frame. */
sourceId
?:
string
;
/** The frame where the `PortProvider` is listening for messages. */
hostFrame
:
Window
;
};
/**
/**
* PortFinder is used by non-host frames in the client to establish a
* PortFinder is used by non-host frames in the client to establish a
* MessagePort-based connection to other frames. It is used together with
* MessagePort-based connection to other frames. It is used together with
* PortProvider which runs in the host frame. See PortProvider for an overview.
* PortProvider which runs in the host frame. See PortProvider for an overview.
*
* @implements {Destroyable}
*/
*/
export
class
PortFinder
{
export
class
PortFinder
implements
Destroyable
{
/**
private
_hostFrame
:
Window
;
* @param {object} options
private
_listeners
:
ListenerCollection
;
* @param {Exclude<Frame, 'host'>} options.source - the role of this frame
private
_source
:
Exclude
<
Frame
,
'host'
>
;
* @param {string} [options.sourceId] - Identifier for this frame
private
_sourceId
:
string
|
undefined
;
* @param {Window} options.hostFrame - the frame where the `PortProvider` is
* listening for messages.
constructor
({
hostFrame
,
source
,
sourceId
}:
Options
)
{
*/
constructor
({
hostFrame
,
source
,
sourceId
})
{
this
.
_hostFrame
=
hostFrame
;
this
.
_hostFrame
=
hostFrame
;
this
.
_source
=
source
;
this
.
_source
=
source
;
this
.
_sourceId
=
sourceId
;
this
.
_sourceId
=
sourceId
;
...
@@ -43,10 +46,9 @@ export class PortFinder {
...
@@ -43,10 +46,9 @@ export class PortFinder {
/**
/**
* Request a specific port from the host frame
* Request a specific port from the host frame
*
*
* @param {Frame} target - the frame aiming to be discovered
* @param target - the frame aiming to be discovered
* @return {Promise<MessagePort>}
*/
*/
async
discover
(
target
)
{
async
discover
(
target
:
Frame
):
Promise
<
MessagePort
>
{
let
isValidRequest
=
false
;
let
isValidRequest
=
false
;
if
(
if
(
(
this
.
_source
===
'guest'
&&
target
===
'host'
)
||
(
this
.
_source
===
'guest'
&&
target
===
'host'
)
||
...
...
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