Sub Class_Globals
Public ws As WebSocket
Private CallBack As Object
Private EventName As String
End Sub
Public Sub Initialize (vCallback As Object, vEventName As String)
CallBack = vCallback
EventName = vEventName
ws.Initialize("ws")
End Sub
Public Sub Connect(Url As String)
ws.Connect(Url)
End Sub
Public Sub Close
If ws.Connected Then ws.Close
End Sub
'Raises an event on the server. The Event parameter must include an underscore
Public Sub SendEventToServer(Event As String, Data As Map)
Dim m As Map
m.Initialize
m.Put("type", "event")
m.Put("event", Event)
m.Put("params", Data)
Dim jg As JSONGenerator
jg.Initialize(m)
ws.SendText(jg.ToString)
End Sub
Private Sub ws_TextMessage(msg As String)
Try
CallSub2(CallBack, EventName & "_TextMessage", msg)
Catch
Log("TextMessage Error: " & LastException)
End Try
End Sub
Private Sub ws_Connected
CallSub(CallBack, EventName & "_Connected")
End Sub
Private Sub ws_Closed (Reason As String)
CallSub2(CallBack, EventName & "_Closed", Reason)
End Sub