Skip to content

Commit

Permalink
private/group chat with file
Browse files Browse the repository at this point in the history
  • Loading branch information
oxogenesis authored Mar 1, 2020
1 parent 00f94b7 commit bc34550
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
45 changes: 24 additions & 21 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,22 @@ function VerifyJsonSignature(json) {
}

let ActionCode = {
"ServerMessage": 0,

"Declare": 200,
"ObjectResponse": 201,

"BulletinRequest": 211,
"BulletinFileRequest": 212,

"ChatDH": 221,
"ChatMessage": 222,
"ChatSync": 223,

"GroupRequest": 231,
"GroupManageSync": 232,
"GroupDH": 233,
"GroupMessageSync": 234
"Declare": 100,
"ObjectResponse": 101,

"BulletinRequest": 201,
"BulletinFileRequest": 202,

"ChatDH": 301,
"ChatMessage": 302,
"ChatSync": 303,
"PrivateFileRequest": 304,

"GroupRequest": 401,
"GroupManageSync": 402,
"GroupDH": 403,
"GroupMessageSync": 404,
"GroupFileRequest": 405
}

//message
Expand All @@ -111,11 +111,14 @@ const MessageCode = {
}

const ObjectType = {
"Bulletin": 111,
"BulletinFile": 112,
"Bulletin": 101,
"BulletinFile": 102,

"PrivateFile": 201,

"GroupManage": 131,
"GroupMessage": 132
"GroupManage": 301,
"GroupMessage": 302,
"GroupFile": 303
}

function strServerMessage(msgCode) {
Expand Down Expand Up @@ -304,7 +307,7 @@ function startClientServer() {
ClientServer = new WebSocket.Server({
port: 3000, //to bind on 80, must use 'sudo node main.js'
clientTracking: true,
maxPayload: 102400
maxPayload: 150 * 1024
})

ClientServer.on('connection', function connection(ws) {
Expand Down
6 changes: 3 additions & 3 deletions schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ let BulletinRequestSchema = {
}
}

let BulletinFileRequestSchema = {
let FileRequestSchema = {
"type": "object",
"required": ["Action", "SHA1", "CurrentChunk", "To", "Timestamp", "PublicKey", "Signature"],
"maxProperties": 7,
Expand Down Expand Up @@ -343,7 +343,7 @@ var vDeclare = ajv.compile(DeclareSchema)
var vObjectResponseSchema = ajv.compile(ObjectResponseSchema)

var vBulletinRequestSchema = ajv.compile(BulletinRequestSchema)
var vBulletinFileRequestSchema = ajv.compile(BulletinFileRequestSchema)
var vFileRequestSchema = ajv.compile(FileRequestSchema)

var vChatMessageSchema = ajv.compile(ChatMessageSchema)
var vChatSyncSchema = ajv.compile(ChatSyncSchema)
Expand All @@ -358,7 +358,7 @@ function checkClientSchema(strJson) {
if (typeof strJson == "string") {
try {
let json = JSON.parse(strJson)
if (vObjectResponseSchema(json) || vBulletinRequestSchema(json) || vBulletinFileRequestSchema(json) || vChatMessageSchema(json) || vChatSyncSchema(json) || vChatDHSchema(json) || vDeclare(json) || vGroupRequestSchema(json) || vGroupManageSyncSchema(json) || vGroupDHSchema(json) || vGroupMessageSyncSchema(json)) {
if (vObjectResponseSchema(json) || vBulletinRequestSchema(json) || vFileRequestSchema(json) || vChatMessageSchema(json) || vChatSyncSchema(json) || vChatDHSchema(json) || vDeclare(json) || vGroupRequestSchema(json) || vGroupManageSyncSchema(json) || vGroupDHSchema(json) || vGroupMessageSyncSchema(json)) {
return json
} else {
return false
Expand Down

0 comments on commit bc34550

Please sign in to comment.