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
e7b406e9
Commit
e7b406e9
authored
May 11, 2022
by
Lyza Danger Gardner
Committed by
Lyza Gardner
May 16, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add JSON-RPC 2.0 notification support to client
parent
886e3c15
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
1 deletion
+38
-1
postmessage-json-rpc.js
src/sidebar/util/postmessage-json-rpc.js
+18
-0
postmessage-json-rpc-test.js
src/sidebar/util/test/postmessage-json-rpc-test.js
+20
-1
No files found.
src/sidebar/util/postmessage-json-rpc.js
View file @
e7b406e9
...
...
@@ -98,3 +98,21 @@ export function call(
throw
err
;
});
}
/**
* Send a JSON-RPC 2.0 notification request to another frame via `postMessage`.
* No response is expected.
*
* @param {Window} frame - Frame to send call to
* @param {string} origin - Origin filter for `window.postMessage` call
* @param {string} method - Name of the JSON-RPC method
* @param {unknown[]} params - Parameters of the JSON-RPC method
*/
export
function
notify
(
frame
,
origin
,
method
,
params
=
[])
{
const
request
=
{
jsonrpc
:
'2.0'
,
method
,
params
,
};
frame
.
postMessage
(
request
,
origin
);
}
src/sidebar/util/test/postmessage-json-rpc-test.js
View file @
e7b406e9
import
EventEmitter
from
'tiny-emitter'
;
import
{
call
,
$imports
}
from
'../postmessage-json-rpc'
;
import
{
call
,
notify
,
$imports
}
from
'../postmessage-json-rpc'
;
class
FakeWindow
{
constructor
()
{
...
...
@@ -14,6 +14,25 @@ describe('sidebar/util/postmessage-json-rpc', () => {
const
origin
=
'https://embedder.com'
;
const
messageId
=
42
;
describe
(
'notify'
,
()
=>
{
let
frame
;
beforeEach
(()
=>
{
frame
=
{
postMessage
:
sinon
.
stub
()
};
});
it
(
'should send a JSON-RPC 2.0 notification to the frame'
,
()
=>
{
notify
(
frame
,
origin
,
'testMethod'
,
[
1
,
2
,
3
]);
assert
.
calledOnce
(
frame
.
postMessage
);
assert
.
calledWith
(
frame
.
postMessage
,
{
jsonrpc
:
'2.0'
,
method
:
'testMethod'
,
params
:
[
1
,
2
,
3
],
});
});
});
describe
(
'call'
,
()
=>
{
let
frame
;
let
fakeWindow
;
...
...
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