Comments (14)
Hi @seba9999
I think it's working method 🙂 One thing that I would do potentially differently is an iteration - can we iterate in JS code?
Just theoretically we can slightly change internals of the library and change the signature of sendMessage
:
-public void sendMessage(String message, final Promise promise) {
+public void sendMessageTo(String message, String address, final Promise promise) {...}
+public void sendMessage(String message, final Promise promise) { // just to keep backward compatibility
+ this.sendMessageTo(message, wifiP2pInfo.groupOwnerAddress.getHostAddress(), promise)
+}
Then I think broadcastTo
method can be fully implemented on JS side (through Promise.all
construction). What do you think?
I would love to help with the implementation, but I don't have even 2 physical devices to test the implementation.
from react-native-wifi-p2p.
What do you mean by iterate ? Looping through a list of adresses ?
Yes, I meant this.
I'm also wondering (that's a part I didn't fully understood) If the "port" setting should be changed or not ?
Good question :) I think the answer could be discovered only by trial and error 😄
I would be very happy to help to test it out ! I've got 3 devices ( thanks family :D ) to test it out. If you make a branch with such modifications I would import the new branch and test it on my app for you no problem 👍
I will try to find a time on this weekend and modify code. But can not assure the code will work, since I even don't have two physical devices 🙈
from react-native-wifi-p2p.
Let me know when there's something to try :)
from react-native-wifi-p2p.
Hi @kirillzyusko,
It's been a while and I wasn't able to work on this since November but I would like to work on this again. Are you planning to try to implement the broadcast thing we were talking about ? :)
Did you achieve somehting like you described ?
from react-native-wifi-p2p.
Hi. I am working in a change that solves this issue and also #57 .
I had trouble compiling the code of react-native-wifi-p2p (maybe some issue with gradle) and tried to implement it using react-native-wifi-p2p-reborn.
Implemented here sendFileTo (untested) and sendMessageTo (testing in my application).
There is a breaking change in receiveMessage(), that now instead of receiving just the message (string), it receives an object with the following structure:
{
fromAddress: "192.168.43.20",
message: "message received"
}
I had to do that to know the IP of the nodes in the network, besides the group owner. So, in my application logic, after the connection is estabilished, the group owner starts to receive messages (using receiveMessage() ) and the nodes send a first message.
I think it is possible now to cherry-pick the changes in this commit to this project. If approved, the README also will have to be changed.
from react-native-wifi-p2p.
What do you mean by iterate ? Looping through a list of adresses ? Of course we could do it in JS ! The real question is in which side we want to handle the potentials errors / non-receive... And I'm afraid I don't know where's the best place place to do so ( JS / java )
Btw both should work !
I would be very happy to help to test it out ! I've got 3 devices ( thanks family :D ) to test it out. If you make a branch with such modifications I would import the new branch and test it on my app for you no problem 👍
I'm also wondering (that's a part I didn't fully understood) If the "port" setting should be changed or not ? ... Here
from react-native-wifi-p2p.
I've found a fork from your project that provide 2 other functions linked to services ...
https://github.com/m3tasploit/react-native-wifi-p2p-reborn
Would you mind having a look at the changes ? I'm not 100% sur it create some broadcast feature ... the Android wifip2pManager Doc isn't clear enough IMO.
from react-native-wifi-p2p.
Hi @seba9999
I think reborn
version adds TS support and a wrapper around WifiP2pDnsSdServiceInfo
class.
I don't have experience with this stuff, to be honest. After a quick search in a google for me it seems like it's needed for device management (like printers) that are connected to the same network (though I may be mistaken and I may assume that it's more powerful stuff than I suppose 🤷♂️ ).
As you pointed out Android documentation is not clear especially for p2p stuff. For me it seems like DnsSd is kind of a protocol that is needed for specific use cases. But once again, I'm not an expert in this 😔
from react-native-wifi-p2p.
I am looking for some kind of broadcast too. I just need that A, B and C shares the same information the app is handling at the same time, as A and C are not connected (because wifi restrictions on distance), C would't receive the data that A has modified. Another use case it would be that B takes some space from the other users (physically speaking) and get disconnected from A or C (BUT never between both), also A and C get connection stablished (or maybe not).
Could these examples help to achieve broadcast between all connected devices in a group?
Sends data to all connected devices in the group. This function should iterate through the list of connected devices and send the data to each one individually.
function broadcastData(data) {
wifi.getConnectedPeers((peers) => {
peers.forEach((peer) => {
wifi.sendData(peer.address, data);
});
});
}
Listen for incoming data, and check if the data is intended for the broadcast.
wifi.onDataReceived((data) => {
if (data.isBroadcast) {
// Handle broadcast data
} else {
// Handle regular data
}
});
In order to know that the data is intended for the broadcast, add a flag or a specific key-value pair in the data. For example, add the key isBroadcast with the value true in the data before sending it.
const data = {
message: 'Hello World',
isBroadcast: true
};
broadcastData(data);
from react-native-wifi-p2p.
Hi @seba9999
Are you planning to try to implement the broadcast thing we were talking about ? :)
I don't think so, because currently I'm busy with other stuff 😔 But I will be glad to review your PR 😊
from react-native-wifi-p2p.
Hi @viniciuscb
Would you mind to submit a PR? Your changes looks good for me 👍
I'm compiling the project using test example project: https://github.com/kirillzyusko/react-native-wifi-p2p-example
There you can specify a package from github:
"react-native-wifi-p2p": "https://github.com/seba9999/react-native-wifi-p2p#feature-broadcast"
Or you can use symlink to link a local package (I prefer this option, since I can easily modify file locally and I don' need to reinstall deps every time).
@viniciuscb just want to ask - did you test your changes? Do they actually work? If yes, then I'd like to ask you to add info about new methods in README and submit a PR 😊 I'd love to merge them and release a new version of the library!
from react-native-wifi-p2p.
Closed since #61 was merged
Thanks @viniciuscb and @seba9999 for contributing to the project! I really appreaciate your help! 😊
from react-native-wifi-p2p.
Hi. @kirillzyusko . Nice to contribute.
from react-native-wifi-p2p.
Thank you @viniciuscb! I will try it out soon!
from react-native-wifi-p2p.
Related Issues (20)
- DeviceEventEmitter.removeListener is deprecated HOT 1
- transmit an image from a camera HOT 1
- Set Group Owner operating frequency band HOT 1
- Is there a way to get device Address with ipv4 format ? HOT 2
- Example code is not working HOT 15
- unsubscribeFromPeersUpdates : EventEmitter.removeListener() : Method has been deprecated HOT 5
- Urgent: Sending File from Server to Client HOT 5
- Could not resolve all files for configuration ':react-native-wifi-p2p:classpath' HOT 7
- Android 13 rejects startDiscoveringPeers() with code 0 HOT 7
- Receive messages when the device is a mobile hotspot HOT 1
- sendMessage and receiveMessage refactoring? HOT 6
- connectionInfo is not updated when connection closes HOT 5
- SendMessageTo - can't use MAC address and we don't have ip addresses HOT 7
- sendFile and receiveFile refactoring HOT 6
- I want to make a real-time-streaming (Two Android devices connected 1:1) HOT 2
- Get Available devices not working HOT 4
- getAvailablePeers() always return empty array HOT 3
- method getAvailablePeers() always return empty device array HOT 1
- TypeError: null is not an object (evaluating 'WiFiP2PManager.init') HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-wifi-p2p.