Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
Try
ws = WebSocket1
If ws.Session = Null Then
Return
End If
' Log(ws.Session.Id)
modFunctions.LogText("Session ID " & ws.Session.Id, False)
Dim info As ClientInfo
info.Initialize
info.UserID = Rnd(1, 100) & " RND Has to be user ID " & DateTime.Time(DateTime.Now) ' Write this yourself or use a counter/UUID
info.UserName = "Anonymous" ' Or detect from query params
info.IsPlayer = False ' Set to True for your local Music Player if needed
info.SessionID = ws.Session.Id
Main.connectedClients.Put(ws, info)
If ServerTimer.IsInitialized = False Then
ServerTimer.Initialize("ServerTimer", 5000)
ServerTimer.Enabled = True
End If
End Sub
If I like to access 1 websocket I get the ID from Subs like this in a other Class
Public Sub Broadcast_List(ws As WebSocket, FunctionName As String, Data As List, sendToAll As Boolean)
If sendToAll = True Then
For Each objWs As Object In Main.connectedClients.Keys
Dim tmpWS As WebSocket = objWs
tmpWS.RunFunction(FunctionName, Array(Data))
tmpWS.Flush
Next
Else
Dim sessionID As String = GetWebSocketID(ws)
For Each objWs As Object In Main.connectedClients.Keys
Dim tmpWS As WebSocket = objWs
Log(tmpWS.Session.Id)
If tmpWS.Session.Id = sessionID Then
tmpWS.RunFunction(FunctionName, Array(Data))
tmpWS.Flush
Exit
End If
Next
End If
End Sub