-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.lua
250 lines (224 loc) · 9.87 KB
/
test.lua
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
--
-- Project: Loowy
-- User: kostik
-- Date: 08.03.15
--
package.path = "../src/?.lua;" .. package.path
local config = {}
local wsServer
for line in io.lines('config.ini') do
local key, value = line:match("^(%w+)%s*=%s*(.+)$")
if key and value then
if tonumber(value) then value = tonumber(value) end
if value == "true" then value = true end
if value == "false" then value = false end
if key == 'wsServer' then
wsServer = value
else
config[key] = value
end
end
end
local printdump = require("loowy.vardump").printdump
local ev = require 'ev'
local loowy = require 'loowy.client'
local client1
local firstDisconnect = true
print('Connecting client to WAMP Server: ' .. wsServer)
client1 = loowy.new(wsServer, {
realm = config.realm,
maxRetries = config.maxRetries,
transportEncoding = config.transportEncoding,
debug = config.debug,
onConnect = function()
print('Got to WAMP Client instance onConnect callback')
print('Subscribing to topic.test1')
client1:subscribe('topic.test1', {
onSuccess = function()
print('Got to topic topic.test1 subscribe onSuccess')
print('Adding another subscription to topic.test1')
client1:subscribe('topic.test1', {
onSuccess = function()
print('Got to another topic topic.test1 subscribe onSuccess')
end,
onError = function(err)
print('Got to another topic topic.test1 subscribe onError: ' .. err.error)
end,
onEvent = function(evt)
print 'Got to another topic topic.test1 subscribe onEvent'
print('Event payload: ')
printdump(evt)
end
})
end,
onError = function(err)
print('Got to topic topic.test1 subscribe onError: ' .. err.error)
end,
onEvent = function(evt)
print 'Got to topic topic.test1 subscribe onEvent'
print('Event payload: ')
printdump(evt)
end
})
print('Publishing to topic.test1 without payload')
client1:publish('topic.test1', nil, {
onSuccess = function()
print('Got to publish to topic topic.test1 onSuccess')
end,
onError = function(err)
print('Got to publish to topic topic.test1 onError: ' .. err.error)
end
}, { disclose_me = true, exclude_me = false })
print('Publishing to topic.test1 with payload: string "string payload"')
client1:publish('topic.test1', "string payload", {
onSuccess = function()
print('Got to publish to topic topic.test1 onSuccess')
end,
onError = function(err)
print('Got to publish to topic topic.test1 onError: ' .. err.error)
end
}, { disclose_me = true, exclude_me = false })
print('Publishing to topic.test1 with payload: integer 25')
client1:publish('topic.test1', 25, {
onSuccess = function()
print('Got to publish to topic topic.test1 onSuccess')
end,
onError = function(err)
print('Got to publish to topic topic.test1 onError: ' .. err.error)
end
}, { disclose_me = true, exclude_me = false })
print('Publishing to topic.test1 with payload: array { 1, 2, 3, 4, 5 }')
client1:publish('topic.test1', { 1, 2, 3, 4, 5 }, {
onSuccess = function()
print('Got to publish to topic topic.test1 onSuccess')
end,
onError = function(err)
print('Got to publish to topic topic.test1 onError: ' .. err.error)
end
}, { disclose_me = true, exclude_me = false })
print('Publishing to topic.test1 with payload: table { key1 = "string", key2 = 100, key3 = true }')
client1:publish('topic.test1', { key1 = "string", key2 = 100, key3 = true }, {
onSuccess = function()
print('Got to publish to topic topic.test1 onSuccess')
end,
onError = function(err)
print('Got to publish to topic topic.test1 onError: ' .. err.error)
end
}, { disclose_me = true, exclude_me = false })
local unsubscribeTimer
unsubscribeTimer = ev.Timer.new(function()
unsubscribeTimer:stop(ev.Loop.default)
print('Unsubscribing from topic.test1')
client1:unsubscribe('topic.test1', {
onSuccess = function()
print('Got to unsubscribe from topic topic.test1 onSuccess')
print('Publishing to topic.test1 with string payload and settings: disclose_me = true, exclude_me = false')
print('We should not receive this event')
client1:publish('topic.test1', "unsubscribed event string", {
onSuccess = function()
print('Got to publish to unsubscribed topic topic.test1 onSuccess')
end,
onError = function(err)
print('Got to publish to unsubscribed topic topic.test1 onError: ' .. err.error)
end
}, { disclose_me = true, exclude_me = false })
end,
onError = function(err)
print('Got to unsubscribe from topic topic.test1 onError: ' .. err.error)
end
})
end, 10)
unsubscribeTimer:start(ev.Loop.default)
print('Registering new RPC rpc.test1')
client1:register('rpc.test1', {
rpc = function(data)
print('Invoked rpc.test1')
print('RPC payload')
printdump(data)
return { argsList = data.argsList, argsDict = data.argsDict }
end,
onSuccess = function()
print('Got to register rpc rpc.test1 onSuccess')
print('Calling rpc rpc.test1 without data')
client1:call('rpc.test1', nil, {
onSuccess = function(data)
print('Got to rpc call rpc.test1 onSuccess')
print('Call result')
printdump(data)
end,
onError = function(err)
print('Got to rpc call rpc.test1 onError: ' .. err.error)
end
}, { disclose_me = true, exclude_me = false })
print('Calling rpc rpc.test1 with payload: string "string payload"')
client1:call('rpc.test1', "string payload", {
onSuccess = function(data)
print('Got to rpc call rpc.test1 onSuccess')
print('Call result')
printdump(data)
end,
onError = function(err)
print('Got to rpc call rpc.test1 onError: ' .. err.error)
end
}, { disclose_me = true, exclude_me = false })
print('Calling rpc rpc.test1 with payload: integer 25')
client1:call('rpc.test1', 25, {
onSuccess = function(data)
print('Got to rpc call rpc.test1 onSuccess')
print('Call result')
printdump(data)
end,
onError = function(err)
print('Got to rpc call rpc.test1 onError: ' .. err.error)
end
}, { disclose_me = true, exclude_me = false })
print('Calling rpc rpc.test1 with payload: array { 1, 2, 3, 4, 5 }')
client1:call('rpc.test1', { 1, 2, 3, 4, 5 }, {
onSuccess = function(data)
print('Got to rpc call rpc.test1 onSuccess')
print('Call result')
printdump(data)
end,
onError = function(err)
print('Got to rpc call rpc.test1 onError: ' .. err.error)
end
}, { disclose_me = true, exclude_me = false })
print('Calling rpc rpc.test1 with payload: table { key1 = "string", key2 = 100, key3 = true }')
client1:call('rpc.test1', { key1 = "string", key2 = 100, key3 = true }, {
onSuccess = function(data)
print('Got to rpc call rpc.test1 onSuccess')
print('Call result')
printdump(data)
end,
onError = function(err)
print('Got to rpc call rpc.test1 onError: ' .. err.error)
end
}, { disclose_me = true, exclude_me = false })
end,
onError = function(err)
print('Got to register rpc rpc.test1 onError: ' .. err.error)
end
})
local disconnectTimer
disconnectTimer = ev.Timer.new(function()
disconnectTimer:stop(ev.Loop.default)
print('Disconnecting from WAMP Server')
client1:disconnect()
end, 30)
disconnectTimer:start(ev.Loop.default)
end,
onClose = function()
print('Got to WAMP Client instance onClose callback')
if firstDisconnect then
client1.connect()
firstDisconnect = false
end
end,
onError = function(err)
print('Got to WAMP Client instance onError callback: ' .. err.error)
end,
onReconnect = function()
print 'Got to WAMP Client instance onReconnect callback'
end
})
ev.Loop.default:loop()