You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
require"base64"require"./application"require"./webrtc/*"modulePlaceOS::ApiclassWebRTC < Applicationbase"/api/engine/v2/webrtc/"structCaptchaResponseincludeJSON::Serializablepropertysuccess : BoolendclassPlaceOS::Api::ErrorclassRecaptchaFailed < ErrorendclassGuestAccessDisabled < Errorendend# 401 if recaptcha fails
@[AC::Route::Exception(Error::RecaptchaFailed,status_code: HTTP::Status::UNAUTHORIZED)]defrecaptcha_failed(error) : CommonErrorLog.debug{error.message}CommonError.new(error,false)endJWT_SECRET=ENV["JWT_SECRET"]?.try{ |k| Base64.decode_string(k)}# this route provides a guest access to an anonymous chat room
@[AC::Route::POST("/guest_entry/:system_id",body: guest)]defguest_entry(guest : GuestParticipant,
@[AC::Param::Info(description: "either a system id or a unique permalink",example: "sys-12345")]system_id : String) : Niljwt_secret=JWT_SECRETraiseError::GuestAccessDisabled.new("guest access not enabled")unlessjwt_secret# TODO:: ensure the system is valid and exists# the system id that defines the name and rules for a collection of chats# note, this is not a chat, it represents a collection of chats# captcha, name, phone, type, chat_to_user_id, room_id, guest_chat_id (user_id), session_idauthority=current_authority.not_nil!ifrecaptcha_secret=authority.internals["recaptcha_secret"]?.try(&.as_s)HTTP::Client.new("www.google.com",tls: true)do |client|
client.connect_timeout=2begincaptresp=client.post("/recaptcha/api/siteverify?secret=#{recaptcha_secret}&response=#{guest.captcha}")ifcaptresp.success?result=CaptchaResponse.from_json(captresp.body)raiseError::RecaptchaFailed.new("recaptcha rejected")unlessresult.successelseraiseError::RecaptchaFailed.new("error verifying recaptcha response")endrescueerror# We don't want chat to be out of action if google is down, so we'll continueLog.error(exception: error){"recaptcha failed"}endendelseraiseError::RecaptchaFailed.new("recaptcha not configured")endpayload={iss: "POS",iat: 1.minute.ago.to_unix,exp: 12.hours.from_now.to_unix,jti: UUID.random.to_s,aud: authority.domain,scope: ["guest"],sub: guest.user_id,u: {n: guest.name,e: guest.email || "#{guest.phone}@phone" || "#{guest.name}@unknown",p: 0,r: [guest.user_id,system_id],},}jwt=JWT.encode(payload,jwt_secret,JWT::Algorithm::RS256)cookies["api-key"]=jwt
::PlaceOS::Driver::RedisStorage.with_redis &.publish("placeos/#{authority.domain}/guest/entry",{system_id=>guest,}.to_json)end
@[AC::Route::POST("/transfer/:user_id/?:session_id",body: body,status: {Nil=>HTTP::Status::OK,Bool=>HTTP::Status::PRECONDITION_REQUIRED,})]deftransfer_guest(user_id : String,session_id : String? =nil,body : JSON::Any?=nil) : Nil | Boolresult=MANAGER.transfer(user_id,session_id,body.try &.to_json)caseresultin.signal_sent?
nilin.no_session?
truein.no_connection?
falseendendstructRoomDetailsincludeJSON::Serializablegettersystem : Model::ControlSystemgettermetadata : Hash(String,PlaceOS::Model::Metadata::Interface)definitialize(@system,@metadata)endend# * create a permalink entry for systems# * system public flag for grabbing metadata# *# this route provides a guest access to an anonymous chat room
@[AC::Route::GET("/system/:system_id")]defpublic_room(
@[AC::Param::Info(description: "either a system id or a unique permalink",example: "sys-12345")]system_id : String) : RoomDetails# TODO:: check the system is publicsystem=Model::ControlSystem.find!(system_id,runopts: {"read_mode"=>"majority"})meta=Model::Metadata.build_metadata(system_id,nil)RoomDetails.new(system,meta)endICE_CONFIG={}ofString=> StringMANAGER=ChatManager.new(ICE_CONFIG)# WebRTC signaller endpoint, managing call participants
@[AC::Route::WebSocket("/signaller")]defsignaller(websocket) : NilLog.trace{{request_id: request_id,frame: "OPEN"}}authority=current_authority.not_nil!auth_id=authority.id.as(String)# https://developer.mozilla.org/en-US/docs/Web/API/RTCIceServerICE_CONFIG[auth_id]=authority.internals["webrtc_ice"]?.try(&.to_json) || WEBRTC_DEFAULT_ICE_CONFIGMANAGER.handle_session(websocket,request_id,user_token.id,auth_id)endendend
The text was updated successfully, but these errors were encountered:
the system id that defines the name and rules for a collection of chats
note, this is not a chat, it represents a collection of chats
system public flag for grabbing metadata
this route provides a guest access to an anonymous chat room
rest-api/src/placeos-rest-api/controllers/webrtc.cr
Line 42 in 36838fb
The text was updated successfully, but these errors were encountered: