mongo-dart / lib / objectory / objectory_server.dart

vadimtsushko af4ea1f 


Map<String, String> contentTypes = const {
  "html": "text/html; charset=UTF-8",
  "dart": "application/dart",
  "js": "application/javascript", 

List<WebSocketConnection> connections;
void processMessage(message){
  print("in process message $message");
  if (message is String){
    Binary buffer = new Binary.from(message);    
    BsonMap command = new BsonMap(null);
void main() {
  connections = new List();
  WebSocketHandler wsHandler = new WebSocketHandler();
  wsHandler.onOpen = (WebSocketConnection conn) {
    print("Connection opened. Connections total: ${connections.length}");
    conn.onClosed = (a, b) => removeConnection(conn);
    conn.onError = (_) => removeConnection(conn);
    conn.onMessage = processMessage;

  HttpServer server = new HttpServer();
  server.addRequestHandler((_) => true, wsHandler.onRequest);   

  server.listen("", 8080);  
void removeConnection(WebSocketConnection conn) {
  int index = connections.indexOf(conn);
  if (index > -1) {
    connections.removeRange(index, 1);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.