Skip to content

Commit b03ba19

Browse files
committed
Send error message if version of CrewLink is unsupported
1 parent adbb0df commit b03ba19

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/index.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import socketIO from 'socket.io';
77
import Tracer from 'tracer';
88
import morgan from 'morgan';
99

10+
const supportedCrewLinkVersions = new Set(['1.2.0']);
1011
const httpsEnabled = !!process.env.HTTPS;
1112

1213
const port = process.env.PORT || (httpsEnabled ? '443' : '9736');
@@ -64,6 +65,23 @@ app.get('/health', (req, res) => {
6465
});
6566
})
6667

68+
io.use((socket, next) => {
69+
const userAgent = socket.request.headers['user-agent'];
70+
const matches = /^CrewLink\/(\d+\.\d+\.\d+) \((\w+)\)$/.exec(userAgent);
71+
const error = new Error() as any;
72+
error.data = { message: 'The voice server does not support your version of CrewLink.\nSupported versions: ' + Array.from(supportedCrewLinkVersions).join() };
73+
if (!matches) {
74+
next(error);
75+
} else {
76+
const version = matches[1];
77+
// const platform = matches[2];
78+
if (supportedCrewLinkVersions.has(version)) {
79+
next();
80+
} else {
81+
next(error);
82+
}
83+
}
84+
});
6785

6886
io.on('connection', (socket: socketIO.Socket) => {
6987
connectionCount++;

0 commit comments

Comments
 (0)