How to handle multiple video streams in Red5? - java

I am writing a Red5 application that provides 1-on-1 video chat to a Flash client over RTMP.
Unfortunately most tutorials I was able to find were sketchy at best and the documentation of Red5 itself tends to be vague when it comes to API concepts and intended usage.
In short, I am a bit stuck and looking for hints on Red5 ApplicationAdapter implementation. Gnarly details are as follows:
First of all, the connections come in two flavors: visitors and consultants. A visitor should be able to indicate which consultant it wishes to communicate with. A consultant simply gets connected to the requesting visitor as long as the consultant is not busy servicing another.
Obviously, every RTMP connection has two-way traffic: both sending and receiving video. From the standpoint of the server, connections bring in a bunch of video streams that get their receiving endpoints assigned by request.
Since several video conversations can be in progress simultaneously, the main task of the application is to handle the mapping of visitor streams to consultants and provide a list indicating each consultant's state (busy/available) via AMF.
So, all in all, I have a pretty good idea what I am aiming for but how to achieve it with Red5 is still a bit of a mystery.
Hopefully someone can enlighten me in any or all of the following:
What is the easiest way to establish the connection type (visitor/consultant)?
Which API classes should be used to implement a persistent, globally accessible list of active connections for reporting the state of each consultant?
How to switch receving endpoints dynamically when the goal is to connect a specific visitor to the selected consultant?

Saul ,
1.What is the easiest way to establish
the connection type
(visitor/consultant)?
assuming that both(visitor/consultant) are using flex client via which they start publishing their live video stream ,here you need to make sure that each published video stream name is unique (HOWTO is already mentioned in demo apps)
2.Which API classes should be used to
implement a persistent, globally
accessible list of active connections
for reporting the state of each
consultant?
and for providing the list of active connections you simply need to store(preferably in your db) each user's id with the stream name (which is also available as a tutorial demo app) to connect to.
I believe all the code is available for the red5 demos Do try oflaDemo , simpleSubscriber , fitcDemo demo apps.
I hope I am closer to your solution.

Since Oflademo or red5 is capable of 1v1 chats, then replicate this code to make around 50 chats. You can maintain a table with the following columns :
chat room number (1 to 50)
user1
user2
status(0 or 1 - unoccupied or occupied)
If let say a visitor V22 wants to get consulted from consultor C33, then a program can detect the first unoccupied room from 1 to 50, if the 7th room is unoccupied then, redirect V22 and C33 to room 7 and change status to 1(occupied). After the video call, the status can be reset to 0, and the table at roomno:7 , user1 of roomno:7, user2 of roomno:7, can be set to NULL. Its like maintaining tables in a restaurant in a computer.
You can basically develop multiple chatting using 1to1 using a database and php queries, no need to edit any swf code or maintain a complicated server etc.

Related

How to test a distributed P2P game if it can handle 100 connections?

For a big project at school we have made a P2P variant of the famous beergame. The GUI is built in JavaFX.
I have to do research on how to test a quality attribute scenario, which is the following:
100 players can connect to the game and play it.
Connecting to a game goes via an input in the GUI where the player needs to put the IP address (with port if its over WAN) of the host (gameleader). We are implementing RAFT as the state consensus algorithm.
The first step I did was researching the best possible way to create 100 clients/computers however you want to call it. I quickly came to the conclusion that Docker was about the only piece of software that could have 100 containers running simultaneously. My real problem now is how to test the application in a containerized environment.
I thought about it and the only real way to test the flow to play a game on each container was to walk through the UI elements with for each client other settings (every client needs to join the game with different usernames) with some kind of UI testing framework like TestFX.
I have found a framework that lets you test the UI, but it needs an host OS with a graphical interface to function (or at least, that's the assumption I have based on a short search on the internet).
Is there maybe a way to do this in IntellJ itself. Creating 100 containers of with the game with each an unique IP-address so that they can connect to the game host.
Edit for #Karol Dowbecki
The way we are communicating is sending serialized AppendEntries(heartbeats) every 100ms over TCP/IP with UPnP which contain changes that have to be committed (if nothing happened, then the appendentry has no logentries). So if a player does an action, it sents an AppendEntry to the leader of at that moment(gameleader/host) which then relays it back to all the other nodes and waits for the majority of the nodes to send it back (two-phase commit) after which it is added to the list of logentries of each player (all data of the game). If a new player joins the game, that player receives all of the logEntries that exist for that game in just 1 heartbeat, which is a gigantic serialized json object, after which it recalculates the steps (logEntries) from the bottom up until the last one, which is the player joined the game.
So what you are suggesting is capturing these serialized appendEntries that go over the network, deserialize them and compare it to the expected result? It will be very hard if I had to scan every AppendEntry, as each client sends 10 of them per second to the leader (if the client is a player) and 10 to all of the nodes (if the client is the leader/host).
Also the AppendEntries go back and forth. Everytime a player joins the LogIndex(the index of the LogEntries, basically the index of how many gamestate changes have occured) goes up by 1, which ultimately defines how many changes have occured in the gamestate. So its not that I am sending static information back and forth. Its changing with every joining player. Also when a player "disconnects" this affects the LogIndex again. I have to be able to keep track of the fact that 100 people joined the game and are still there.
You don't necessary have to create 100 instances of the game. Doing this will have one considerable downside, by scripting the client UI it's hard to tell if the bottleneck will be in the client or in the server (the Coordinated Omission problem).
If you understand what is the wire protocol used and what are the expected player behaviors you can create a test plan using Apache JMeter or Gatling. You can use Wireshark to inspect and record the wire protocol used by the client.
This won't create a true player experience but as long as you will recreate the most popular player's actions it will be good enough to stress test the server. Mentioned frameworks will also have a number of features that will help you spot the problem e.g. ramping up and down connections over a period of time, plotting the results, etc.

Salesforce: Which API to use without Login required?

I'm currently working on a native Android app for my company and ran into some problems with Salesforce lately.
I hope I can find some help here.
What I want to achieve:
The company has a lot of Accounts in Salesforce with 3 important fields for the app: Name, Business (Workshop or Parts Dealer) and location(latitude, longitude)
I would like to show those Accounts(Workshops/Parts Dealers) as markers on a google map in my Android app based on a radius around the user's current location. So it would be more than sufficient to get the data as JSON or XML(i read about sObjects, which would be nice too)
The app will be freely available on Google Play Store and every user should be able to see all the Workshops/Parts dealers around the world.
The problem I'm facing is that I can't find a way to fetch the data inside my app without authenticating every user with a Salesforce-Login. 
Which API is the best to use in this case?
It would be so awesome if anybody could help me with this problem.
What I tried so far: 
- SalesforceMobileSDK: If i extend SalesForceApplication() i always end up with the Salesforce-Login Screen.
It seems that every client has to be authenticated for API-calls to work. I tried using the method peekUnauthenticatedRestClient(), but this method only works on full path URL's(e.g. "https://api.spotify.com/v1/search?q=James%20Brown&type=artist"), which isn't really practical for my Use-case.
I feel like I read nearly all docs about salesforce API, but can't quite get my head around how to solve this problem, although it seems like to be a pretty common use-case.  
would a salesforce-apex method which would select all records inside a set radius around the user's location to be accessible without authentication?
Thanks for your help in advance!
Roman
Try asking on salesforce.stackexchange.com. Your question is more about licensing model than a particular programming problem. It might even be the case that you don't really need Salesforce for your project, you'd be better off on Heroku (even free tier) if the login piece is an issue...
All Salesforce APIs require some form of authentication. If you're positive you don't want to hardcode "Integration user" credentials in the app and you don't want to pay for (self-)registered user licenses in your org...
Try to read about these:
Site - piece of Visualforce running under specific "guest user", letting you view & interact with SF data without having to log in. You expose SF data to the world but that means it's your job to handle security (if any) and craft the API. You want to really display the data to human? Or just return JSON content or what...
Sites are meant to be displayin some incentive to contact you. Your product catalog / basic order form. Some map of nearby locations. Maybe a "contact us" form. There's limit on the traffic so eventually they'll explode as your app gets popular:
Customer Community - typically you need named licenses (even if they're fairly cheap) to let your customers log in to your SF. You create a Contact, click magic button - boom, this Contact now has a real matching User record with its own license. Think of it as some kind of step up from Sites - it'll still have some limits but will offer more than just raw API access and you'll have better control on what's going on.

Skype.getAllChats() not detecting cloud-based group chats

I'm trying to write a bot that, for starters, listens and logs every message said in a cloud-based chat -- that is, a chat where the command \get name returns a string with the prefix 19:, e.g. 19:f0ddd8dbc5b64372a2dd1de9f37f8689#thread.skype in my specific case.
However, I cannot get Skype4Java to find any of the cloud-based chats I'm participating in.
Group[] groups = Skype.getContactList().getAllGroups();
The above returns an empty list, even when there are P2P groups present.
Chat[] chats = Skype.getAllChats()
The above returns all chats (P2P group or individual) except for cloud-based group chat.
Is Skype4Java not able to interact with cloud-based chats? I know Skype4Py (the Python equivalent) isn't able to. (Inappropriate follow-up question: are there any APIs that do interact with cloud-based chats?)
(Edit: This is a self-answer after hours of mostly fruitless research. Putting it up in the hopes that it'll help some other newb bot writer.)
Skype4Java, Skype4Py, and most other API wrappers cannot interact with cloud-based chats.
There is no workaround other than recreating the desired chat with /createmoderatedchat and adding all the participants from the previous.
The only alternative I could find is Skypeweb, a library that's part of Skype4Pidgin. It does work with cloud-based chats, as far as I can tell. However, there is very little documentation.
This article from the Bitlbee Wiki may be helpful. It describes how to incorporate SkypeWeb into Bitlbee.

How should I manage Bluetooth connections in Android?

Q. What are your best practices in managing bluetooth connectivity?
I've read the android bluetooth guide & many bluetooth connectivity tutorials. Not helpful with encapsulation-design nor best practices.
When should I open/close the connection?
Is the "connection" with a single bluetooth device called a "socket" connection?
Can a single connection send data while listening? (...or between listening states).
I've never coded connectivity with external devices before. It took two weeks for me to wrap my head around the code that scans for near-by bluetooth devices and throw them into a ListView. Listeners, Broadcasts, and Adapters!
My project will be printing 1-40 receipts every 15 minutes on a bluetooth receipt printer. At the moment, security is not an issue. On the same connection, it will also be receiving data (sending & receiving simultaneously does not appear to be necessary but would be useful). I'm not yet sure how the devices are configured on this single dongle device but I would guess the devices are connected via USB controller to the dongle.
So far, I have 1 object to manage a single I/O connection. Staticly I open an activity to select a connection (to later save the label, mac, and pin in the database). Based on tutorials, I have "open", "listen", "send", and "close" methods. What confuses me is "how" to use these functions. Can I leave a connection open all day (10hrs) and use it every 3mins? Should I open/close the connection when sending or requesting data? Where would I detect the need to reconnect?
sorry for the short answer, but from my practice with the Bluetooth API, I have found that this video describe the things very good (totally personal opinion...)
Video 1
In addition this is useful when you do NOT have any previous experience
Tutorial
And as last check out this question in stackoverflow it has a bunch of good references and examples!!
Again sorry for the shortage, but I believe that if you check these out at least most of your questions and concerns will become answered!
:)
EDIT
So, let me be a bit more descriptive and share some of my experience.
I have written an App that communicates with BLE device that has 3 functions
double sided event driven button (push the button on phone -> event is fired to the device; push the button on the BLE device -> event is fired to the phone)
send request from phone -> BLE device answers with current battery percentage
continuously reading strength signal (as aprox. distance) between the phone and the BLE device
So far so good, now the things is that the basic approach is:
Search for BLE devices (bluetooth search or "discovery" of nearby bluetooth devices)
Here you will need android permissions!
Choose the device you want to connect to
To differ the devices (maybe there are a lot around you :) ) you can use BLE device's name or UUID or ... best - use the name ;)
After both devices connect to each other you can then start the Gatt communication. The approach with state machine is a little too much overkill for me. But anyway the communication is done through bytes (in my case...)
In one of the videos/resources there was something specific and VERY HELPFUL at least for me! To be honest I don't remember it exactly, but the idea was that before any communication it's RECOMMENDED to read/get all the options from the BLE device or something similar...
Maybe it was something like discoverOptions() or something like that
Great thing will be to know your device "communication codes" or at least I call them that way.
Check this link for example: Link
** Now you can see there are tables with the USEFUL INFO! E.g. if you want to read the battery level you navigate to this page and find that in order to read the battery, the service name is UUID XXXXX and you need to send 0x01 to the BLE device and it will "answer" to your call with some data which is again in bytes.
I really hope that this is somehow helpful!
PLEASE NOTE
This is strictly coming from my experience and there could be some mismatches or wrong terms, but that's how I personally see the things and because my project was long ago, I don't remember most of the things exactly.
IMPORTANT:
This is only a summery of STUCI's provided links above. He has since updated his answer and I have not updated/edited this summery. Topics in my summery are not explanatory but provided for reference and help in generating specific questions.
Original Post...
Thank you Stuci! Some of that was helpful:- some not. I thought it best to collect my thoughts and see what has been explained and if anything hasn't.
(I can't post this much in a comment tho, sorry)
PLEASE CALL ME ON ANYTHING THAT IS INCORRECT.
Video of Bluetooth LE
(Covers a bunch of random things)
While I "dont-like" videos of code:- I watched it because it was recommended ... and I am glad I did. While not very helpful it did introduce some concepts I was unaware of. Since I am targeting old android devices (v8+) the LE features are inconsequential.
Pushing Data: [Depending on the source feature-set], one does not need to continually pull data (ex. with a temperature sensor) but some devices can "push" it to the device on change. Seems to use the 'advertisement" design concept.
UUIDs define Services and/or Characteristics of the connected device.
Possibility to write configuration on (to) connected devices.
Characteristics which seem to be simply "settings" that can be assigned over bluetooth. Not sure if this (~19mins) applies to non-gatt connectoins but seems similar to the state-machine that controls
Advertisements which seem to be the "metadata" regarding the devices current state or config (~24mins). Again, not sure if this even applies to non LE Bluetooth.
Leaving Connections Open
Bluetooth connections can indeed remain open; starting at the point which the "startActivityForResult(...) method is successfully called.
Two basic things affect whether or not one would want to maintain an open connection:
Understand the power consumption.
Having the adapter active simply consumes additional power. If one can keep the adapter shut-off while it is not "absolutely-needed" will mearly save battery power.
Accidental disconnects are managed.
Other than leaving the connection continually connected, one could disconnect & reconnect regularly at specified intervals to ensure a connection is up.
In the thread(s) used for I/O, one could check for a disconnect and reconnect (possibly starting a new thread).
I/O Streams pr Connection
A single connection can indeed "have" simultaneous Input & Output streams. I
Since it was suggested, I re-read Android's Bluetooth Guide and under "managing a connection" (talking about a single socket) I noticed this...
Get the InputStream and OutputStream that handle transmissions through the socket, via getInputStream() and getOutputStream(), respectively.
Read and write data to the streams with read(byte[]) and write(byte[]).
...but continues with noting that read & write block each other. Something I still need to look further into. It seems like you cant I/O simultaneously on the same socket???
Max Connections
I also looked into the max connection issue Stuci added and found no documentation on the Android-side. It might exist, I cant find it. However, most people seem to agree that there is a limitation (that could be as low as 4) imposed by whatever hardware you are coding for.
Some notable links:
- How many devices we can pair via Bluetooth of BLE to Android?
- How many maximum device can we pair via Bluetooth to android device at a time?
- https://groups.google.com/forum/#!topic/android-developers/adeBD275u30

Which pattern is good for bullets hit test in game that need server validates?

I would like to design a PvP game uses flash in client and java socket server, but I do need server validates trajectory and if bullets hit target from cheating.
Is there any tutorial or paper provides how to do this ?
To do it you need to have a server-side logic.
Mainly you will use clients just to show gamestates that are sent by server (if you want you can also let your clients show whatever they think is right until a new gamestate is received and synch to it) and to send to the servers just actions that are done (clicks or key presses) while your server should take care of everything else..
clients should be mainly frontends for the world representation..
The general idea for a uncheatable multiplayer game is:
You should only send the keys the user is pressing, the server stores it and after some intervals, it processes the informations and send a snapshot of the current position of all objects in the game.
Maybe if you don't want to waste too much network traffic:
You could save everything's position for 2 seconds, record the last user input (with the input, he may also send his last snapshot id), then send only what differs from the position now and what the user have.
Since you asked for patterns, I am assuming you understand the kind of logic you want to write on server side, but not sure about how to organize your code.
You should look at strategy pattern (http://en.wikipedia.org/wiki/Strategy_pattern) once. Since in this problem based on various locations on the screen, you need to change the way server validates the data, strategy pattern is a good fit for the problem.
#Jack: +1, and you should not actually do physical exercises at server,server just check start point, end point, range and time ect... if they are reasonable!

Categories