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
Show 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';
...
@@ -6,14 +6,17 @@ import { normalizeGroupIds } from './helpers/groups';
* @typedef {import('../types/rpc').FocusUserInfo} FocusUserInfo
* @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
=
[];
let
preStartQueue
=
[];
/**
/**
* Return the mapped methods that can be called remotely via this server.
* Return the mapped methods that can be called remotely via this server.
*
*
* @param {object} store - The global store
* @param {import('./store').SidebarStore} store - The global store
* @return {object}
*/
*/
const
registeredMethods
=
store
=>
{
const
registeredMethods
=
store
=>
{
return
{
return
{
...
@@ -31,10 +34,19 @@ const registeredMethods = store => {
...
@@ -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.
* Return true if `data` "looks like" a JSON-RPC message.
*
*
* @param {any} data
* @param {any} data
* @return {data is JSONRPCMessage}
*/
*/
function
isJsonRpcMessage
(
data
)
{
function
isJsonRpcMessage
(
data
)
{
// eslint-disable-next-line eqeqeq
// eslint-disable-next-line eqeqeq
...
@@ -62,9 +74,14 @@ function isJsonRpcMessage(data) {
...
@@ -62,9 +74,14 @@ function isJsonRpcMessage(data) {
* notifications) and sending back a successful "ok" response.
* notifications) and sending back a successful "ok" response.
*
*
* All methods called upon must be mapped in the `registeredMethods` function.
* 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
)
{
export
function
startServer
(
store
,
settings
,
$window
)
{
/** @type {Record<string, (...args: any[]) => void>} */
const
methods
=
registeredMethods
(
store
);
const
methods
=
registeredMethods
(
store
);
// Process the pre-start incoming RPC requests
// Process the pre-start incoming RPC requests
...
@@ -78,6 +95,7 @@ export function startServer(store, settings, $window) {
...
@@ -78,6 +95,7 @@ export function startServer(store, settings, $window) {
// Start listening to new RPC requests
// Start listening to new RPC requests
$window
.
addEventListener
(
'message'
,
receiveMessage
);
$window
.
addEventListener
(
'message'
,
receiveMessage
);
/** @param {MessageEvent} event */
function
receiveMessage
(
event
)
{
function
receiveMessage
(
event
)
{
let
allowedOrigins
=
settings
.
rpcAllowedOrigins
||
[];
let
allowedOrigins
=
settings
.
rpcAllowedOrigins
||
[];
...
@@ -96,10 +114,15 @@ export function startServer(store, settings, $window) {
...
@@ -96,10 +114,15 @@ export function startServer(store, settings, $window) {
// data param.
// data param.
let
jsonRpcRequest
=
event
.
data
;
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
)
{
function
jsonRpcResponse
(
request
)
{
const
method
=
methods
[
request
.
method
];
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