...
This example is a two-directional video chat using a client Flash application executed as a simple swf file.
The example demonstrates operation of a Flash video chat that allows two-directional video communication to the same example for iOS, Android or Web SDK.
The screenshot displays operation of the Flash video chat.
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
session = new Session(url, username); session.on(SessionStatus.FAILED, function():void{ setStatus(sessionStatus, SessionStatus.FAILED); onLeft(); }).on(SessionStatus.DISCONNECTED, function():void { setStatus(sessionStatus, SessionStatus.DISCONNECTED); onLeft(); }).on(SessionStatus.ESTABLISHED, function():void { setStatus(sessionStatus, SessionStatus.ESTABLISHED); joinRoom(); }); session.connect(); |
3. While the participant joins the room, the reactions to various events in the room are added. line 150
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
session.join(this.roomName).on(RoomStatus.STATE, function(room:Room):void{ var participants:Array = room.getParticipants(); setInviteAddress(room); if (participants.length > 0) { var chatState:String = "participants: "; for (var i:Number = 0; i < participants.length; i++) { installParticipant(participants[i]); chatState += participants[i].getName(); if (i != participants.length - 1) { chatState += ","; } } } } addMessage("chat", chatState); } else { addMessage("chat", " room is empty"); } publishLocalMedia(room); onJoined(room); }).on(RoomStatus.JOINED, function(participant:Participant):void{ installParticipant(participant); addMessage(participant.getName(), "joined"); }).on(RoomStatus.LEFT, function(participant:Participant):void{ removeParticipant(); addMessage(participant.getName(), "left"); }).on(RoomStatus.PUBLISHED, function(participant:Participant):void{ playParticipantsStream(participant); }).on(RoomStatus.FAILED, function(room:Room, info:Object):void{ failedInfo.text = info.info; session.disconnect(); }).on(RoomStatus.MESSAGE, function(message:Object):void{ addMessage(message.from.getName(), message.text); }); |
4. Publishing the video stream from the web camera to the WCS server. line 232
| Code Block | ||||
|---|---|---|---|---|
| ||||
private function publishLocalMedia(room:Room):void {
var stream:NetStream = room.publish(mic, cam);
stream.addEventListener(NetStatusEvent.NET_STATUS, function(event:NetStatusEvent):void{
Logger.info("handlePublishStreamStatus: "+event.info.code);
switch (event.info.code) {
case "NetStream.Publish.BadName":
setStatus(streamStatus, "FAILED");
onMediaStopped(room);
break;
case "NetStream.Unpublish.Success":
setStatus(streamStatus, "UNPUBLISHED");
onMediaStopped(room);
break;
case "NetStream.Publish.Start":
setStatus(streamStatus, "PUBLISHING");
onMediaPublished(stream);
break;
}
});
} |
5. Playing the stream of another participant. line 207
| Code Block | ||||
|---|---|---|---|---|
| ||||
private function playParticipantsStream(p:Participant):void
{
var stream:NetStream = p.play();
if (stream != null) {
remoteDisplay.attachNetStream(stream);
stream.addEventListener(NetStatusEvent.NET_STATUS, function(event:NetStatusEvent):void{
Logger.info("handlePlayStreamStatus: "+event.info.code);
switch (event.info.code) {
case "NetStream.Video.DimensionChange":
var res:Object = downScaleToFitSize(remoteDisplay.videoWidth, remoteDisplay.videoHeight, display.width, display.height);
remoteDisplay.width = res.w;
remoteDisplay.height = res.h;
remoteDisplayHolder.width = res.w;
remoteDisplayHolder.height = res.h;
break;
case "NetStream.Play.UnpublishNotify":
case "NetStream.Play.Stop":
remoteDisplay.clear();
break;
}
});
}
} |