Skip to content

Commit b8838e5

Browse files
committed
Merge branch 'release-0.23'
2 parents eb00827 + acd13f7 commit b8838e5

File tree

5 files changed

+99
-49
lines changed

5 files changed

+99
-49
lines changed

debian/changelog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
spreed-webrtc-server (0.23.8) precise; urgency=low
2+
3+
* Session subscriptions now notify close both ways.
4+
* Reenable chat rooms on certain conditions related to peer connectivity.
5+
* Fixed an issue where replaced sessions cannot receive data from contacts in other rooms.
6+
7+
-- Simon Eisenmann <[email protected]> Wed, 08 Apr 2015 17:24:59 +0200
8+
19
spreed-webrtc-server (0.23.7) precise; urgency=low
210

311
* Updated SCSS to match coding style.

src/app/spreed-webrtc-server/client.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Client interface {
4343
Session() *Session
4444
Index() uint64
4545
Close()
46-
ReplaceAndClose()
46+
ReplaceAndClose(Client)
4747
}
4848

4949
type client struct {
@@ -87,9 +87,15 @@ func (client *client) Session() *Session {
8787
return client.session
8888
}
8989

90-
func (client *client) ReplaceAndClose() {
91-
client.session.Close()
92-
if client.Connection != nil {
93-
client.Connection.Close()
94-
}
90+
func (client *client) ReplaceAndClose(oldClient Client) {
91+
oldSession := oldClient.Session()
92+
client.session.Replace(oldSession)
93+
go func() {
94+
// Close old session and client in another go routine,
95+
// to avoid blocking the new client if the old one hangs or
96+
// whatever.
97+
log.Printf("Closing obsolete client %d (replaced with %d) with id %s\n", oldClient.Index(), client.Index(), oldSession.Id)
98+
oldSession.Close()
99+
oldClient.Close()
100+
}()
95101
}

src/app/spreed-webrtc-server/hub.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,8 @@ func (h *hub) OnConnect(client Client, session *Session) {
154154
log.Printf("Created client %d with id %s\n", client.Index(), session.Id)
155155
// Register connection or replace existing one.
156156
if ec, ok := h.clients[session.Id]; ok {
157-
// Clean up old client at the end and make sure to run this in another go routine,
158-
// to avoid blocking the new client if the old one hangs or whatever.
159-
go func() {
160-
log.Printf("Closing obsolete client %d (replaced with %d) with id %s\n", ec.Index(), client.Index(), session.Id)
161-
ec.ReplaceAndClose()
162-
}()
157+
// Clean up old client at the end outside the hub lock.
158+
defer client.ReplaceAndClose(ec)
163159
}
164160
h.clients[session.Id] = client
165161
h.mutex.Unlock()

src/app/spreed-webrtc-server/session.go

Lines changed: 51 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type Session struct {
5656
subscriptions map[string]*Session
5757
subscribers map[string]*Session
5858
disconnected bool
59+
replaced bool
5960
}
6061

6162
func NewSession(manager SessionManager, unicaster Unicaster, broadcaster Broadcaster, rooms RoomStatusManager, buddyImages ImageCache, attestations *securecookie.SecureCookie, id, sid string) *Session {
@@ -85,16 +86,13 @@ func (s *Session) authenticated() (authenticated bool) {
8586
}
8687

8788
func (s *Session) Subscribe(session *Session) {
88-
8989
s.mutex.Lock()
9090
s.subscriptions[session.Id] = session
9191
s.mutex.Unlock()
9292
session.AddSubscriber(s)
93-
9493
}
9594

9695
func (s *Session) Unsubscribe(id string) {
97-
9896
s.mutex.Lock()
9997
if session, ok := s.subscriptions[id]; ok {
10098
delete(s.subscriptions, id)
@@ -103,7 +101,6 @@ func (s *Session) Unsubscribe(id string) {
103101
} else {
104102
s.mutex.Unlock()
105103
}
106-
107104
}
108105

109106
func (s *Session) AddSubscriber(session *Session) {
@@ -209,33 +206,39 @@ func (s *Session) Close() {
209206
return
210207
}
211208

212-
outgoing := &DataOutgoing{
213-
From: s.Id,
214-
A: s.attestation.Token(),
215-
Data: &DataSession{
216-
Type: "Left",
217-
Id: s.Id,
218-
Status: "hard",
219-
},
220-
}
209+
// TODO(longsleep): Verify that it is ok to not do all this when replaced is true.
210+
if !s.replaced {
221211

222-
if s.Hello {
223-
// NOTE(lcooper): If we don't check for Hello here, we could deadlock
224-
// when implicitly creating a room while a user is reconnecting.
225-
s.Broadcaster.Broadcast(s.Id, s.Roomid, outgoing)
226-
s.RoomStatusManager.LeaveRoom(s.Roomid, s.Id)
227-
}
212+
outgoing := &DataOutgoing{
213+
From: s.Id,
214+
A: s.attestation.Token(),
215+
Data: &DataSession{
216+
Type: "Left",
217+
Id: s.Id,
218+
Status: "hard",
219+
},
220+
}
228221

229-
for _, session := range s.subscribers {
230-
s.Unicaster.Unicast(session.Id, outgoing)
231-
}
222+
if s.Hello {
223+
// NOTE(lcooper): If we don't check for Hello here, we could deadlock
224+
// when implicitly creating a room while a user is reconnecting.
225+
s.Broadcaster.Broadcast(s.Id, s.Roomid, outgoing)
226+
s.RoomStatusManager.LeaveRoom(s.Roomid, s.Id)
227+
}
232228

233-
for _, session := range s.subscriptions {
234-
session.RemoveSubscriber(s.Id)
235-
}
229+
for _, session := range s.subscribers {
230+
s.Unicaster.Unicast(session.Id, outgoing)
231+
}
232+
233+
for _, session := range s.subscriptions {
234+
session.RemoveSubscriber(s.Id)
235+
s.Unicaster.Unicast(session.Id, outgoing)
236+
}
236237

237-
s.SessionManager.DestroySession(s.Id, s.userid)
238-
s.buddyImages.Delete(s.Id)
238+
s.SessionManager.DestroySession(s.Id, s.userid)
239+
s.buddyImages.Delete(s.Id)
240+
241+
}
239242

240243
s.subscriptions = make(map[string]*Session)
241244
s.subscribers = make(map[string]*Session)
@@ -244,6 +247,27 @@ func (s *Session) Close() {
244247
s.mutex.Unlock()
245248
}
246249

250+
func (s *Session) Replace(oldSession *Session) {
251+
252+
oldSession.mutex.Lock()
253+
if oldSession.disconnected {
254+
oldSession.mutex.Unlock()
255+
return
256+
}
257+
258+
s.mutex.Lock()
259+
260+
s.subscriptions = oldSession.subscriptions
261+
s.subscribers = oldSession.subscribers
262+
263+
s.mutex.Unlock()
264+
265+
// Mark old session as replaced.
266+
oldSession.replaced = true
267+
oldSession.mutex.Unlock()
268+
269+
}
270+
247271
func (s *Session) Update(update *SessionUpdate) uint64 {
248272
s.mutex.Lock()
249273
defer s.mutex.Unlock()

static/js/directives/chat.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
7878
if (!with_message) {
7979
return;
8080
}
81-
// No room with this id, get one with the from id
81+
// No room with this id, get one with the from id.
8282
$scope.$emit("startchat", from, {
8383
restore: with_message
8484
});
@@ -90,14 +90,19 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
9090
room.peerIsTyping = "no";
9191
room.p2p( !! p2p);
9292
if (room.firstmessage) {
93+
// Auto show when this is the first message.
9394
$scope.showRoom(room.id, null, {
9495
restore: with_message
9596
});
9697
}
98+
if (!room.enabled) {
99+
// Reenable chat room when receiving messages again.
100+
room.enabled = true;
101+
}
97102
}
98103

99-
room.$broadcast("received", from, data);
100104
safeApply(room);
105+
room.$broadcast("received", from, data);
101106

102107
});
103108

@@ -108,21 +113,13 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
108113
case "Left":
109114
if (data.Status !== "soft") {
110115
room.enabled = false;
111-
room.$broadcast("received", data.Id, {
112-
Type: "LeftOrJoined",
113-
"LeftOrJoined": "left"
114-
});
115116
safeApply(room);
116117
}
117118
break;
118119
case "Joined":
119120
if (!room.enabled) {
120121
room.enabled = true;
121122
_.delay(function() {
122-
room.$broadcast("received", data.Id, {
123-
Type: "LeftOrJoined",
124-
"LeftOrJoined": "joined"
125-
});
126123
safeApply(room);
127124
}, 1000);
128125
}
@@ -398,6 +395,22 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
398395
}
399396
}
400397
});
398+
subscope.$watch("enabled", function(enabled, old) {
399+
if (enabled === old) {
400+
return;
401+
}
402+
//console.log("enabled", enabled, old);
403+
var value;
404+
if (enabled) {
405+
value = "resumed";
406+
} else {
407+
value = "left";
408+
}
409+
subscope.$broadcast("received", subscope.id, {
410+
Type: "LeftOrJoined",
411+
"LeftOrJoined": value
412+
});
413+
});
401414
chat(subscope, function(clonedElement, $scope) {
402415

403416
pane.append(clonedElement);
@@ -445,6 +458,9 @@ define(['jquery', 'underscore', 'text!partials/chat.html', 'text!partials/chatro
445458
subscope.index = index;
446459
subscope.visible = true;
447460
}
461+
if (!subscope.enabled) {
462+
subscope.enabled = true;
463+
}
448464
}
449465
if (options.autofocus && subscope.visible) {
450466
subscope.$broadcast("focus");

0 commit comments

Comments
 (0)