Changeset View
Changeset View
Standalone View
Standalone View
support/aphlict/client/src/AphlictClient.as
| package { | package { | ||||
| import flash.events.TimerEvent; | import flash.events.TimerEvent; | ||||
| import flash.external.ExternalInterface; | import flash.external.ExternalInterface; | ||||
| import flash.utils.Dictionary; | |||||
| import flash.utils.Timer; | import flash.utils.Timer; | ||||
| final public class AphlictClient extends Aphlict { | final public class AphlictClient extends Aphlict { | ||||
| /** | /** | ||||
| * The connection name for this client. This will be used for the | * The connection name for this client. This will be used for the | ||||
| * @{class:LocalConnection} object. | * @{class:LocalConnection} object. | ||||
| Show All 25 Lines | public function AphlictClient() { | ||||
| ExternalInterface.addCallback('connect', this.externalConnect); | ExternalInterface.addCallback('connect', this.externalConnect); | ||||
| ExternalInterface.call( | ExternalInterface.call( | ||||
| 'JX.Stratcom.invoke', | 'JX.Stratcom.invoke', | ||||
| 'aphlict-component-ready', | 'aphlict-component-ready', | ||||
| null, | null, | ||||
| {}); | {}); | ||||
| } | } | ||||
| public function externalConnect(server:String, port:Number):void { | public function externalConnect( | ||||
| server:String, | |||||
| port:Number, | |||||
| subscriptions:Array):void { | |||||
| this.externalInvoke('connect'); | this.externalInvoke('connect'); | ||||
| this.remoteServer = server; | this.remoteServer = server; | ||||
| this.remotePort = port; | this.remotePort = port; | ||||
| this.client = AphlictClient.generateClientId(); | this.client = AphlictClient.generateClientId(); | ||||
| this.recv.connect(this.client); | this.recv.connect(this.client); | ||||
| this.timer = new Timer(AphlictClient.INTERVAL); | this.timer = new Timer(AphlictClient.INTERVAL); | ||||
| this.timer.addEventListener(TimerEvent.TIMER, this.keepalive); | this.timer.addEventListener(TimerEvent.TIMER, this.keepalive); | ||||
| this.connectToMaster(); | this.connectToMaster(); | ||||
| // Send subscriptions to master. | |||||
| this.log('Sending subscriptions to master.'); | |||||
| this.send.send('aphlict_master', 'subscribe', this.client, subscriptions); | |||||
| } | } | ||||
| /** | /** | ||||
| * Generate a unique identifier that will be used to communicate with the | * Generate a unique identifier that will be used to communicate with the | ||||
| * @{class:AphlictMaster}. | * @{class:AphlictMaster}. | ||||
| */ | */ | ||||
| private static function generateClientId():String { | private static function generateClientId():String { | ||||
| return 'aphlict_client_' + Math.round(Math.random() * 100000); | return 'aphlict_client_' + Math.round(Math.random() * 100000); | ||||
| ▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines | |||||