I'm working on an HTML5 app which needs to interface with Flash to get access to the local media (e.g., the webcam and microphone), and to transmit the audio-video between remote browsers. But in this app, I need the local webcam display to be on one part of the screen, separated by various HTML elements from the remote webcam display. I'm pretty sure this means that I need to have multiple instances of my Flash app running. But I think that you can only grab one instance of a webcam at a time, which means that I need to be able to share those webcam and microphone objects between Flash instances: one displaying the local webcam, and the other communicating with and displaying the remote webcam. Is it possible to do that? For instance, can I pass my Camera and Microphone instances out to JavaScript through the ExternalInterface and then pass them back into a separate instance of my Flash object?
In other words, I'm thinking of having an ActionScript class that looks like this (much simplified of course):
public class MediaController
{
public function MediaController()
{
ExternalInterface.addCallback('getUserMedia', this.getUserMedia);
ExternalInterface.addCallback('getCamera', this.getCamera);
ExternalInterface.addCallback('setCamera', this.setCamera);
ExternalInterface.addCallback('getMicrophone', this.getMicrophone);
ExternalInterface.addCallback('setMicrophone', this.setMicrophone);
}
private var _mic:Microphone;
private var _cam:Camera;
public function getUserMedia()
{
_mic = Microphone.getMicrophone();
_cam = Camera.getCamera();
}
public function getCamera():Camera
{
return this._cam;
}
public function setCamera(cam:Camera):void
{
this._cam = cam;
}
public function getMicrophone():Microphone
{
return this._mic;
}
public function setMicrophone(mic:Microphone):void
{
this._mic = mic;
}
}
And I'd retrieve them in JavaScript like this:
var localUser = $('#localUser')[0];
localUser.getUserMedia();
var mic = localUser.getMicrophone();
var cam = localUser.getCamera();
And then pass them back into the instance that's actually communicating with the remote user like this:
var remoteUser = $('#remoteUser')[0];
remoteUser.setMicrophone(mic);
remoteUser.setCamera(cam);
Any known pitfalls associated with doing it that way? Is there a better way to handle this? (And before you ask, yes, in the absence of advice otherwise, I'm planning to code this up, and I'll let everyone know what I find - just want to know if there are any known pitfalls or alternatives before I get started. :-)