-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/itublockchain/ethistanbul-h…
- Loading branch information
Showing
4 changed files
with
81 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
//yarn add @pushprotocol/restapi @pushprotocol/socket | ||
import { PushAPI, ethersV5SignerType, CONSTANTS } from "@pushprotocol/restapi"; | ||
import { ENV } from "@pushprotocol/restapi/src/lib/constants"; | ||
const env = ENV.STAGING; | ||
|
||
export const useChatStream = async (signer: ethersV5SignerType) => { | ||
const user = await PushAPI.initialize(signer, { env }); | ||
const stream = user.initStream([CONSTANTS.STREAM.CHAT], { | ||
filter: { | ||
channels: ['*'], // pass in specific channels to only listen to those | ||
chats: ['*'], // pass in specific chat ids to only listen to those | ||
}, | ||
connection: { | ||
retries: 3, // number of retries in case of error | ||
}, | ||
raw: false // enable true to show all data | ||
}) | ||
; (await stream).on(CONSTANTS.STREAM.CHAT, (data: any) => { | ||
console.log('chat data', data) | ||
return [data.from, data.content] | ||
} | ||
) | ||
; (await stream).connect() | ||
} | ||
|
||
export const useChatSend = async (message: string, signer: ethersV5SignerType, to: string) => { | ||
try { | ||
const user = await PushAPI.initialize(signer, { env }); | ||
await user.chat.send(to, { content: `${message}`, type: "Text" }) | ||
} | ||
catch (e) { | ||
console.log(e) | ||
throw e | ||
} | ||
} | ||
|
||
export const useChatList = async (signer: ethersV5SignerType) => { | ||
try { | ||
const user = await PushAPI.initialize(signer, { env }); | ||
const chats = await user.chat.list("CHATS") | ||
const mapped = chats.map((chat: any) => { | ||
return { | ||
address: chat.fromDID.split(":")[1], | ||
content: chat.messageContent | ||
} | ||
} | ||
) | ||
} catch (e) { | ||
console.log(e) | ||
throw e | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,24 @@ | ||
import { useState } from "react"; | ||
|
||
export default function Home() { | ||
return <></> | ||
} | ||
const [message, setMessage] = useState(""); | ||
|
||
return ( | ||
<> | ||
<div className="w-full flex flex-col h-[760px] justify-end gap-3"> | ||
<div className="px-48"> | ||
Deneme | ||
</div> | ||
<div className="w-full flex focus:outline-none gap-6 justify-center items-center"> | ||
<input | ||
className="flex gap-5 rounded-xl w-3/4 h-16 bg-white input-box px-4 text-[20px]" | ||
onChange={(e) => setMessage(e.currentTarget.value)} | ||
></input> | ||
<button className="w-[150px] h-[70px] bg-[#3DB9CF] rounded-xl"> | ||
Send | ||
</button> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} |