-
Notifications
You must be signed in to change notification settings - Fork 0
/
wamp_adapter.js
91 lines (63 loc) · 2.02 KB
/
wamp_adapter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/******************************************************************************
*
* Copyright 2012-2014 Tavendo GmbH.
*
* Apache License
* Version 2.0, January 2004
* http://www.apache.org/licenses/
*
******************************************************************************/
// Create keyboard events to control HexGL racing game based on WAMP events
"use strict";
var demoRealm = "crossbardemo";
// var wsuri = "ws://192.168.1.143:8080/ws";
var wsuri = "wss://demo.crossbar.io/ws";
// if (document.location.origin == "file://") {
// wsuri = "ws://127.0.0.1:8080/ws";
// } else {
// wsuri = (document.location.protocol === "http:" ? "ws:" : "wss:") + "//" +
// document.location.host + "/ws";
// }
var session;
var connection = null;
function connect() {
connection = new autobahn.Connection({
url: wsuri,
realm: demoRealm
}
);
connection.onopen = function (sess) {
console.log("connected");
session = sess;
setupConnector();
};
connection.onclose = function() {
session = null;
console.log("connection closed ", arguments);
}
connection.open();
}
connect();
function setupConnector() {
// subscribe to the control event
session.subscribe("io.crossbar.demo.gamecontrol.on_event", function (args) {
console.log("received movement", args[0]);
var movement = args[0];
switch (movement) {
case "up":
abControl("up", false);
break;
case "upFast":
abControl("up", true);
break;
case "down":
abControl("down", false);
break;
case "downFast":
abControl("down", true);
case "rest":
abControls_p1();
break;
}
});
}