Basic websocket test on connect

This commit is contained in:
Jeremy Zhang 2017-08-19 05:09:13 +00:00
parent d7ac9fd9c9
commit 6b3ada44db
5 changed files with 18 additions and 1 deletions

View File

@ -3,7 +3,7 @@ from .database import db
from flask import Flask, render_template, request, session, url_for, redirect, jsonify
from flask_sslify import SSLify
from titanembeds.utils import rate_limiter, discord_api, bot_alive, socketio
from .blueprints import api, user, admin, embed
from .blueprints import api, user, admin, embed, gateway
import os
from titanembeds.database import get_administrators_list
@ -26,6 +26,7 @@ app.register_blueprint(api.api, url_prefix="/api", template_folder="/templates")
app.register_blueprint(admin.admin, url_prefix="/admin", template_folder="/templates")
app.register_blueprint(user.user, url_prefix="/user", template_folder="/templates")
app.register_blueprint(embed.embed, url_prefix="/embed", template_folder="/templates")
socketio.on_namespace(gateway.Gateway('/gateway'))
@app.route("/")
def index():

View File

@ -0,0 +1 @@
from .gateway import Gateway

View File

@ -0,0 +1,6 @@
from titanembeds.utils import socketio
from flask_socketio import Namespace, emit
class Gateway(Namespace):
def on_connect(self):
emit('key', {'data': 'Connected', 'best_pone': "rainbow"})

View File

@ -7,6 +7,8 @@
/* global localStorage */
/* global visitors_enabled */
/* global cheet */
/* global location */
/* global io */
(function () {
const theme_options = ["DiscordDark", "BetterTitan"]; // All the avaliable theming names
@ -247,6 +249,12 @@
} else {
primeEmbed();
}
/* SocketIO Test */
var socket = io.connect(location.protocol + '//' + document.domain + ':' + location.port + "/gateway");
socket.on('connect', function() {
console.log("Socket.IO Connected!");
});
});
function changeTheme(theme=null, keep_custom_css=true) {

View File

@ -197,6 +197,7 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/jQuery-linkify/2.1.4/linkify.min.js" integrity="sha256-/qh8j6L0/OTx+7iY8BAeLirxCDBsu3P15Ci5bo7BJaU=" crossorigin="anonymous"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jQuery-linkify/2.1.4/linkify-jquery.min.js" integrity="sha256-BlSfVPlZijMLojgte2AtSget879chk1+8Z8bEH/L4Cs=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cheet.js/0.3.3/cheet.min.js" integrity="sha256-FxQrnIC3BX45JRzOyFUlKiM6dY3A/ZakV6w4WpYyfyA=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.3/socket.io.js" integrity="sha256-sdmLD9jD1PIzq3KOQPNSGZYxjv76rds79Mnyk5JNp1M=" crossorigin="anonymous"></script>
{% raw %}
<script id="mustache_channellistings" type="text/template">