Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure webpubsub integration #1

Merged
merged 17 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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