Skip to content

Commit

Permalink
feat(live): set initial instances
Browse files Browse the repository at this point in the history
  • Loading branch information
Novout committed May 12, 2022
1 parent 55f1708 commit 4ce25e8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
/>
<p>{{ t('editor.live.enter.description') }}</p>
<InputText
ref="target"
v-model="input"
class="w-full bg-theme-background-opacity-1 py-0.5 px-3"
@keypress.enter="onEnter"
Expand All @@ -26,13 +27,16 @@
import { usePlugin } from 'better-write-plugin-core'
import { ref } from 'vue'
import { useI18n } from 'vue-i18n'
import { useStorage } from '@/use/storage/storage'
const ABSOLUTE = useAbsoluteStore()
const { t } = useI18n()
const plugin = usePlugin()
const storage = useStorage()
const base = ref<HTMLElement | null>(null)
const target = ref<HTMLInputElement | null>(null)
const input = ref<string>('')
const { style } = useDraggable(base as any, {
Expand All @@ -47,10 +51,12 @@
ABSOLUTE.live.enter = false
}
const onEnter = (e) => {
const onEnter = async (e) => {
e.preventDefault()
e.stopPropagation()
await storage.normalize()
plugin.emit('plugin-multiplayer-enter', input.value)
input.value = ''
Expand Down
15 changes: 12 additions & 3 deletions packages/better-write-plugin-multiplayer/src/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export const PluginMultiplayerSet = (
stores.AUTH.account.multiplayer.client = client

const setContext = async (room: Room) => {
room.subscribe('others', (others) => {})
room.subscribe('others', (others) => {
console.log(others.toArray())
})
}

On.multiplayer().PluginMultiplayerCreate(emitter, [
Expand All @@ -27,7 +29,12 @@ export const PluginMultiplayerSet = (
).toUpperCase()
const key = `BETTERWRITE-PUBLIC-${random}`

room = client.enter(key)
room = client.enter(key, {
initialPresence: { cursor: null },
initialStorage: {
instance: new LiveObject(hooks.storage.getProjectObject()),
},
})

hooks.plugin.emit('plugin-multiplayer-room-id', key)

Expand All @@ -42,9 +49,11 @@ export const PluginMultiplayerSet = (
])

On.multiplayer().PluginMultiplayerEnter(emitter, [
(id: ID<string>) => {
async (id: ID<string>) => {
room = client.enter(id)

const object = await room.getStorage()

stores.AUTH.account.multiplayer.connect = {
key: id,
type: 'guest',
Expand Down

0 comments on commit 4ce25e8

Please sign in to comment.