This manual consist info about Flashphoner Samples.
Samples is the examples of applications and functions that can be implemented in Flashphoner.
These examples are opensource and free. You can use them as you wish.
| Samples has no official supports from Flashphoner team. This is just examples. |
Auto login
Working scheme
Auto login may be used in personal pages.
This way uses token, which used for retrieving SIP login and SIP password at the server-side by this token.
So, SIP password can not be sniffed or intercepted in client-side.
Scheme:
- Web page uses flashvars to set token value for swf application.
- Flash application sends token value to Flashphoner-server
- Flashphoner-server sends a HTTP request to the authentication server, for example: http://authserver.mydomain.com?token=12345abcdef
- Authentication server returns an XML:
<sip_user sip_login="vasya" sip_password="123" sip_server="sipnet.ru" auth="true"/>
- Flashphoner-server uses the sip_user and sip_password to connect with a voip server.
If auth = "false", Flash-server rejects the connection.
Client implementation
We have changed 4 client files related standard Flashphoner-1.0.3.512 sources, you can find complete sources here: svn://flashphoner.com/branches/auto_login
- flashphoner_api FlashAPI.as
- flashphoner_api PhoneServerProxy.as
- flashphoner_client Phone.html
- flashphoner_client phone.mxml
- You need to add the token value in html page.
You may use any server-side technology as php, jsp, asp, cgi, e.t.c or plain HTML to do this.Phone.htmlflashvars.token="q1zaw2xse3cd"; - Use accepted token in phone.mxml
phone.mxml
var token:String; try{ if (Application.application.parameters != null && Application.application.parameters.token!=null){ token = Application.application.parameters.token; } } catch (e:Error){ token = ""; } DataPhone.getInstance().viewController.showConnectingView(); DataPhone.getInstance().flash_API.loginWithToken(token);
- Introduce Flash_API.loginWithToken() function.
Flash_API.as
public function loginWithToken(token:String):int{ ExternalInterface.call("notifyRegisterRequired",PhoneConfig.REGISTER_REQUIRED); if (PhoneConfig.REGISTER_REQUIRED){ upRegisteredTimer(); startRegisterTimer(); } return phoneServerProxy.loginWithToken(token); }
- Introduce PhoneServerProxy.loginWithToken() function.
PhoneServerProxy.as
public function loginWithToken(token:String):int{ var modelLocator:ModelLocator = flash_API.modelLocator; var obj:Object = new Object(); obj.registerRequired = PhoneConfig.REGISTER_REQUIRED; obj.token = token; obj.mode = "flashphoner"; modelLocator.mode="flashphoner"; nc.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler); nc.connect(PhoneConfig.SERVER_URL+"/"+PhoneConfig.APP_NAME,obj); return 0; }
Server implementation
Change method onConnect(IClient client, RequestFunction requestFunction, AMFDataList params) of FlashphonerApp.java.
Algorithm is quite simple: if we have no token, then the authorization goes through the usual algorithm, otherwise we will send a request to the auth-server.
Then we parse the xml answer, to get necessary data:sip_login, sip_password, e.t.c.
if (token == null) { //usual algorithm of the authorization } else { URL url; StringBuilder response = new StringBuilder(); try { url = new URL(AUTH_URL + token); URLConnection conn = url.openConnection(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); String line; while ((line = rd.readLine()) != null) { response.append(line); } rd.close(); Logger.logger.info("response from auth server - " + response.toString()); } catch (MalformedURLException e) { Logger.logger.error("ERROR - " + AUTH_URL + " is wrong;\n" + e); client.rejectConnection(); return; } catch (IOException e) { Logger.logger.error("ERROR - " + AUTH_URL + " is wrong;\n" + e); client.rejectConnection(); return; } Document dom; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); try { DocumentBuilder db = dbf.newDocumentBuilder(); InputStream in = new ByteArrayInputStream(response.toString().getBytes("UTF-8")); dom = db.parse(in); } catch (Exception e) { Logger.logger.error("ERROR - '" + response.toString() + "' has wrong format;\n" + e); client.rejectConnection(); return; } Element el = dom.getDocumentElement(); String temp = el.getAttribute("auth"); if (!(temp == null || "".equals(temp))) { regRequired = Boolean.parseBoolean(temp); } login = el.getAttribute("sip_login"); if (login == null || "".equals(login)) { Logger.logger.error("ERROR - '" + response.toString() + "' has wrong format;"); } password = el.getAttribute("sip_password"); if (password == null || "".equals(password)) { Logger.logger.error("ERROR - '" + response.toString() + "' has wrong format;"); } if (outboundProxy == null || "".equals(outboundProxy)) { sipProviderAddress = el.getAttribute("sip_server"); } else { sipProviderAddress = outboundProxy; } if (sipProviderAddress == null || "".equals(sipProviderAddress)) { Logger.logger.error("ERROR - '" + response.toString() + "' has wrong format;"); client.rejectConnection(); return; } String sipProviderPortString = el.getAttribute("sip_port"); if (sipProviderAddress == null || "".equals(sipProviderAddress)) { sipProviderPort = 5060; } else { try { sipProviderPort = Integer.parseInt(sipProviderPortString); } catch (NumberFormatException ex) { sipProviderPort = 5060; } } } rtmpClient = new RtmpClient(login, password, client, sipProviderAddress, sipProviderPort, visibleName, regRequired, APPLICATION_NAME, Config.MODE_FLASHPHONER);
You can download autologin sources here: svn://flashphoner.com/branches/auto_login
See also Developer guide - How to build sources