Skip to content

Commit

Permalink
Merge pull request #1 from palantirnet/azure-webpubsub-integration
Browse files Browse the repository at this point in the history
Azure webpubsub integration
  • Loading branch information
byrond authored Nov 16, 2023
2 parents 8be2fc4 + ca12e7d commit 9d3ae7a
Show file tree
Hide file tree
Showing 4 changed files with 522 additions and 3,384 deletions.
8 changes: 4 additions & 4 deletions bin/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import ws from 'ws'
import { WebSocketServer } from 'ws'
import http from 'http'
import * as map from 'lib0/map'

Expand All @@ -12,8 +12,7 @@ const wsReadyStateClosed = 3 // eslint-disable-line
const pingTimeout = 30000

const port = process.env.PORT || 4444
// @ts-ignore
const wss = new ws.Server({ noServer: true })
const wss = new WebSocketServer({ noServer: true })

const server = http.createServer((request, response) => {
response.writeHead(200, { 'Content-Type': 'text/plain' })
Expand Down Expand Up @@ -81,7 +80,7 @@ const onconnection = conn => {
closed = true
})
conn.on('message', /** @param {object} message */ message => {
if (typeof message === 'string') {
if (typeof message === 'string' || message instanceof Buffer) {
message = JSON.parse(message)
}
if (message && message.type && !closed) {
Expand Down Expand Up @@ -109,6 +108,7 @@ const onconnection = conn => {
if (message.topic) {
const receivers = topics.get(message.topic)
if (receivers) {
message.clients = receivers.size
receivers.forEach(receiver =>
send(receiver, message)
)
Expand Down
Loading

0 comments on commit 9d3ae7a

Please sign in to comment.