# Path: lib/socketiogame.py
# class SocketApp(object):
#     def __init__(self):
#         self.buffer = []
#         self.request = {}
# 
#     def __call__(self, environ, start_response):
#         path = environ['PATH_INFO'].strip('/')
# 
#         if not path:
#             headers = [('Location', '/client/index.html'), ]
#             start_response('301 Redirect', headers)
#             return []
# 
#         if path.startswith('client/'):
#             mode = 'rb'
#             if path.endswith(".png"):
#                 content_type = "image/png"
#             elif path.endswith(".js"):
#                 mode = 'r'
#                 content_type = "text/javascript"
#             elif path.endswith(".css"):
#                 mode = 'r'
#                 content_type = "text/css"
#             elif path.endswith(".swf"):
#                 content_type = "application/x-shockwave-flash"
#             else:
#                 mode = 'r'
#                 content_type = "text/html"
# 
#             try:
#                 data = open(path.replace('/', os.sep), mode).read()
#             except Exception:
#                 return self.not_found(start_response)
# 
#             start_response('200 OK', [('Content-Type', content_type)])
#             return [data]
# 
#         if path.startswith("socket.io"):
#             socketio_manage(environ, {'': GameNamespace}, self.request)
#         else:
#             return self.not_found(start_response)
# 
#     def not_found(self, start_response):
#         start_response('404 Not Found', [])
#         return ['<h1>Not Found</h1>']


from socketio.server import SocketIOServer
from lib.socketiogame import SocketApp
from multiprocessing import Process, Queue
from gi.repository import WebKit
from gi.repository import Gtk
from gi.repository import GObject as gobject
    server = SocketIOServer(('0.0.0.0', 0), SocketApp(), policy_server=False)
    server.start()
    port = server.socket.getsockname()[1]
    q.put(port)
    server.serve_forever()


class mywindow(Gtk.Window):
    def __init__(self, url):
        Gtk.Window.__init__(self)
        self.browser = WebKit.WebView()
        self.browser.open(url)
        self.add(self.browser)
        self.show()

    def quit(self, *args):
        self.hide()
        self.destroy()


class App():
    def __init__(self):
        q = Queue()
        self.ioserver = Process(target=socketio_server, args=(q,))
        self.ioserver.start()
        port = q.get()

        gobject.threads_init()
        self.mainloop = gobject.MainLoop()


# Path: lib/socketiogame.py
# class SocketApp(object):
#     def __init__(self):
#         self.buffer = []
#         self.request = {}
# 
#     def __call__(self, environ, start_response):
#         path = environ['PATH_INFO'].strip('/')
# 
#         if not path:
#             headers = [('Location', '/client/index.html'), ]
#             start_response('301 Redirect', headers)
#             return []
# 
#         if path.startswith('client/'):
#             mode = 'rb'
#             if path.endswith(".png"):
#                 content_type = "image/png"
#             elif path.endswith(".js"):
#                 mode = 'r'
#                 content_type = "text/javascript"
#             elif path.endswith(".css"):
#                 mode = 'r'
#                 content_type = "text/css"
#             elif path.endswith(".swf"):
#                 content_type = "application/x-shockwave-flash"
#             else:
#                 mode = 'r'
#                 content_type = "text/html"
# 
#             try:
#                 data = open(path.replace('/', os.sep), mode).read()
#             except Exception:
#                 return self.not_found(start_response)
# 
#             start_response('200 OK', [('Content-Type', content_type)])
#             return [data]
# 
#         if path.startswith("socket.io"):
#             socketio_manage(environ, {'': GameNamespace}, self.request)
#         else:
#             return self.not_found(start_response)
# 
#     def not_found(self, start_response):
#         start_response('404 Not Found', [])
#         return ['<h1>Not Found</h1>']


# Path: gtk-webview.py
from socketio.server import SocketIOServer
from lib.socketiogame import SocketApp
from multiprocessing import Process, Queue
from gi.repository import WebKit
from gi.repository import Gtk
from gi.repository import GObject as gobject

    server = SocketIOServer(('0.0.0.0', 0), SocketApp(), policy_server=False)
    server.start()
    port = server.socket.getsockname()[1]
    q.put(port)
    server.serve_forever()


class mywindow(Gtk.Window):
    def __init__(self, url):
        Gtk.Window.__init__(self)
        self.browser = WebKit.WebView()
        self.browser.open(url)
        self.add(self.browser)
        self.show()

    def quit(self, *args):
        self.hide()
        self.destroy()


class App():
    def __init__(self):
        q = Queue()
        self.ioserver = Process(target=socketio_server, args=(q,))
        self.ioserver.start()
        port = q.get()

        gobject.threads_init()
        self.mainloop = gobject.MainLoop()


        url = 'http://google.com'