Skip to content

Commit f8431bb

Browse files
author
epriestley
committed
Make Aphlict client somewhat more approachable
Summary: Provide a reasonable JS API for the Aphlict client. Provide an example behavior to invoke it. Test Plan: Ran "aphlict_server.js" with: $ sudo node aphlict_server.js Loaded /aphlict/. Opened console. Got "hello" from the server every second. Got reasonable errors with the server not present ("Security exception", but this is because it can't connect to port 843 to access the policy server). Reviewers: ddfisher, keebuhm, allenjohnashton, btrahan Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T944 Differential Revision: https://secure.phabricator.com/D1800
1 parent 1409279 commit f8431bb

File tree

13 files changed

+310
-23
lines changed

13 files changed

+310
-23
lines changed

src/__celerity_resource_map__.php

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,17 @@
321321
),
322322
'disk' => '/rsrc/css/application/herald/herald-test.css',
323323
),
324+
'javelin-aphlict' =>
325+
array(
326+
'uri' => '/res/50cae715/rsrc/js/application/aphlict/Aphlict.js',
327+
'type' => 'js',
328+
'requires' =>
329+
array(
330+
0 => 'javelin-install',
331+
1 => 'javelin-util',
332+
),
333+
'disk' => '/rsrc/js/application/aphlict/Aphlict.js',
334+
),
324335
'javelin-behavior' =>
325336
array(
326337
'uri' => '/res/0017f840/rsrc/js/javelin/lib/behavior.js',
@@ -331,6 +342,19 @@
331342
),
332343
'disk' => '/rsrc/js/javelin/lib/behavior.js',
333344
),
345+
'javelin-behavior-aphlict-listen' =>
346+
array(
347+
'uri' => '/res/6388e057/rsrc/js/application/aphlict/behavior-aphlict-listen.js',
348+
'type' => 'js',
349+
'requires' =>
350+
array(
351+
0 => 'javelin-behavior',
352+
1 => 'javelin-aphlict',
353+
2 => 'javelin-util',
354+
3 => 'javelin-stratcom',
355+
),
356+
'disk' => '/rsrc/js/application/aphlict/behavior-aphlict-listen.js',
357+
),
334358
'javelin-behavior-aphront-basic-tokenizer' =>
335359
array(
336360
'uri' => '/res/9be30797/rsrc/js/application/core/behavior-tokenizer.js',
@@ -1658,17 +1682,6 @@
16581682
),
16591683
'disk' => '/rsrc/css/application/slowvote/slowvote.css',
16601684
),
1661-
0 =>
1662-
array(
1663-
'uri' => '/res/b6096fdd/rsrc/js/javelin/lib/__tests__/URI.js',
1664-
'type' => 'js',
1665-
'requires' =>
1666-
array(
1667-
0 => 'javelin-uri',
1668-
1 => 'javelin-php-serializer',
1669-
),
1670-
'disk' => '/rsrc/js/javelin/lib/__tests__/URI.js',
1671-
),
16721685
'phabricator-standard-page-view' =>
16731686
array(
16741687
'uri' => '/res/7e09bbfc/rsrc/css/application/base/standard-page-view.css',
@@ -1892,6 +1905,17 @@
18921905
),
18931906
'disk' => '/rsrc/css/core/syntax.css',
18941907
),
1908+
0 =>
1909+
array(
1910+
'uri' => '/res/b6096fdd/rsrc/js/javelin/lib/__tests__/URI.js',
1911+
'type' => 'js',
1912+
'requires' =>
1913+
array(
1914+
0 => 'javelin-uri',
1915+
1 => 'javelin-php-serializer',
1916+
),
1917+
'disk' => '/rsrc/js/javelin/lib/__tests__/URI.js',
1918+
),
18951919
), array(
18961920
'packages' =>
18971921
array(

src/__phutil_library_map__.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@
445445
'MetaMTAConstants' => 'applications/metamta/constants/base',
446446
'MetaMTANotificationType' => 'applications/metamta/constants/notificationtype',
447447
'Phabricator404Controller' => 'applications/base/controller/404',
448+
'PhabricatorAphlictTestPageController' => 'applications/notifications/controller/test',
448449
'PhabricatorAuditActionConstants' => 'applications/audit/constants/action',
449450
'PhabricatorAuditAddCommentController' => 'applications/audit/controller/addcomment',
450451
'PhabricatorAuditComment' => 'applications/audit/storage/auditcomment',
@@ -621,6 +622,7 @@
621622
'PhabricatorMetaMTAViewController' => 'applications/metamta/controller/view',
622623
'PhabricatorMetaMTAWorker' => 'applications/metamta/worker',
623624
'PhabricatorMySQLFileStorageEngine' => 'applications/files/engine/mysql',
625+
'PhabricatorNotificationsController' => 'applications/notifications/controller/base',
624626
'PhabricatorOAuthClientAuthorization' => 'applications/oauthserver/storage/clientauthorization',
625627
'PhabricatorOAuthClientAuthorizationBaseController' => 'applications/oauthserver/controller/clientauthorization/base',
626628
'PhabricatorOAuthClientAuthorizationDeleteController' => 'applications/oauthserver/controller/clientauthorization/delete',
@@ -1247,6 +1249,7 @@
12471249
'ManiphestView' => 'AphrontView',
12481250
'MetaMTANotificationType' => 'MetaMTAConstants',
12491251
'Phabricator404Controller' => 'PhabricatorController',
1252+
'PhabricatorAphlictTestPageController' => 'PhabricatorNotificationsController',
12501253
'PhabricatorAuditAddCommentController' => 'PhabricatorAuditController',
12511254
'PhabricatorAuditComment' => 'PhabricatorAuditDAO',
12521255
'PhabricatorAuditCommitListView' => 'AphrontView',
@@ -1390,6 +1393,7 @@
13901393
'PhabricatorMetaMTAViewController' => 'PhabricatorMetaMTAController',
13911394
'PhabricatorMetaMTAWorker' => 'PhabricatorWorker',
13921395
'PhabricatorMySQLFileStorageEngine' => 'PhabricatorFileStorageEngine',
1396+
'PhabricatorNotificationsController' => 'PhabricatorController',
13931397
'PhabricatorOAuthClientAuthorization' => 'PhabricatorOAuthServerDAO',
13941398
'PhabricatorOAuthClientAuthorizationBaseController' => 'PhabricatorOAuthServerController',
13951399
'PhabricatorOAuthClientAuthorizationDeleteController' => 'PhabricatorOAuthClientAuthorizationBaseController',

src/aphront/default/configuration/AphrontDefaultApplicationConfiguration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ public function getURIMap() {
423423
'channel/(?P<channel>[^/]+)/' =>
424424
'PhabricatorChatLogChannelLogController',
425425
),
426+
427+
'/aphlict/' => 'PhabricatorAphlictTestPageController',
426428
);
427429
}
428430

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2012 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
abstract class PhabricatorNotificationsController
20+
extends PhabricatorController {
21+
22+
public function buildStandardPageResponse($view, array $data) {
23+
24+
$page = $this->buildStandardPageView();
25+
26+
$page->setApplicationName('Notifications');
27+
$page->setBaseURI('/notifications/');
28+
$page->setTitle(idx($data, 'title'));
29+
$page->setGlyph('!');
30+
$page->appendChild($view);
31+
32+
$response = new AphrontWebpageResponse();
33+
return $response->setContent($page->render());
34+
35+
}
36+
37+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'aphront/response/webpage');
10+
phutil_require_module('phabricator', 'applications/base/controller/base');
11+
12+
phutil_require_module('phutil', 'utils');
13+
14+
15+
phutil_require_source('PhabricatorNotificationsController.php');
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/*
4+
* Copyright 2012 Facebook, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
final class PhabricatorAphlictTestPageController
20+
extends PhabricatorNotificationsController {
21+
22+
public function processRequest() {
23+
24+
$instructions = '<h1>Check Your Javascript Console!</h1>';
25+
26+
$object_id = 'aphlictswfobject';
27+
28+
$content = phutil_render_tag(
29+
'object',
30+
array(
31+
'classid' => 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000',
32+
),
33+
'<param name="movie" value="/rsrc/swf/aphlict.swf" />'.
34+
'<param name="allowScriptAccess" value="always" />'.
35+
'<embed src="/rsrc/swf/aphlict.swf" id="'.$object_id.'"></embed>');
36+
37+
Javelin::initBehavior(
38+
'aphlict-listen',
39+
array(
40+
'id' => $object_id,
41+
'server' => '127.0.0.1',
42+
'port' => 2600,
43+
));
44+
45+
return $this->buildStandardPageResponse(
46+
array(
47+
$instructions,
48+
$content,
49+
),
50+
array(
51+
'title' => 'Aphlict Test Page',
52+
));
53+
}
54+
55+
56+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
/**
3+
* This file is automatically generated. Lint this module to rebuild it.
4+
* @generated
5+
*/
6+
7+
8+
9+
phutil_require_module('phabricator', 'applications/notifications/controller/base');
10+
phutil_require_module('phabricator', 'infrastructure/javelin/api');
11+
12+
phutil_require_module('phutil', 'markup');
13+
14+
15+
phutil_require_source('PhabricatorAphlictTestPageController.php');

support/aphlict/client/build_aphlict_client.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ set -x
1717
-output aphlict.swf \
1818
-default-background-color=0x444444 \
1919
-default-size=500,500 \
20-
-target-player=10.2.0 \
2120
-warnings=true \
2221
-debug=true \
2322
-source-path=$ROOT/externals/vegas/src \
2423
-static-link-runtime-shared-libraries=true \
2524
src/Aphlict.as)
2625

2726
mv $BASEDIR/aphlict.swf $ROOT/webroot/rsrc/swf/aphlict.swf
27+
28+
# -target-player=10.2.0 \

support/aphlict/client/src/Aphlict.as

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,26 @@ package {
2727
private var socket:Socket;
2828
private var readBuffer:ByteArray;
2929

30+
private var remoteServer:String;
31+
private var remotePort:Number;
32+
3033
public function Aphlict() {
3134
super();
3235

36+
ExternalInterface.addCallback('connect', this.externalConnect);
37+
ExternalInterface.call(
38+
'JX.Stratcom.invoke',
39+
'aphlict-component-ready',
40+
null,
41+
{});
42+
}
43+
44+
public function externalConnect(server:String, port:Number):void {
45+
this.externalInvoke('connect');
46+
47+
this.remoteServer = server;
48+
this.remotePort = port;
49+
3350
this.master = null;
3451
this.receiver = new AphlictReceiver(this);
3552
this.subjects = [];
@@ -90,25 +107,33 @@ package {
90107

91108
socket.addEventListener(Event.CONNECT, didConnectSocket);
92109
socket.addEventListener(Event.CLOSE, didCloseSocket);
93-
socket.addEventListener(IOErrorEvent.IO_ERROR, didErrorSocket);
94110
socket.addEventListener(ProgressEvent.SOCKET_DATA, didReceiveSocket);
95111

96-
socket.connect('127.0.0.1', 2600);
112+
socket.addEventListener(IOErrorEvent.IO_ERROR, didIOErrorSocket);
113+
socket.addEventListener(
114+
SecurityErrorEvent.SECURITY_ERROR,
115+
didSecurityErrorSocket);
116+
117+
socket.connect(this.remoteServer, this.remotePort);
97118

98119
this.readBuffer = new ByteArray();
99120
this.socket = socket;
100121
}
101122

102123
private function didConnectSocket(event:Event):void {
103-
this.log("Connect!");
124+
this.externalInvoke('connected');
104125
}
105126

106127
private function didCloseSocket(event:Event):void {
107-
this.log("Close!");
128+
this.externalInvoke('close');
129+
}
130+
131+
private function didIOErrorSocket(event:IOErrorEvent):void {
132+
this.externalInvoke('error', event.text);
108133
}
109134

110-
private function didErrorSocket(event:Event):void {
111-
this.log("Error!");
135+
private function didSecurityErrorSocket(event:SecurityErrorEvent):void {
136+
this.externalInvoke('error', event.text);
112137
}
113138

114139
private function didReceiveSocket(event:Event):void {
@@ -126,7 +151,7 @@ package {
126151
var msg_len:Number = parseInt(b.readUTFBytes(8), 10);
127152
if (b.length >= msg_len + 8) {
128153
var bytes:String = b.readUTFBytes(msg_len);
129-
var data:Object = JSON.deserialize(bytes);
154+
var data:Object = vegas.strings.JSON.deserialize(bytes);
130155
var t:ByteArray = new ByteArray();
131156
t.writeBytes(b, msg_len + 8);
132157
this.readBuffer = t;
@@ -150,11 +175,15 @@ package {
150175
}
151176

152177
public function receiveMessage(msg:Object):void {
153-
this.log("Received message!");
178+
this.externalInvoke('receive', msg);
179+
}
180+
181+
public function externalInvoke(type:String, object:Object = null):void {
182+
ExternalInterface.call('JX.Aphlict.didReceiveEvent', type, object);
154183
}
155184

156-
public function log(msg:String):void {
157-
ExternalInterface.call('console.log', msg);
185+
public function log(message:String):void {
186+
ExternalInterface.call('console.log', message);
158187
}
159188

160189
}

support/aphlict/server/aphlict_server.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ function getFlashPolicy() {
66
'<!DOCTYPE cross-domain-policy SYSTEM ' +
77
'"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">',
88
'<cross-domain-policy>',
9-
'<allow-access-from domain="*" to-ports="*"/>',
9+
'<allow-access-from domain="*" to-ports="2600"/>',
1010
'</cross-domain-policy>'
1111
].join("\n");
1212
}

0 commit comments

Comments
 (0)