Skip to content

Commit

Permalink
websocket deplyment
Browse files Browse the repository at this point in the history
  • Loading branch information
zainhoda committed Mar 22, 2023
1 parent e5cd5ff commit 68bfedc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions sample-apps/websockets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ def to_html(self):
return """
<div id="log"></div>
<script>
var httpProtocol = 'http://';
var wsProtocol = 'ws://';
if (window.location.protocol === 'https:') {
httpProtocol = 'http://';
wsProtocol = 'wss://';
}
const log = (text, color) => {
document.getElementById('log').innerHTML += `<span style="color: ${color}">${text}</span><br>`;
};
const socket = new WebSocket('ws://' + location.host + '""" + self.path_to_websocket + """');
const socket = new WebSocket(wsProtocol + location.host + '""" + self.path_to_websocket + """');
socket.addEventListener('message', ev => {
document.getElementById('log').innerHTML += ev.data;
});
Expand Down Expand Up @@ -49,7 +56,7 @@ def to_html(self):

@app.route('/')
def index():
page = pv.Page('Websocket Test')
page = pv.Page('Websocket Test', description='WebSocket proof of concept using Flask-Sock and PyVibe')

page.add_header("Websocket Test")

Expand All @@ -62,7 +69,8 @@ def index():
card.add_header('Receive')
card.add_component(WebSocketReceiverComponent('/echo'))

page.add_emgithub("https://github.com/pycob/pyvibe/blob/weboscket/sample-apps/websockets/main.py")
page.add_header("Source Code")
page.add_emgithub("https://github.com/pycob/pyvibe/blob/main/sample-apps/websockets/main.py")

return page.to_html()

Expand Down
1 change: 1 addition & 0 deletions sample-apps/websockets/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pyvibe
pycob
flask
flask-sock
gunicorn

0 comments on commit 68bfedc

Please sign in to comment.