Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
cmd committed Mar 4, 2024
1 parent fd1ba01 commit 284cc8b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
21 changes: 21 additions & 0 deletions demo/draft/alice/leave.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { DraftSession } from '@scrow/core'
import { signer } from './config.js'
import { secret_id } from '../terms.js'

const session = new DraftSession(secret_id, signer, {
debug : false,
verbose : false
})

session.on('ready', () => {
console.log('session:', session.data)
if (session.is_member) {
session.leave()
}
})

session.on('leave', (data) => {
console.log('left:', data)
})

await session.connect('wss://relay.damus.io')
15 changes: 6 additions & 9 deletions src/client/class/draft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
} from '@/lib/policy.js'

import {
get_object_id,
is_hash,
now
} from '@/lib/util.js'
Expand Down Expand Up @@ -372,8 +371,8 @@ export class DraftSession extends EventEmitter <{
this.emit('leave', mship)
}

_leave_handler (msg : EventMessage<MemberData>) {
const mship = msg.body
_leave_handler (msg : EventMessage) {
const mship = JSON.parse(msg.body)
const cat = msg.envelope.created_at
this._leave(mship, cat)
this.log.info('member left :', mship.pub)
Expand Down Expand Up @@ -534,13 +533,11 @@ export class DraftSession extends EventEmitter <{
const members = this.data.members
const signer = this.signer
if (has_membership(members, signer._signer)) {
const cred = signer.credential.claim(members)
const mship = cred.data
const commit_id = get_object_id(mship).hex
const receipt = this.when_commit(commit_id)
this.log.info('send commit :', commit_id)
const cred = signer.credential.claim(members)
const mship = cred.data
this._leave(mship)
this._room.send('leave', JSON.stringify(mship))
return receipt
this.log.info('send leave :', mship.pub)
}
return
}
Expand Down

0 comments on commit 284cc8b

Please sign in to comment.