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
{
generateHexString
}
from
'../random'
;
import
{
isMessageEqual
}
from
'./port-util'
;
import
type
{
Frame
}
from
'./port-util'
;
/** Timeout for waiting for the host frame to respond to a port request. */
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. */
export
const
POLLING_INTERVAL_FOR_PORT
=
250
;
/**
* @typedef {import('../../types/annotator').Destroyable} Destroyable
* @typedef {import('./port-util').Message} Message
* @typedef {import('./port-util').Frame} Frame
*/
export
type
Options
=
{
/** The role of this frame. */
source
:
Exclude
<
Frame
,
'host'
>
;
/** 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
* MessagePort-based connection to other frames. It is used together with
* PortProvider which runs in the host frame. See PortProvider for an overview.
*
* @implements {Destroyable}
*/
export
class
PortFinder
{
/**
* @param {object} options
* @param {Exclude<Frame, 'host'>} options.source - the role of this frame
* @param {string} [options.sourceId] - Identifier for this frame
* @param {Window} options.hostFrame - the frame where the `PortProvider` is
* listening for messages.
*/
constructor
({
hostFrame
,
source
,
sourceId
})
{
export
class
PortFinder
implements
Destroyable
{
private
_hostFrame
:
Window
;
private
_listeners
:
ListenerCollection
;
private
_source
:
Exclude
<
Frame
,
'host'
>
;
private
_sourceId
:
string
|
undefined
;
constructor
({
hostFrame
,
source
,
sourceId
}:
Options
)
{
this
.
_hostFrame
=
hostFrame
;
this
.
_source
=
source
;
this
.
_sourceId
=
sourceId
;
...
...
@@ -43,10 +46,9 @@ export class PortFinder {
/**
* Request a specific port from the host frame
*
* @param {Frame} target - the frame aiming to be discovered
* @return {Promise<MessagePort>}
* @param target - the frame aiming to be discovered
*/
async
discover
(
target
)
{
async
discover
(
target
:
Frame
):
Promise
<
MessagePort
>
{
let
isValidRequest
=
false
;
if
(
(
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