simple video chat using as3 - actionscript-3

I'm trying to make a simple video chat using Flex framework and red5 server. It's an application with 2 video displays. With connection to the server more or less figured out. However, I do not understand how to transfer user1 stream to user2.
Here is functions i use to transfer webcam image to the server and to get the stream.
public function appendStream(connection:NetConnection):void {
myNetStream = new NetStream (connection);
myNetStream.attachAudio(cameraVideo.getMic());
myNetStream.attachCamera(cameraVideo.getCam());
myNetStream.publish("videochat" , "live");
}
public function getStream(connection:NetConnection):Video {
guestNetStream = new NetStream(connection);
video2.attachNetStream (guestNetStream);
guestNetStream.play("videochat");
return video2;
}
As you can see, i am getting my own stream.
Is it possible to solve the problem by flex, or I need programming on the server side?

You dont need separate rooms, simply use unique stream names for each client. The ez way is to create your steam names ahead of time and pass them to your swf via flashvars; that way you dont have to pair them with some other complicated scheme.
For a bit more background in red5, a room is a type of scope and a scope can contain other scopes which includes broadcast scopes, shared object scopes, and rooms. There is no limit on the number of these scopes other than the amount of RAM on the server itself.

You need to have two "rooms" instead of one "videochat". User1 must publish to "videochat1" and stream from "videochat2". Vice versa for user2.
And please remove Flex mention here since there's nothing related to Flex UI framework here

Related

Method GetInfo in WebSerial API? Is there another way to get device infos?

I'm using the Web Serial API to connect two different scales. They send the weight data in different ways, so I'm trying to get the serialport metadata from them (vendorId etc) because I want to detect which scale is connected. The "getInfo()" method does not work because it is undefined in the Serialport Object.
[Exposed=(DedicatedWorker,Window), SecureContext]
interface SerialPortInfo {
maplike<DOMString, DOMString?>;
};
This is the interface for the metadata but I don't even know, how to use it.
My sources: https://wicg.github.io/serial/#dom-serialportinfo
The method is declared a little strangely in that version of the specification. You can treat the return value as a plan object. If the port is a USB device then it will have usbVendorId and usbProductId properties which are the metadata you are interested in.

How to find out the availability status of a Web API from a Windows Store application

I have a Line-of-Business (LoB) Windows 8.1 Store application I developed for a client. The client side-loads it on several Windows 10 tablets. They use it in an environment where WiFi is spotty at best and they would like to get some sort of notification inside the app, regardless of what page they are on, notification that will let them know that they've lost connectivity to the network. I have created a method on my Web API that is not hitting the repository (database). Instead, it quickly returns some static information regarding my Web API, such as version, date and time of the invocation and some trademark stuff that I'm required to return. I thought of calling this method at precise intervals of time and when there's no response, assume that the Web API connectivity is lost. In my main page, the first one displayed when the application is started, I have the following stuff in the constructor of my view model:
_webApiStatusTimer = new DispatcherTimer();
_webApiStatusTimer.Tick += OnCheckWebApiStatusEvent;
_webApiStatusTimer.Interval = new TimeSpan(0, 0, 30);
_webApiStatusTimer.Start();
Then, the event handler is implemented like this:
private async void OnCheckWebApiStatusEvent(object sender, object e)
{
// stop the timer
_webApiStatusTimer.Stop();
// refresh the search
var webApiInfo = await _webApiClient.GetWebApiInfo();
// add all returned records in the list
if (webApiInfo == null)
{
var messageDialog = new MessageDialog(#"The application has lost connection with the back-end Web API!");
await messageDialog.ShowAsync();
// restart the timer
_webApiStatusTimer.Start();
}
}
When the Web API connection is lost, I get a nice popup message that informs me that the Web API is no longer available. The problem I have is that after a while, especially if I navigate away from the first page but not necessary, I get an UnauthorizedAccessException in my application.
I use the DispatcherTimer since my understanding is that this is compatible with
UI threads, but obviously, I still do something wrong. Anyone cares to set me on the right path?
Also, if you did something similar and found a much better approach, I'd love to hear about your solution.
Thanks in advance,
Eddie
First, If you are using Windows Store Apps, then you could possibly use a Background task to check poll for the status of the web api instead of putting this responsibility on your view model, its not the viewmodels concern
Second, if you are connecting from your Windows store app to your API then one successful authentication/ authorization for the first time, how and where do you store the token (assuming you are using token authentication). If you are (and ideally you should), is there a timer that you start which is set to the token expiration time? Is your local storage getting flushed somehow and loosing the aurthorization data?
Need more information.

Is there a way to write a |RtmpSampleAccess command to a NetStream in data generation mode?

I'm streaming data from a server and passing it into a net stream in data generation mode. I'm successfully wrapping H264 and PCMU to be played back through NetStream, however I need to be able to capture this output from the video display it's on and store it in an image. When using an RTMP server, I'd configure it to send an RtmpSampleAccess command, with true,true for audio and video access allowed. When using RTMFP I'd do the same, send() a RtmpSampleAccess true,true from the peer to allow access.
I believe I need to send in an FLV tag for a script data object to represent the RtmpSampleAccess command, however I can't find any information on what the format of that tag needs to be. I've tried using the OSMF FLVTagScriptDataObject with the objects set to the following combinations:
["|RtmpSampleAccess", true, true];
["|RtmpSampleAccess", [true, true]];
And various attempts at guessing the naming for object parameters (though looking at the protocol docs, I'm not sure there is one).
Could someone out there help me here, would be much appreciated.
Where you put your Netstream into Data Generation mode you add a second Play command. The second one simply plays "a blank" and for some reason this overrides the security error.
ns.play(null);
ns.play(""); //works to avoid all security errors
ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
Then to draw just setup a button to run the draw_VideoFrame function when clicked, or try real-time drawing with something like below (using enterFrame):
vid_Obj.addEventListener(Event.ENTER_FRAME, draw_VideoFrame);
and then create a function like this example.
function draw_VideoFrame (e:Event) : void
{
vid_BMD.draw( vid_Obj ); //draw into a BitMapData variable
}

Red5 2-way camera setup (videochat)

I got a problem with RED5 in combination with Flash. For a personal project i am trying to make a Skype-like application. I already got a application that records the users webcam and saves it with a custom filename on the RED5 server.
But i am stuck trying to connect one more user to that window for a video chat. I made a new video container in Flash but i don't know how to connect a second client to the same stream in AS3 with Red5?
I searched on the net but i only get really old threads about RED5 in combination with Flex.
Maybe this is helping understanding my problem?
Could someone help me out? Or get me in the right direction?
Video chat? You will need 2 streams, for every client. Inbound and outbound. Outbound is a stream from the client to the media server, inbound is consumed stream of another user. So it will look like:
_streamOut = new NetStream(connection, NetStream.CONNECT_TO_FMS);
_streamIn = new NetStream(connection, NetStream.CONNECT_TO_FMS);
_streamOut.addEventListener(NetStatusEvent.NET_STATUS, onStreamOutNetStatus);
_streamIn.addEventListener(NetStatusEvent.NET_STATUS, onStreamInNetStatus);
_streamOut.attachAudio(microphone);
_streamOut.attachCamera(camera);
_streamOut.publish(hostPeerID);
_streamIn.play(companionPeerID);
Also there are some helpful examples, did you check them?

Flash As3 Number of people online

I have created a Jar that I want to fill with fireflies, depending on how many users are online.
I did a little digging and I found how to create a XMLSocket. It worked but I didn't know how to get the information how many people are online and also it required a CMD window to run all the time.
The second way I found was trough a PHP,MYSQL witch I have runing with my Apache server, but the tutorials and scripts I found did not work for me, for example. I did not create the required tables.
My question is what is the simplest way to find the current count of users online on your page/flash file? Is there a quick way to do it inside flash and not get involved with MYSQL or PHP?
No, there is not a simple way to only do it in Flash without using any external part (PHP, MySQL, Java, and more...). Remember that Flash is run locally, and thus needs to interact with PHP or similar to interact with the server to tell the server about the activity by the user and to ask the server about other users activities (number of users online).
If you only want to display the users online, I recommend the way that is shown in the example you posted. Simply update the database when activity has been seen by a user and count the user as offline when no activity has been seen for x minutes. There's no need to involve XMLSockets for this unless you want the users to interact with each other in any way.
If you want more than just displaying the users online, I recommend using XMLSockets in ActionScript and looking into PHP Sockets.
i dont think so, the flash player must need a way to "check" on the server the number of users who are online. the simplest would be to send a URLRequest (i hope i got the class name right) to a server script, which could be either a php or an aspx (or any server technology) script / page.
that server script should return the number of users the site has.
e.g.
var numberOfVisitors:Int = 0;
function onLoaded(e:Event):void {
numberOfVisitors = e.target.data;
// now print this 'numberOfVisitors' where you want to on the client
}
var numVisitors:URLLoader = new URLLoader();
numVisitors.addEventListener(Event.COMPLETE, onLoaded);
numVisitors.load(new URLRequest("num_users.php"));
the next part would be a php script (or any other server script) that keeps track of the number of users. that i think you should post as another SO question perhaps?
I got it to work, but I hat to link the php file not trough it's HTTP address, instead just the path relative to the .swf file (just myFile.php or path/myFile.php).
AS3 file:
NewRequest = new URLRequest("numOnline.php");
var numberOfVisitors:int = 10;
var NewRequest:URLRequest;
var UrlLoader:URLLoader;
UrlLoader = new URLLoader();
UrlLoader.dataFormat = URLLoaderDataFormat.TEXT;
UrlLoader.addEventListener(Event.COMPLETE, onLoaded);
UrlLoader.load(NewRequest);
function onLoaded(e:Event):void {
trace(e.target.data);
numberOfVisitors = int(e.target.data);
}
I convert the text As3 receives to int, because i don't know yet how to send veria
php files
main PHP file (the file that as3 connects to):
<?php
include_once 'config.php'; //This file would contain the variables needed to connect to the database with $link, below
include_once 'functions.php'; //We include the functions we have created
$database = "online";
$link = mysql_connect($server, $db_user, $db_pass)or die ("Could not connect to mysql because ".mysql_error());
mysql_select_db($database)or die ("Could not select database because ".mysql_error());
usersOnline(5); //We call the usersOnline function with a time span of 5 minutes
showUsersOnline(1); //Show the number of users online, and the list of users
mysql_close($link);
?>
the function file sends the number of Visiters Online with echo $count;
Yes, you can do it without a database (MYSQL) and PHP; BUT you will still need a (Media) Server.
I wouldn't suggest the following if your "only" purpose is to count the connecting clients, but if you have the reasons and have access to a Flash Media Server, you can try the following:
On Server Side:
Create an application (folder) on FMS, create the main.asc file inside that folder.
Inside the main.asc; create a (remote) SharedObject (server-side) (e.g.: users_so)
Watch for connecting clients on application.onConnect event. Add each connecting client to that SharedObject inside this handler.
Also watch for disconnecting clients on application.onDisconnect event. Remove each disconnecting client from the SharedObject inside this handler.
On Client Side:
Connect each Flash client to FMS (with your new app-folder path in the URI) when the application loads in the browser.
Watch for the NetStatusEvent.NET_STATUS event and "NetConnection.Connect.Success" code. When connected; create a SharedObject (client-side) and get the remote from the server.
Add the SyncEvent.SYNC event listener to the SharedObject. This will sync with each Flash client when a user connects or disconnects from the server.
Inside the sync event handler, get and count the users from the event response.
Display the count on your Flash client.
See Server-Side ActionScript Language Reference for Flash Media Server 4.5, especially the Application Class.
Also useful: Flash Media Server Developer Center
Hope this helps.

Categories