def rtmp_stage2_user_auth_check(channelLoc, ipaddress): sysSettings = settings.settings.query.first() currentTime = datetime.datetime.utcnow() requestedChannel = Channel.Channel.query.filter_by(channelLoc=channelLoc).first() if requestedChannel is not None: authedStream = Stream.Stream.query.filter_by(streamKey=requestedChannel.streamKey).first() if authedStream is not None: authedStream.currentViewers = int(xmpp.getChannelCounts(requestedChannel.channelLoc)) authedStream.totalViewers = int(xmpp.getChannelCounts(requestedChannel.channelLoc)) db.session.commit() if requestedChannel.imageLocation is None: channelImage = (sysSettings.siteProtocol + sysSettings.siteAddress + "/static/img/video-placeholder.jpg") else: channelImage = (sysSettings.siteProtocol + sysSettings.siteAddress + "/images/" + requestedChannel.imageLocation) webhookFunc.runWebhook(requestedChannel.id, 0, channelname=requestedChannel.channelName, channelurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/channel/" + str(requestedChannel.id)), channeltopic=requestedChannel.topic, channelimage=channelImage, streamer=templateFilters.get_userName(requestedChannel.owningUser), channeldescription=str(requestedChannel.description), streamname=authedStream.streamName, streamurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/view/" + requestedChannel.channelLoc), streamtopic=templateFilters.get_topicName(authedStream.topic), streamimage=(sysSettings.siteProtocol + sysSettings.siteAddress + "/stream-thumb/" + requestedChannel.channelLoc + ".png")) subscriptionQuery = subscriptions.channelSubs.query.filter_by(channelID=requestedChannel.id).all() for sub in subscriptionQuery: # Create Notification for Channel Subs newNotification = notifications.userNotification(templateFilters.get_userName(requestedChannel.owningUser) + " has started a live stream in " + requestedChannel.channelName, "/view/" + str(requestedChannel.channelLoc), "/images/" + str(requestedChannel.owner.pictureLocation), sub.userID) db.session.add(newNotification) db.session.commit() try: subsFunc.processSubscriptions(requestedChannel.id, sysSettings.siteName + " - " + requestedChannel.channelName + " has started a stream", "<html><body><img src='" + sysSettings.siteProtocol + sysSettings.siteAddress + sysSettings.systemLogo + "'><p>Channel " + requestedChannel.channelName + " has started a new video stream.</p><p>Click this link to watch<br><a href='" + sysSettings.siteProtocol + sysSettings.siteAddress + "/view/" + str(requestedChannel.channelLoc) + "'>" + requestedChannel.channelName + "</a></p>") except: system.newLog(0, "Subscriptions Failed due to possible misconfiguration") returnMessage = {'time': str(currentTime), 'request': 'Stage2', 'success': True, 'channelLoc': requestedChannel.channelLoc, 'ipAddress': str(ipaddress), 'message': 'Success - Stream Authenticated & Initialized'} db.session.close() return returnMessage else: returnMessage = {'time': str(currentTime), 'request': 'Stage2', 'success': False, 'channelLoc': requestedChannel.channelLoc, 'ipAddress': str(ipaddress), 'message': 'Failed - No Matching Stage 1 Connection'} db.session.close() return returnMessage else: returnMessage = {'time': str(currentTime), 'request': 'Stage2', 'success': False, 'channelLoc': channelLoc, 'ipAddress': str(ipaddress), 'message': 'Failed - Passed Stage 1 Channel ID Does Not Match Any Known Channels'} db.session.close() return returnMessage
def handle_new_viewer(streamData): channelLoc = str(streamData['data']) sysSettings = settings.settings.query.first() requestedChannel = Channel.Channel.query.filter_by(channelLoc=channelLoc).first() stream = Stream.Stream.query.filter_by(streamKey=requestedChannel.streamKey).first() currentViewers = xmpp.getChannelCounts(requestedChannel.channelLoc) streamName = "" streamTopic = 0 requestedChannel.currentViewers = currentViewers db.session.commit() if stream is not None: stream.currentViewers = currentViewers db.session.commit() streamName = stream.streamName streamTopic = stream.topic else: streamName = requestedChannel.channelName streamTopic = requestedChannel.topic if requestedChannel.imageLocation is None: channelImage = (sysSettings.siteProtocol + sysSettings.siteAddress + "/static/img/video-placeholder.jpg") else: channelImage = (sysSettings.siteProtocol + sysSettings.siteAddress + "/images/" + requestedChannel.imageLocation) join_room(streamData['data']) if current_user.is_authenticated: pictureLocation = current_user.pictureLocation if current_user.pictureLocation is None: pictureLocation = '/static/img/user2.png' else: pictureLocation = '/images/' + pictureLocation webhookFunc.runWebhook(requestedChannel.id, 2, channelname=requestedChannel.channelName, channelurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/channel/" + str(requestedChannel.id)), channeltopic=requestedChannel.topic, channelimage=channelImage, streamer=templateFilters.get_userName(requestedChannel.owningUser), channeldescription=str(requestedChannel.description), streamname=streamName, streamurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/view/" + requestedChannel.channelLoc), streamtopic=templateFilters.get_topicName(streamTopic), streamimage=(sysSettings.siteProtocol + sysSettings.siteAddress + "/stream-thumb/" + requestedChannel.channelLoc + ".png"), user=current_user.username, userpicture=(sysSettings.siteProtocol + sysSettings.siteAddress + str(pictureLocation))) else: webhookFunc.runWebhook(requestedChannel.id, 2, channelname=requestedChannel.channelName, channelurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/channel/" + str(requestedChannel.id)), channeltopic=requestedChannel.topic, channelimage=channelImage, streamer=templateFilters.get_userName(requestedChannel.owningUser), channeldescription=str(requestedChannel.description), streamname=streamName, streamurl=(sysSettings.siteProtocol + sysSettings.siteAddress + "/view/" + requestedChannel.channelLoc), streamtopic=templateFilters.get_topicName(streamTopic), streamimage=(sysSettings.siteProtocol + sysSettings.siteAddress + "/stream-thumb/" + requestedChannel.channelLoc + ".png"), user="******", userpicture=(sysSettings.siteProtocol + sysSettings.siteAddress + '/static/img/user2.png')) handle_viewer_total_request(streamData, room=streamData['data']) db.session.commit() db.session.close() return 'OK'
def handle_leaving_viewer(streamData): channelLoc = str(streamData['data']) sysSettings = settings.settings.query.first() requestedChannel = Channel.Channel.query.filter_by(channelLoc=channelLoc).first() stream = Stream.Stream.query.filter_by(streamKey=requestedChannel.streamKey).first() currentViewers = xmpp.getChannelCounts(requestedChannel.channelLoc) requestedChannel.currentViewers = currentViewers if requestedChannel.currentViewers < 0: requestedChannel.currentViewers = 0 db.session.commit() if stream is not None: stream.currentViewers = currentViewers if stream.currentViewers < 0: stream.currentViewers = 0 db.session.commit() leave_room(streamData['data']) handle_viewer_total_request(streamData, room=streamData['data']) db.session.commit() db.session.close() return 'OK'
def handle_viewer_total_request(streamData, room=None): channelLoc = str(streamData['data']) viewers = xmpp.getChannelCounts(channelLoc) channelQuery = Channel.Channel.query.filter_by( channelLoc=channelLoc).first() if channelQuery is not None: channelQuery.currentViewers = viewers for stream in channelQuery.stream: stream.currentViewers = viewers db.session.commit() db.session.commit() db.session.close() if room is None: emit('viewerTotalResponse', {'data': str(viewers)}) else: emit('viewerTotalResponse', {'data': str(viewers)}, room=room) return 'OK'
def handle_viewer_total_request(streamData, room=None): channelLoc = str(streamData['data']) viewers = xmpp.getChannelCounts(channelLoc) ChannelUpdateStatement = (update(Channel.Channel).where( Channel.Channel.channelLoc == channelLoc).values( channelViewers=viewers)) channelQuery = Channel.Channel.query.filter_by( channelLoc=channelLoc).with_entities(Channel.Channel.id).first() StreamUpdateStatement = (update(Stream.Stream).where( Stream.Stream.linkedChannel == channelQuery.id).values( currentViewers=viewers)) db.session.commit() db.session.close() if room is None: emit('viewerTotalResponse', {'data': str(viewers)}) else: emit('viewerTotalResponse', {'data': str(viewers)}, room=room) return 'OK'
def handle_leaving_viewer(streamData): channelLoc = str(streamData['data']) sysSettings = settings.settings.query.first() requestedChannel = Channel.Channel.query.filter_by( channelLoc=channelLoc).first() stream = Stream.Stream.query.filter_by( streamKey=requestedChannel.streamKey).first() #userSID = request.cookies.get('ospSession') #userSID = request.sid #streamSIDList = r.smembers(channelLoc + '-streamSIDList') #if streamSIDList is not None: # r.srem(channelLoc + '-streamSIDList', userSID) # currentViewers = len(streamSIDList) currentViewers = xmpp.getChannelCounts(requestedChannel.channelLoc) requestedChannel.currentViewers = currentViewers if requestedChannel.currentViewers < 0: requestedChannel.currentViewers = 0 db.session.commit() if stream is not None: stream.currentViewers = currentViewers if stream.currentViewers < 0: stream.currentViewers = 0 db.session.commit() leave_room(streamData['data']) handle_viewer_total_request(streamData, room=streamData['data']) db.session.commit() db.session.close() return 'OK'