Prajwal BM

785 posts

Prajwal BM banner
Prajwal BM

Prajwal BM

@xshadowdev

You will never be younger than today.

加入时间 Mayıs 2025
618 关注1.3K 粉丝
置顶推文
Prajwal BM
Prajwal BM@xshadowdev·
Tony Stark was able to build this in a cave, with a box of scraps. And I was able to build this in a room, with ASUS TUF15,i7 13Gen,16GB DDR5 RAM,RTX4060. (Not a scrap actually) (Disclaimer: The site is responsive but I recommend you to open in desktop) mark1-p86.vercel.app
English
145
68
659
46.1K
Prajwal BM
Prajwal BM@xshadowdev·
Small update: Updated the UI and added a feature to change the display name, and also learnt a concept called Stale Closure, read till the end to learn about it. - Today I coded with no internet, which made me give more time to think what logic am I writing and what the bug is happening, and how do I solve it. - Added a feature where the peer can change their name which will instantly update on every connected peer by updating it through websocket. Concept: Stale closure - occurs when a function captures an outdated variable from an old scope, failing to see updated values function Counter() { const [count, setCount] = React.useState(0); useEffect(() => { setInterval(() => { console.log("Count:", count); }, 2000); }, []); return ( ); } now you expect the count to go as 0,1,2,3,4,5 as you click. but it wont instead it will be 0,0,0,0 for ever, but why? when the component first renders, react runs the effect and the setinterval is created, but the funtion captures count as 0, even when react updatesthe state the internal callback still sees the initial value. replay with the solution. - I was using a zustand state variable inside a useeffect which ran on first component mount, now every time i used the variable inside the effect it was null, but zustand has a better way to solve it by using store.getState() as zustand store is not tied to react and can be accessed anywhere.
Prajwal BM tweet media
Prajwal BM@xshadowdev

DAY 2: worked on the client side ws connection. - I used to write inline code where I put the logic of ws connection in the useeffct and make a connection, but this had some downsides like ws instance being created on each rerender. - So I learnt and used a different code structure in the client side for the first time. I used oops structure to create a service class of ws, and used custom hooks to bridge the ws with a react component. By doing so we keep the main logic in the service class, and bridging logic in the hooks which run in components life cycle , used zustand for global state management and kept the react component purely UI. - Built a basic UI where it renders each peer connecting to the websocket server, right now im using different browser tabs as peer and they are grouped into a room automatically as they are in the same IP. - we can see that the peers appear on the screen with their random name and device type, where one peer can select the peer they want to share the data with. Next up: will add webrtc logic of ice candidates, stun servers and connect the peers to share the data with data channel.

English
1
0
13
401
Prajwal BM
Prajwal BM@xshadowdev·
DAY 2: worked on the client side ws connection. - I used to write inline code where I put the logic of ws connection in the useeffct and make a connection, but this had some downsides like ws instance being created on each rerender. - So I learnt and used a different code structure in the client side for the first time. I used oops structure to create a service class of ws, and used custom hooks to bridge the ws with a react component. By doing so we keep the main logic in the service class, and bridging logic in the hooks which run in components life cycle , used zustand for global state management and kept the react component purely UI. - Built a basic UI where it renders each peer connecting to the websocket server, right now im using different browser tabs as peer and they are grouped into a room automatically as they are in the same IP. - we can see that the peers appear on the screen with their random name and device type, where one peer can select the peer they want to share the data with. Next up: will add webrtc logic of ice candidates, stun servers and connect the peers to share the data with data channel.
Prajwal BM tweet media
Prajwal BM@xshadowdev

Got some time to continue my project ( actually begin ) Read this till the end I got some learnings to share which are amazing. DAY 1 : Initialized server (nodejs,ts,ws) and client(react,ts,zustand,websockets,webrtc). - Created the server side logic for room management and signaling with websockets. - Every client is a new Peer and on the websocket connection establishment they are grouped into rooms so that one peer is able to see other peers in the same room. - Basically room is used to group the peers so that they find each other in the particular room by joining a room. - Used signaling logic to send and broadcast the joining, leaving and finding new peer using websocket objects methods. next up - will implement client side and some message formats for communicating the offers and answers. Learnings : - I learnt the actual difference between using OOPs and function style. the core of it is not performance its about state control and architecture discipline. I knew about OPPS concept but this is my first time using it in action. - Why we had to choose Map over normal array and objects for room variable in the RoomManager object?. rooms: Map>. so why Map? lets say the rooms variable is an array of objects, every time you wanted to find a room, you would have to use .find() or a for loop. You have to check every single item. If you have 1,000 rooms and the one you want is at the end, you just did 1,000 operations. But in the Map you say rooms.get('101') and the computer goes instantly to that spot in memory. While Map and object both store key-value pair, but the key types in object is strictly string, and in Map it can be of any type. Using Map is a performance decision and it has better methods like .set() .get() .delete() and all. That's it for today will have some more learning on DAY 2.

English
4
0
17
924
Prajwal BM
Prajwal BM@xshadowdev·
Got some time to continue my project ( actually begin ) Read this till the end I got some learnings to share which are amazing. DAY 1 : Initialized server (nodejs,ts,ws) and client(react,ts,zustand,websockets,webrtc). - Created the server side logic for room management and signaling with websockets. - Every client is a new Peer and on the websocket connection establishment they are grouped into rooms so that one peer is able to see other peers in the same room. - Basically room is used to group the peers so that they find each other in the particular room by joining a room. - Used signaling logic to send and broadcast the joining, leaving and finding new peer using websocket objects methods. next up - will implement client side and some message formats for communicating the offers and answers. Learnings : - I learnt the actual difference between using OOPs and function style. the core of it is not performance its about state control and architecture discipline. I knew about OPPS concept but this is my first time using it in action. - Why we had to choose Map over normal array and objects for room variable in the RoomManager object?. rooms: Map>. so why Map? lets say the rooms variable is an array of objects, every time you wanted to find a room, you would have to use .find() or a for loop. You have to check every single item. If you have 1,000 rooms and the one you want is at the end, you just did 1,000 operations. But in the Map you say rooms.get('101') and the computer goes instantly to that spot in memory. While Map and object both store key-value pair, but the key types in object is strictly string, and in Map it can be of any type. Using Map is a performance decision and it has better methods like .set() .get() .delete() and all. That's it for today will have some more learning on DAY 2.
Prajwal BM tweet media
English
4
0
11
771
Aryan Srivastava
Aryan Srivastava@distroaryan·
@xshadowdev i am also trying to build a p2p network for file sharing and storage without any centralised server. 🤝
English
1
0
1
28
Prajwal BM
Prajwal BM@xshadowdev·
Will be building a project with the technology I learnt in the past few days, WebRTC and WebSockets. I want to build a file sharing system through browsers without needing to upload it to a server. Inspired by pairdrop[dot]net. And will add some more features later.
English
1
0
7
191
Prajwal BM
Prajwal BM@xshadowdev·
Today's Learning: websockets websockets - It’s a persistent, bidirectional TCP connection between client and server. No polling. No repeated HTTP requests. Just one open pipe. Its not just limited to chat applications, it is used in real time updates in treading, live data feed, multiplayer games, collaboration tools etc... Rooms logic - Rooms are NOT a WebSocket feature. They’re just server-side data structures. I learnt about Map and Set data structure along the way. - Map is just like an object with key: value pair where key can be any type and not just a string. - Set is a collection of unique values and it does not allow duplicates better then using an array where duplicates are common. - Learnt to use different websocket object methods like .on .send .onmessage .onconnection and many more to integrate a chat application Created a simple chat application, with rooms logic where user can past a room code and join the room to chat. Used native websockets on the client side and ws library on the server side with a simple http express for initial handshake.
English
1
0
19
433
SUMUKH
SUMUKH@iam_enginner·
@xshadowdev These concepts are so cool thanks for sharing such info
English
1
0
1
31
Prajwal BM
Prajwal BM@xshadowdev·
Today's Learning: Backpressure and data load handling. Backpressure - A feedback mechanism that allows a system to manage data flow when components produce data faster than they can consume it. Lets understand a scenario of file sharing : lets say you are about to send a 100GB file through web, your disk read speed is 500MB/s and your network upload speed is 50MB/s. So for every second 450MB of data is left "waiting" in the browser's RAM while your network is uploading 50MB. After 10 seconds : 4.5GB is waiting in RAM and this will cause the browser to crash due to out of memory. To solve this we can use Backpressure by checking channel.bufferedAmount in the WebRTC api, if the buffer is full, we pause the reading from the disk until the network catches up. In the below video I used some dummy junk data and tried uploading 100MB of data from one browser tab to another by using some defined chunkSize of 16kb where the data is shared in chunks, and bufferThreshold of 1MB and used a promise which pauses the data transmission until the bufferamount is drained and resolves after that. if (channel.bufferedAmount > BUFFER_THRESHHOLD){ await new Promise((resolve) => { channel.onbufferedamountlow = () => { channel.onbufferedamountlow = null; resolve(); }; }); }
English
2
0
20
454
SUMUKH
SUMUKH@iam_enginner·
building infinite castle from demon slayer in @threejs is this looking good 🤔
English
3
1
46
1.9K
CodeZee
CodeZee@Pritam27442834·
@xshadowdev Remeber to make it in dev doc maybe simple version of these things ice candidate exchange mediasoup stuffs..🫠🫠..I had Explored it but forget for lack of practice..
English
1
0
1
22
Prajwal BM
Prajwal BM@xshadowdev·
Before you read, just a quick Q. Is WebRTC an old technology to learn? ya its the era of AI and its in the trend now, but I somehow got curious into webrtc and started a small project to understand it. Today's Learning: WebRTC stuff - How real time communication works in real world. - What are STUN & TURN servers, and why are the used in webrtc. - Signaling servers to establish a connection between two parties, which could be an existing communication media be it, http, websockets, or any messaging platform like WhatsApp, email. - What are ICE candidates and SDP. - What is an offer and an answer. - How to use RTC object and apis, like RTCPeerConnection, onconnectionstatechange, onicecandidate, ondatachannel, RTCDataChannel, onopen, onmessage, createoffer, createanswer, setLocalDescription, setRemoteDescription. many more. Simulated a basic peer to peer connection by generating an offer on user A and copying the sdp and pasting it into user B, generated an answer on user B, pasted it into user A, accepted the answer, and boom connection is made and data channel is set. And test it by exchanging some messages from both the sides.
English
4
1
29
887
Prajwal BM
Prajwal BM@xshadowdev·
@pitoorpitoor Not it's not an SDK. It's just a technology used for real time communication
English
0
0
1
15
Mohit
Mohit@pitoorpitoor·
@xshadowdev Bro lets build it together Is it an sdk?
English
1
0
1
11
Prajwal BM
Prajwal BM@xshadowdev·
Building a new project around WebRTC. Today's Learning: 1. ArrayBuffer - A container for raw bytes which is immutable. - Uint8Array - As ArrayBuffer is immutable, we use Uint8Array as a view to manipulate the data inside it. - Blob - is a Js object which represents raw immutable data, usually in file-like data stored in memory. 2. Web workers - web workers are a browser feature that allow us to run JavaScript in a separate background thread, independent of the main UI thread. Used to perform heavy task in background. - "self" is a global object in the workers world, similar to "window" object in browser. - learnt about onmessage, postMessage, streaming data using Transferable Objects in postMessage method. worker.postMessage(hugeData, [hugeData]), by doing so we will be not copying the data, instead we will be moving the data between threads. 3. Filesystem : used showSaveFilePicker from fileSystemHandle API to show the save dialog. And then used createWritable method to directly write to the disk instead of copying it to the memory and downloading it. So that we will reduce the memory usage.
English
2
0
21
384
SUMUKH
SUMUKH@iam_enginner·
@xshadowdev It's a long journey which was introduced by you😁
English
1
0
1
17
SUMUKH
SUMUKH@iam_enginner·
@xshadowdev Cool concept will explore some day 😋
English
1
0
1
29
SUMUKH
SUMUKH@iam_enginner·
Is this terrain color looking good ?
SUMUKH tweet media
English
3
0
4
387
Prajwal BM
Prajwal BM@xshadowdev·
version 1 of my first portfolio is done, just need to add projects. Kept it simple and no animations for now. will keep improving it in next versions.
English
3
0
44
1K