Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Adding built protobuf stuff and related helpers etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcottontensor committed Jan 30, 2024
1 parent c74fec9 commit 6e35535
Show file tree
Hide file tree
Showing 7 changed files with 1,955 additions and 17 deletions.
143 changes: 128 additions & 15 deletions Common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
"types": "types/pixelstreamingcommon.d.ts",
"sideEffects": false,
"scripts": {
"build_proto": "npx protoc --ts_out src/Messages --proto_path protobuf protobuf/signalling_messages.proto",
"compile": "tsc --build --clean && tsc",
"build": "tsc --build --clean && tsc",
"build-all": "npm run build_proto && npm run build",
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
Expand All @@ -30,5 +32,8 @@
"license": "MIT",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@protobuf-ts/plugin": "^2.9.3"
}
}
3 changes: 3 additions & 0 deletions Common/src/Messages/base_message.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface BaseMessage {
type: string;
}
11 changes: 11 additions & 0 deletions Common/src/Messages/message_helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IMessageType } from "@protobuf-ts/runtime";
import { BaseMessage } from './base_message';

export function createMessage(messageType: IMessageType<BaseMessage>, params?: any) {
const message = messageType.create();
message.type = messageType.typeName;
if (params) {
messageType.mergePartial(message, params);
}
return message;
}
28 changes: 28 additions & 0 deletions Common/src/Messages/message_registry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { IMessageType } from "@protobuf-ts/runtime";
import * as Messages from './signalling_messages';
import { BaseMessage } from './base_message';

export const MessageRegistry: Record<string, IMessageType<BaseMessage>> = {
'answer': Messages.answer,
'config': Messages.config,
'dataChannelRequest': Messages.dataChannelRequest,
'disconnectPlayer': Messages.disconnectPlayer,
'endpointId': Messages.endpointId,
'iceCandidate': Messages.iceCandidate,
'identify': Messages.identify,
'layerPreference': Messages.layerPreference,
'listStreamers': Messages.listStreamers,
'offer': Messages.offer,
'peerDataChannelsReady': Messages.peerDataChannelsReady,
'ping': Messages.ping,
'playerConnected': Messages.playerConnected,
'playerCount': Messages.playerCount,
'playerDisconnected': Messages.playerDisconnected,
'pong': Messages.pong,
'stats': Messages.stats,
'streamerDataChannels': Messages.streamerDataChannels,
'streamerDisconnected': Messages.streamerDisconnected,
'streamerList': Messages.streamerList,
'subscribe': Messages.subscribe,
'unsubscribe': Messages.unsubscribe,
}
Loading

0 comments on commit 6e35535

Please sign in to comment.