Exemplo n.º 1
0
def index():
    '''
    posts = [
        {
            'author': {'username': '******'},
            'body': 'Beautiful day in Portland!'
        },
        {
            'author': {'username': '******'},
            'body': 'The Avengers movie was so cool!'
        }
    ]
    '''
    # create namespace for user here
    # also create session?
    print(current_user.username)
    print(current_user.email)

    # remove spaces and add forward slash to create namespace
    temp_namespace = "/" + (current_user.username).replace(" ", "")
    print(temp_namespace)

    # create a namespace for a user profile
    socketio.on_namespace(MyNamespace(temp_namespace))

    return render_template('index.html', title='Home')#, posts=posts)
Exemplo n.º 2
0
            return

        if len(encounter.characters) <= 0:
            encounter.running = False
            InitiativeNamespace.emit_new_state(broadcast=True)
            return

        next_character = encounter.characters[0]
        current_passed = False
        for character in encounter.characters:
            if current_passed:
                next_character = character
                break

            if character.id == encounter.current_character_id:
                current_passed = True
                continue

        print('Next turn: {}'.format(next_character.name))
        encounter.current_character_id = next_character.id
        db.session.commit()
        InitiativeNamespace.emit_new_state(broadcast=True)


socketio.on_namespace(InitiativeNamespace('/initiative'))


@app.route('/')
def home():
    return 'Nothing to see here!'
Exemplo n.º 3
0
def init_room_namespaces():
    for room in db.rooms.page_by_page(1):
        if room:
            socketio.on_namespace(RoomNamespace('/' + room[0].id))
Exemplo n.º 4
0
# pylint: disable=unused-import
from app import app, socketio
from web_sockets import GameCore
from game import Chess
from views import index

if __name__ == '__main__':
    socketio.on_namespace(GameCore('/'))
    socketio.run(app, port=5000, use_reloader=True)
Exemplo n.º 5
0
        },
             room=message['room'])

    def on_disconnect_request(self):
        session['receive_count'] = session.get('receive_count', 0) + 1
        emit('my_response', {
            'data': 'Disconnected!',
            'count': session['receive_count']
        })
        disconnect()

    def on_my_ping(self):
        emit('my_pong')

    def on_connect(self):
        global thread
        with thread_lock:
            if thread is None:
                thread = socketio.start_background_task(
                    target=background_thread)
        emit('my_response', {'data': 'Connected', 'count': 0})

    def on_disconnect(self):
        print('Client disconnected', request.sid)


socketio.on_namespace(MyNamespace('/test'))

if __name__ == '__main__':
    socketio.run(app)
Exemplo n.º 6
0
# encoding: utf-8

from app import api, app, socketio

from app.api.user import UserData, Email, ForgetPassword, Token, Password
from app.api.room import RoomData, Join
from app.api.socket import RoomData as socket

api.add_resource(UserData, '/api/user/current')
api.add_resource(Email, '/api/user/email')
api.add_resource(ForgetPassword, '/api/user/forget')
api.add_resource(Token, '/api/user/token')
api.add_resource(Password, '/api/user/password')
api.add_resource(RoomData, '/api/room/data')
api.add_resource(Join, '/api/room/join')
socketio.on_namespace(socket())

if __name__ == '__main__':
    # app.run(debug=True)
    socketio.run(app, host='127.0.0.1', port=5000)
Exemplo n.º 7
0
    def on_my_ping(self):
        emit('my_pong')

    def on_a911_alarm(self, message):
        emit('a911_alarm', {'type': 'alarm', 'id': message['id']}, \
            broadcast=True)

    def on_a911_alarms(self, message):
        emit('a911_alarms', {'type': 'alarm', 'id': message['ids']}, \
            broadcast=True)

    def on_client_refresh(self, message):
        emit('client_refresh', {'type': 'admin', 'station': message['station']},\
            broadcast=True)

    def on_connect(self):
        global thread
        with thread_lock:
            if thread is None:
                thread = socketio.start_background_task(active911_thread, \
                            current_app._get_current_object())

        emit('my_response', {'data': 'Connected', 'count': 0})

    def on_disconnect(self):
        pass


socketio.on_namespace(AFDNamespace('/afd'))
Exemplo n.º 8
0
            # return emit({'status': 'fail', 'text': 'Что-то пошло не так...'})

        sender_id, claims = self.init()

        ids = Message.query.with_entities(
            Message.sender_id, Message.receiver_id).filter(
                Message.chat_room == data['chat_id'], ).first()

        receiver_id = ids.receiver_id if ids.sender_id == sender_id else ids.sender_id
        room = "_".join(sorted([str(sender_id), str(receiver_id)]))

        message = Message(sender_id=sender_id,
                          chat_room=data['chat_id'],
                          receiver_id=receiver_id,
                          text=data['message'])

        db.session.add(message)
        db.session.commit()

        emit('response_message', {
            'nickname': claims['nickname'],
            'sent_at': message.sent_at.strftime("%H:%M"),
            'sender_id': sender_id,
            'text': message.text
        },
             room=room)


Chat.register(bp)
socketio.on_namespace(Chat())
Exemplo n.º 9
0
def index():
    # remove spaces and add forward slash to create namespace
    temp_namespace = "/" + (current_user.username).replace(" ", "")
    # create a namespace for a user profile
    socketio.on_namespace(MyNamespace(temp_namespace))
    return render_template('index.html', title='Home')
Exemplo n.º 10
0
import os

from app import create_app, db, socketio
from server.chat import Chat
from flask_script import Manager, Shell
from flask_migrate import Migrate, MigrateCommand

app = create_app('development')
manager = Manager(app=app)
socketio.on_namespace(Chat('/chat'))


def make_shell_context():
    return dict(app=app, db=db)


manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command(
    'run', socketio.run(app=app, host='127.0.0.1', port=8000, debug=True))

if __name__ == '__main__':
    manager.run()
Exemplo n.º 11
0
        print("emit_join ")
        socketio.emit('player_join', {user.username: {
                             'avatar': user.avatar,
                             'entry': user.entry,
                             'votes': user.votes_received
                             }}, room=user.arena_id, namespace=self.namespace)

    def emit_player_leave(self, user):
        print("emit_leave ")
        socketio.emit('player_leave', {"username": user.username}, room=user.arena_id, namespace=self.namespace)

    def emit_entry_update(self, user, entry):
        print('emit_entry ')
        socketio.emit('entry_update', {user.username: { 'entry':entry}}, room=user.arena_id, namespace=self.namespace)

    def emit_votes_changed(self, user):
        print('emit_votes ')
        socketio.emit('votes_changed', {user.username: { 'votes': user.votes_received }}, room=user.arena_id, namespace=self.namespace)

    def emit_new_notification(self, room, notif):
        print('emit_notification ', room)
        socketio.emit('new_notification', {'message': notif.message, 'type': notif.type}, room=room, namespace=self.namespace)

    def emit_arena_end(self, user):
        print('emit_arena_end ')
        socketio.emit('arena_end', room=user.arena_id, namespace=self.namespace)


arena_room = Arena_Room('/sock')
socketio.on_namespace(arena_room)
Exemplo n.º 12
0
        emit('my_pong')

    def on_connect(self):
        session['socket_id'] = request.sid
        emit('my_response', {'data': 'Connected', 'count': 0})

    def on_background_start(self, data):
        _id = session['socket_id']
        try:
            if running_process[_id] is False:
                running_process[_id] = True
                socketio.start_background_task(background_thread, _id, data)
        except KeyError:
            running_process[_id] = True
            socketio.start_background_task(background_thread, _id, data)

        emit('connection_response', {
            'data': 'Connected',
            'id': session['socket_id']
        })

    def on_disconnect(self):
        _id = session['socket_id']
        running_process[_id] = False
        print('Client disconnected', request.sid)
        disconnect()


socketio.on_namespace(RedditIO('/reddit'))
# socketio.on_namespace(UpworkIO('/reddit'))
Exemplo n.º 13
0
from app import socketio

from .sio_modles import Q8INamespace

# https://www.jianshu.com/p/3c3e18456ccc Flask-socketio多workers实现

# ## 管理中心消息
socketio.on_namespace(Q8INamespace('/sio_q8i'))
Exemplo n.º 14
0
Url /v1/token/check/ for check token,
Url /v1/test/ for test connect to api,

Class Logan is for user registrations,email confirmed and change password,
Class RestorPassword is for restor user is password,
Class Forum is output categories and questions this category,
Class ForumPost  output user's message this questions,
socketio Connects 
'''

app.add_url_rule('/v1/authorization/',
                 view_func=authorization,
                 methods=['POST'])
app.add_url_rule('/v1/token/check/', view_func=checktoken, methods=['POST'])
app.add_url_rule('/v1/test/',
                 view_func=tees,
                 methods=['GET', 'POST', 'PUT', 'DELETE'])

api.add_resource(Logan, '/v1/login/', '/v1/login/<public_id>',
                 '/v1/login/confirm/<token>')
api.add_resource(RestorPassword, '/v1/login/restore_password/<token>/',
                 '/v1/login/restore_password/')
api.add_resource(Forum, '/v1/get/<key>/', '/v1/add/<cate>/')
api.add_resource(ForumPosts, '/v1/get/public_id/<key>/', '/v1/put/public_id/')

socketio.on_namespace(Chat('/v1/chats/'))

got_request_exception.connect(log_exception, app)

if __name__ == '__main__':
    socketio.run(app)
Exemplo n.º 15
0
                'status': 'typing'
            },
                 room=room,
                 include_self=False)
        if status == '0':
            emit('status', {
                'user': current_user.username,
                'status': 'not_typing'
            },
                 room=room,
                 include_self=False)

    @authenticated_only
    def on_disconnect(self):
        print("Executing user logged in")
        current_user.user_info.status = "offline"
        emit('status', {
            'user': current_user.username,
            'status': 'user_offline'
        },
             room=current_user.key[0],
             include_self=False)
        print('Client Disconnected', request.sid)

    @authenticated_only
    def on_connect(self):
        print('Client connected', request.sid)


socketio.on_namespace(ChatIO('/api/chat'))