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
28f6e4d3
Commit
28f6e4d3
authored
Apr 15, 2022
by
Robert Knight
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing types in cross-origin-rpc.js
parent
66a89458
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
6 deletions
+29
-6
cross-origin-rpc.js
src/sidebar/cross-origin-rpc.js
+29
-6
No files found.
src/sidebar/cross-origin-rpc.js
View file @
28f6e4d3
...
...
@@ -6,14 +6,17 @@ import { normalizeGroupIds } from './helpers/groups';
* @typedef {import('../types/rpc').FocusUserInfo} FocusUserInfo
*/
// Array to keep track of pre-start requests
/**
* List of not-yet-processed messages received during application startup.
*
* @type {MessageEvent[]}
*/
let
preStartQueue
=
[];
/**
* Return the mapped methods that can be called remotely via this server.
*
* @param {object} store - The global store
* @return {object}
* @param {import('./store').SidebarStore} store - The global store
*/
const
registeredMethods
=
store
=>
{
return
{
...
...
@@ -31,10 +34,19 @@ const registeredMethods = store => {
};
};
/**
* @typedef JSONRPCMessage
* @prop {string} jsonrpc
* @prop {string} id
* @prop {string} method
* @prop {unknown[]} params
*/
/**
* Return true if `data` "looks like" a JSON-RPC message.
*
* @param {any} data
* @return {data is JSONRPCMessage}
*/
function
isJsonRpcMessage
(
data
)
{
// eslint-disable-next-line eqeqeq
...
...
@@ -62,9 +74,14 @@ function isJsonRpcMessage(data) {
* notifications) and sending back a successful "ok" response.
*
* All methods called upon must be mapped in the `registeredMethods` function.
*
* @param {import('./store').SidebarStore} store
* @param {import('../types/config').SidebarSettings} settings
* @param {Window} $window
* @inject
*/
// @inject
export
function
startServer
(
store
,
settings
,
$window
)
{
/** @type {Record<string, (...args: any[]) => void>} */
const
methods
=
registeredMethods
(
store
);
// Process the pre-start incoming RPC requests
...
...
@@ -78,6 +95,7 @@ export function startServer(store, settings, $window) {
// Start listening to new RPC requests
$window
.
addEventListener
(
'message'
,
receiveMessage
);
/** @param {MessageEvent} event */
function
receiveMessage
(
event
)
{
let
allowedOrigins
=
settings
.
rpcAllowedOrigins
||
[];
...
...
@@ -96,10 +114,15 @@ export function startServer(store, settings, $window) {
// data param.
let
jsonRpcRequest
=
event
.
data
;
event
.
source
.
postMessage
(
jsonRpcResponse
(
jsonRpcRequest
),
event
.
origin
);
const
source
=
/** @type {Window} */
(
event
.
source
);
source
.
postMessage
(
jsonRpcResponse
(
jsonRpcRequest
),
event
.
origin
);
}
/** Return a JSON-RPC response to the given JSON-RPC request object. */
/**
* Return a JSON-RPC response to the given JSON-RPC request object.
*
* @param {JSONRPCMessage} request
*/
function
jsonRpcResponse
(
request
)
{
const
method
=
methods
[
request
.
method
];
...
...
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