29 using System.Collections.Generic;
30 using System.Reflection;
31 using OpenSim.Framework.Servers;
35 using OpenSim.Region.Framework.Interfaces;
36 using OpenSim.Region.Framework.Scenes;
38 using OpenSim.Framework.Servers.HttpServer;
44 [Extension(Path =
"/OpenSim/RegionModules", NodeName =
"RegionModule", Id =
"WebSocketEchoModule")]
47 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
50 public string Name {
get {
return "WebSocketEchoModule"; } }
52 public Type ReplaceableInterface {
get {
return null; } }
55 private HashSet<WebSocketHttpServerHandler> _activeHandlers =
new HashSet<WebSocketHttpServerHandler>();
59 enabled = (pConfig.Configs[
"WebSocketEcho"] != null);
70 MainServer.Instance.AddWebSocketHandler(
"/echo", WebSocketHandlerCallback);
76 SubscribeToEvents(handler);
77 handler.SetChunksize(8192);
78 handler.NoDelay_TCP_Nagle =
true;
79 handler.HandshakeAndUpgrade();
85 handler.OnClose += HandlerOnOnClose;
86 handler.OnText += HandlerOnOnText;
87 handler.OnUpgradeCompleted += HandlerOnOnUpgradeCompleted;
88 handler.OnData += HandlerOnOnData;
89 handler.OnPong += HandlerOnOnPong;
94 handler.OnClose -= HandlerOnOnClose;
95 handler.OnText -= HandlerOnOnText;
96 handler.OnUpgradeCompleted -= HandlerOnOnUpgradeCompleted;
97 handler.OnData -= HandlerOnOnData;
98 handler.OnPong -= HandlerOnOnPong;
101 private void HandlerOnOnPong(
object sender,
PongEventArgs pongdata)
103 m_log.Info(
"[WebSocketEchoModule]: Got a pong.. ping time: " + pongdata.PingResponseMS);
109 obj.SendData(data.Data);
110 m_log.Info(
"[WebSocketEchoModule]: We received a bunch of ugly non-printable bytes");
118 _activeHandlers.Add(obj);
124 obj.SendMessage(text.Data);
125 m_log.Info(
"[WebSocketEchoModule]: We received this: " + text.Data);
129 private void HandlerOnOnClose(
object sender,
CloseEventArgs closedata)
132 UnSubscribeToEvents(obj);
134 lock (_activeHandlers)
135 _activeHandlers.Remove(obj);
148 WebSocketHttpServerHandler[] items =
new WebSocketHttpServerHandler[_activeHandlers.Count];
149 _activeHandlers.CopyTo(items);
151 for (
int i = 0; i < items.Length; i++)
153 items[i].Close(string.Empty);
156 _activeHandlers.Clear();
157 MainServer.Instance.RemoveWebSocketHandler(
"/echo");
void AddRegion(Scene scene)
This is called whenever a Scene is added. For shared modules, this can happen several times...
This class implements websockets. It grabs the network context from C::Webserver and utilizes it dire...
void RegionLoaded(Scene scene)
This will be called once for every scene loaded. In a shared module this will be multiple times in on...
void PostInitialise()
This method sets up the callback to WebSocketHandlerCallback below when a HTTPRequest comes in for /e...
void Initialise(IConfigSource pConfig)
This is called to initialize the region module. For shared modules, this is called exactly once...
void WebSocketHandlerCallback(string path, WebSocketHttpServerHandler handler)
void RemoveRegion(Scene scene)
This is called whenever a Scene is removed. For shared modules, this can happen several times...
Interactive OpenSim region server
void UnSubscribeToEvents(WebSocketHttpServerHandler handler)
void SubscribeToEvents(WebSocketHttpServerHandler handler)