Files
DefinitelyTyped/autobahn/autobahn-tests.ts
Andy Hawkins — (̖̣͕̠̬̭̞̪̐̅ỉ̭̣͈̪̠ͮs̳̳̦̞̰̜̞̳͑͌͋ͪ̃̍ ̩̘́͑ͨ̈́̎̋ͮ͊̀ñ͔̣͓̬̈ͮͦ́ͫ͐͛ͅͅo̩̦̳̠̙̗̯̺̐͆̽t̜̥̻̙̟̼̜͂ͩ͋̅̈́ ̠̦̹̟͕͕̱͉͒͋̅́͐ā̟̻̱ͦ̒̍͋ ̗̞͚ͨͩ͊͂̉ͅh͔̼͚̩͚̪̝̝ͣa̫̫̒̓ͬc̦̲̳͍̹̃ͥͯk̲͕̗̖̤̙̜͍̊e̫͎̟̼̺̫̿r͙̰̊̑̿̅ͯͅ)̪̖͇̝̮̪͖̦͆̇ͧ͑̚ 5001f99793 add import to autobahn-test.ts
2015-08-02 14:26:46 -04:00

50 lines
1.2 KiB
TypeScript

/// <reference path="autobahn.d.ts"/>
import autobahn = require("autobahn");
class MyClass {
add2Count: number = 0;
session: autobahn.Session;
constructor(session: autobahn.Session) {
this.session = session;
}
add2(args: Array<number>): number {
this.add2Count++;
return args[0] + args[1];
}
onEvent(args: Array<any>): void {
console.log("Event:", args[0]);
}
}
function test_client() {
var options: autobahn.IConnectionOptions =
{ url: 'ws://127.0.0.1:8080/ws', realm: 'realm1' };
var connection = new autobahn.Connection(options);
connection.onopen = session => {
var myInstance = new MyClass(session);
// 1) subscribe to a topic
session.subscribe('com.myapp.hello', myInstance.onEvent);
// 2) publish an event
session.publish('com.myapp.hello', ['Hello, world!']);
// 3) register a procedure for remoting
session.register('com.myapp.add2', myInstance.add2);
// 4) call a remote procedure
session.call<number>('com.myapp.add2', [2, 3]).then(
res => {
console.log("Result:", res);
});
};
connection.open();
}