Skip to content

Commit

Permalink
Merge pull request #861 from Roguelike-Celebration/orbPonder
Browse files Browse the repository at this point in the history
Try to set up orb pondering endpoint
  • Loading branch information
lazerwalker authored Sep 22, 2024
2 parents 2cf6f69 + ff217f9 commit 12a02da
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
server/firebase-admin.json
server/firebase-admin.*.json
node_modules
dist
.env
Expand Down
24 changes: 17 additions & 7 deletions server/src/endpoints/sendChatMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,25 @@ const sendChatMessage: AuthenticatedEndpointFunction = async (user: User, inputs
}

log(`Sending to ${user.roomId}: ${message} from ${user.id}`)
const messages = [
{
groupId: user.roomId,
target: 'chatMessage',
arguments: [inputs.id, user.id, message]
}
]

if (user.roomId === 'theater' && message.startsWith('!')) {
console.log('Sending ! message to orb ponderer')
messages.push({
groupId: 'orbMessages',
target: 'chatMessage',
arguments: [inputs.id, user.id, message]
})
}

return {
messages: [
{
groupId: user.roomId,
target: 'chatMessage',
arguments: [inputs.id, user.id, message]
}
],
messages,
httpResponse: { status: 200 }
}
}
Expand Down
32 changes: 32 additions & 0 deletions server/startPonderingOrbs/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "webPubSubConnection",
"name": "connection",
"hub": "chat",
"userId": "{headers.userid}",
"direction": "in"
},
{
"type": "webPubSub",
"name": "actions",
"hub": "chat",
"direction": "out"
}
],
"scriptFile": "../dist/startPonderingOrbs/index.js"
}
23 changes: 23 additions & 0 deletions server/startPonderingOrbs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { AzureFunction, Context, HttpRequest } from '@azure/functions'

const httpTrigger: AzureFunction = async function (context: Context, req: HttpRequest, connection): Promise<void> {
if (req.headers.userId !== process.env.ORB_PONDER_USER) {
context.res = {
status: 401,
body: 'Unauthorized'
}
return
}

// This never gets undone, but the fact this group always exists is ~fine~
context.bindings.actions.push({
actionName: 'addUserToGroup',
userId: req.headers.userId,
group: 'orbMessages'
})

context.res = { body: connection }
context.done()
}

export default httpTrigger
3 changes: 3 additions & 0 deletions server/startPonderingOrbs/sample.dat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "Azure"
}

0 comments on commit 12a02da

Please sign in to comment.