Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CollabSpace Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mona Schulz
CollabSpace Backend
Commits
e5cbc3f7
Commit
e5cbc3f7
authored
1 year ago
by
Marius Friess
Browse files
Options
Downloads
Plain Diff
merge main into feat/hand-signal
parents
c6016588
bdbb1aac
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/channel/channel.ts
+46
-22
46 additions, 22 deletions
src/channel/channel.ts
with
46 additions
and
22 deletions
src/channel/channel.ts
+
46
−
22
View file @
e5cbc3f7
import
*
as
crypto
from
'
crypto
'
;
import
{
Server
,
Socket
}
from
'
socket.io
'
;
import
{
User
}
from
'
../user/user.entity
'
;
import
{
Room
}
from
'
../room/room.entity
'
;
...
...
@@ -20,22 +19,32 @@ export interface Student extends ChannelUser {
}
export
class
Channel
{
public
readonly
id
:
string
;
public
teacher
?:
Teacher
;
p
ublic
readonly
students
:
Student
[]
=
[]
;
p
rivate
closeTimeout
:
NodeJS
.
Timeout
;
constructor
(
public
readonly
room
:
Room
,
public
readonly
server
:
Server
)
{
// TODO: change id to be a 6 digit random number instead of a UUID to make it easier to type
this
.
id
=
crypto
.
randomUUID
();
}
public
students
:
Map
<
string
,
Student
>
=
new
Map
();
constructor
(
public
readonly
room
:
Room
,
public
readonly
server
:
Server
,
public
readonly
id
:
string
,
)
{}
public
async
joinAsStudent
(
client
:
Socket
,
name
:
string
)
{
await
client
.
join
(
this
.
id
);
this
.
students
.
push
({
name
,
client
,
video
:
true
,
audio
:
true
,
handSignal
:
false
});
const
student
=
{
name
,
client
,
video
:
true
,
audio
:
true
,
handSignal
:
false
,
};
this
.
students
.
set
(
client
.
id
,
student
);
client
.
broadcast
.
to
(
this
.
id
).
emit
(
'
student-joined
'
,
{
id
:
client
.
id
,
name
,
name
:
student
.
name
,
video
:
true
,
audio
:
true
,
handSignal
:
false
,
...
...
@@ -66,20 +75,19 @@ export class Channel {
}
public
async
leaveAsStudent
(
client
:
Socket
)
{
await
client
.
leave
(
this
.
id
);
const
index
=
this
.
students
.
findIndex
((
s
)
=>
s
.
client
.
id
===
client
.
id
);
const
student
=
this
.
students
.
get
(
client
.
id
);
if
(
index
<
0
)
{
return
;
}
this
.
students
.
splice
(
index
,
1
);
if
(
student
)
{
delete
student
.
client
;
this
.
students
.
delete
(
client
.
id
);
client
.
broadcast
.
to
(
this
.
id
).
emit
(
'
student-left
'
,
client
.
id
);
await
client
.
leave
(
this
.
id
);
client
.
broadcast
.
to
(
this
.
id
).
emit
(
'
student-left
'
,
client
.
id
);
}
}
public
isEmpty
():
boolean
{
return
!
this
.
teacher
&&
this
.
students
.
length
===
0
;
return
!
this
.
teacher
&&
this
.
students
.
size
===
0
;
}
public
close
()
{
...
...
@@ -91,7 +99,7 @@ export class Channel {
return
this
.
teacher
;
}
const
student
=
this
.
students
.
find
((
s
)
=>
s
.
client
.
id
===
clientId
);
const
student
=
this
.
students
.
get
(
clientId
);
if
(
student
)
{
return
student
;
...
...
@@ -101,8 +109,7 @@ export class Channel {
}
public
getStudent
(
clientId
:
string
):
Student
{
const
student
=
this
.
students
.
find
((
s
)
=>
s
.
client
.
id
===
clientId
);
const
student
=
this
.
students
.
get
(
clientId
);
if
(
student
)
{
return
student
;
...
...
@@ -112,7 +119,7 @@ export class Channel {
}
public
changeName
(
client
:
Socket
,
name
:
string
)
{
const
student
=
this
.
students
.
find
((
s
)
=>
s
.
client
.
id
===
client
.
id
);
const
student
=
this
.
students
.
get
(
client
.
id
);
if
(
student
)
{
student
.
name
=
name
;
...
...
@@ -139,4 +146,21 @@ export class Channel {
public
toString
():
string
{
return
`Channel{
${
this
.
id
}
}`
;
}
public
clearCloseTimeout
()
{
if
(
this
.
closeTimeout
)
{
clearTimeout
(
this
.
closeTimeout
);
this
.
closeTimeout
=
undefined
;
}
}
public
setCloseTimeout
(
onTimeout
:
()
=>
void
)
{
this
.
clearCloseTimeout
();
this
.
closeTimeout
=
setTimeout
(()
=>
{
if
(
this
.
isEmpty
())
{
this
.
close
();
onTimeout
();
}
},
1000
*
60
*
10
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment