Skip to content

Commit cbd94da

Browse files
Merge branch 'feat/use-mutecore-id-as-principal-id' into 'master'
feat: use mutecoreid as principal id See merge request coast-team/mute/mute-modules/mute-core!1
2 parents 968e776 + e534c12 commit cbd94da

File tree

9 files changed

+2382
-2006
lines changed

9 files changed

+2382
-2006
lines changed

package-lock.json

Lines changed: 2193 additions & 1881 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@coast-team/mute-core",
33
"description": "Core component of MUTE collaborative editor",
4-
"version": "10.0.0-2.2",
4+
"version": "11.0.0",
55
"main": "./dist/mute-core.node.es5.cjs.js",
66
"module": "./dist/mutecore.node.es5.esm.js",
77
"browser": "./dist/mute-core.browser.es5.esm.js",
@@ -26,7 +26,8 @@
2626
"contributors": [
2727
"Philippe Kalitine <[email protected]> (https://philippe.kalitine.name/)",
2828
"Quentin Tardivon",
29-
"Cedric Enclos"
29+
"Cedric Enclos",
30+
"Baptiste Hubert"
3031
],
3132
"license": "GPL-3.0",
3233
"publishConfig": {

src/collaborators/CollaboratorsService.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ export class CollaboratorsService extends Service<proto.ICollaborator, proto.Col
2525
this.joinSubject = new Subject()
2626
this.leaveSubject = new Subject()
2727

28-
this.newSub = this.messageIn$.subscribe(({ senderId, msg }) => {
29-
const updated = { id: senderId, ...msg }
30-
const collab = this.collaborators.get(senderId)
28+
this.newSub = this.messageIn$.subscribe(({ senderNetworkId, msg }) => {
29+
const updated = { ...msg }
30+
const collab = this.collaborators.get(senderNetworkId)
31+
3132
if (collab) {
3233
collab.muteCoreId = updated.muteCoreId || collab.muteCoreId
3334
collab.displayName = updated.displayName || collab.displayName
@@ -37,7 +38,7 @@ export class CollaboratorsService extends Service<proto.ICollaborator, proto.Col
3738
collab.deviceID = updated.deviceID || collab.deviceID
3839
this.updateSubject.next(collab)
3940
} else {
40-
this.collaborators.set(updated.id, updated)
41+
this.collaborators.set(senderNetworkId, updated)
4142
this.joinSubject.next(updated)
4243
}
4344
})
@@ -65,18 +66,18 @@ export class CollaboratorsService extends Service<proto.ICollaborator, proto.Col
6566
}
6667

6768
set memberJoin$(source: Observable<number>) {
68-
this.newSub = source.subscribe((id: number) =>
69-
this.emitUpdate(StreamsSubtype.COLLABORATORS_JOIN, id)
69+
this.newSub = source.subscribe((networkId: number) =>
70+
this.emitUpdate(StreamsSubtype.COLLABORATORS_JOIN, networkId)
7071
)
7172
}
7273

7374
set memberLeave$(source: Observable<number>) {
74-
this.newSub = source.subscribe((id: number) => {
75-
const collab = this.collaborators.get(id)
75+
this.newSub = source.subscribe((networkId: number) => {
76+
const collab = this.collaborators.get(networkId)
7677
if (collab) {
7778
this.leaveSubject.next(collab)
7879
}
79-
this.collaborators.delete(id)
80+
this.collaborators.delete(networkId)
8081
})
8182
}
8283

@@ -94,8 +95,8 @@ export class CollaboratorsService extends Service<proto.ICollaborator, proto.Col
9495
super.dispose()
9596
}
9697

97-
private emitUpdate(subtype: StreamsSubtype, recipientId?: number) {
98-
const { id, ...rest } = this.me
99-
super.send(rest, subtype, recipientId)
98+
private emitUpdate(subtype: StreamsSubtype, recipientNetworkId?: number) {
99+
const { ...rest } = this.me
100+
super.send(rest, subtype, recipientNetworkId)
100101
}
101102
}

src/collaborators/ICollaborator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export interface ICollaborator {
2-
id: number
32
muteCoreId?: number
43
displayName?: string
54
login?: string

src/core/SyncMessage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ export abstract class SyncMessage<Op> extends Service<proto.ISyncMsg, proto.Sync
2222
this.remoteReplySyncSubject = new Subject()
2323

2424
// FIXME: should I save the subscription for later unsubscribe/subscribe?
25-
this.newSub = this.messageIn$.subscribe(({ senderId, msg }) => {
25+
this.newSub = this.messageIn$.subscribe(({ senderNetworkId, msg }) => {
2626
switch (msg.type) {
2727
case 'richOpMsg':
2828
this.handleRichOpMsg(msg.richOpMsg as proto.RichOperationMsg)
2929
break
3030
case 'querySync':
31-
this.remoteQuerySyncIdSubject.next(senderId) // Register the id of the peer
31+
this.remoteQuerySyncIdSubject.next(senderNetworkId) // Register the id of the peer
3232
this.handleQuerySyncMsg(msg.querySync as proto.QuerySyncMsg)
3333
break
3434
case 'replySync':

src/misc/IMessage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ interface IMessage {
66
}
77

88
export interface IMessageIn extends IMessage {
9-
senderId: number
9+
senderNetworkId: number
1010
}
1111

1212
export interface IMessageOut extends IMessage {
13-
recipientId?: number // O value means send to a random peer
13+
recipientNetworkId?: number // O value means send to a random peer
1414
}

src/misc/Service.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface IMessageFactory<OutMsg, InMsg extends OutMsg> {
1212
}
1313

1414
export abstract class Service<OutMsg, InMsg extends OutMsg> extends Disposable {
15-
protected messageIn$: Observable<{ senderId: number; msg: InMsg }>
15+
protected messageIn$: Observable<{ senderNetworkId: number; msg: InMsg }>
1616

1717
private messageOut$: Subject<IMessageOut>
1818
private streamId: Streams
@@ -31,16 +31,16 @@ export abstract class Service<OutMsg, InMsg extends OutMsg> extends Disposable {
3131
this.proto = proto
3232
this.messageIn$ = messageIn.pipe(
3333
filter(({ streamId }) => streamId.type === myStreamId),
34-
map(({ senderId, content }) => ({ senderId, msg: proto.decode(content) }))
34+
map(({ senderNetworkId, content }) => ({ senderNetworkId, msg: proto.decode(content) }))
3535
)
3636
this.messageOut$ = messageOut
3737
this.streamId = myStreamId
3838
}
3939

40-
protected send(msg: OutMsg, subtype: StreamsSubtype, recipientId?: number) {
40+
protected send(msg: OutMsg, subtype: StreamsSubtype, recipientNetworkId?: number) {
4141
this.messageOut$.next({
4242
streamId: { type: this.streamId, subtype },
43-
recipientId,
43+
recipientNetworkId,
4444
content: this.proto.encode(this.proto.create(msg)).finish(),
4545
})
4646
}

src/proto/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ export namespace sync {
691691
public lowerPos?: (sync.ISimpleDotPos|null);
692692

693693
/** DottedLogootSBlockMsg content. */
694-
public content: string;
694+
public content?: (string|null);
695695

696696
/** DottedLogootSBlockMsg concatLength. */
697697
public concatLength?: (sync.IConcatLength|null);

0 commit comments

Comments
 (0)