Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2dbec26

Browse files
committedJul 16, 2021
check to address
1 parent 961cec1 commit 2dbec26

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed
 

‎contracts/Signaling.sol

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pragma solidity >=0.7.0 <0.9.0;
2+
3+
contract Signaling {
4+
event Message(address indexed _from, address indexed _to, string _type, string _message);
5+
6+
function sendMessage(address to, string memory messageType, string memory message) public {
7+
emit Message(msg.sender, to, messageType, message);
8+
}
9+
}

‎src/hooks/useIncomingSignaling.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect } from "react";
22
import Signaling from "../contracts/Signaling";
3+
import web3 from "../utils/web3";
34

45
interface SignalingProps {
56
onAnswer: (message: string) => void;
@@ -14,25 +15,30 @@ export const useIncomingSignaling = ({
1415
}: SignalingProps) => {
1516
useEffect(() => {
1617
const fetch = async () => {
18+
const accounts = await web3.eth.getAccounts();
19+
1720
Signaling.events
1821
.Message()
1922
.on("connected", function (subscriptionId: any) {
2023
console.log(subscriptionId);
2124
})
2225
.on("data", function (event: any) {
2326
console.log(event);
27+
const to = event[1] as string;
2428
const type = event[2] as string;
2529
const message = event[3] as string;
26-
switch (type) {
27-
case "offer":
28-
onOffer(message);
29-
break;
30-
case "answer":
31-
onAnswer(message);
32-
break;
33-
case "ice":
34-
onIceCandidate(message);
35-
break;
30+
if (to === accounts[0]) {
31+
switch (type) {
32+
case "offer":
33+
onOffer(message);
34+
break;
35+
case "answer":
36+
onAnswer(message);
37+
break;
38+
case "ice":
39+
onIceCandidate(message);
40+
break;
41+
}
3642
}
3743
});
3844
};

0 commit comments

Comments
 (0)
Please sign in to comment.